Migrate to latest openapi-ts (#1430)

This commit is contained in:
Patrick Arminio
2024-11-27 12:06:59 +01:00
committed by GitHub
parent e34527325b
commit a21c57ab2b
12 changed files with 1707 additions and 578 deletions

View File

@@ -0,0 +1,15 @@
import { defineConfig } from "@hey-api/openapi-ts"
export default defineConfig({
client: "legacy/axios",
input: "./openapi.json",
output: "./src/client",
// exportSchemas: true,
plugins: [
{
name: "@hey-api/sdk",
// NOTE: this doesn't allow tree-shaking
asClass: true,
},
],
})

File diff suppressed because it is too large Load Diff

View File

@@ -8,7 +8,7 @@
"build": "tsc && vite build",
"lint": "biome check --apply-unsafe --no-errors-on-unmatched --files-ignore-unknown=true ./",
"preview": "vite preview",
"generate-client": "openapi-ts --input ./openapi.json --output ./src/client --client axios --exportSchemas true"
"generate-client": "openapi-ts"
},
"dependencies": {
"@chakra-ui/icons": "2.1.1",
@@ -29,7 +29,7 @@
},
"devDependencies": {
"@biomejs/biome": "1.6.1",
"@hey-api/openapi-ts": "^0.34.1",
"@hey-api/openapi-ts": "^0.57.0",
"@playwright/test": "^1.45.2",
"@tanstack/router-devtools": "1.19.1",
"@tanstack/router-vite-plugin": "1.19.0",

View File

@@ -1,20 +1,21 @@
export type ApiRequestOptions = {
readonly method:
| "GET"
| "PUT"
| "POST"
| "DELETE"
| "OPTIONS"
| "HEAD"
| "PATCH"
readonly url: string
readonly path?: Record<string, unknown>
readonly cookies?: Record<string, unknown>
readonly headers?: Record<string, unknown>
readonly query?: Record<string, unknown>
readonly formData?: Record<string, unknown>
export type ApiRequestOptions<T = unknown> = {
readonly body?: any
readonly cookies?: Record<string, unknown>
readonly errors?: Record<number | string, string>
readonly formData?: Record<string, unknown> | any[] | Blob | File
readonly headers?: Record<string, unknown>
readonly mediaType?: string
readonly method:
| "DELETE"
| "GET"
| "HEAD"
| "OPTIONS"
| "PATCH"
| "POST"
| "PUT"
readonly path?: Record<string, unknown>
readonly query?: Record<string, unknown>
readonly responseHeader?: string
readonly errors?: Record<number, string>
readonly responseTransformer?: (data: unknown) => Promise<T>
readonly url: string
}

View File

@@ -1,10 +1,9 @@
import type { AxiosRequestConfig, AxiosResponse } from "axios"
import type { ApiRequestOptions } from "./ApiRequestOptions"
import type { TResult } from "./types"
type Headers = Record<string, string>
type Middleware<T> = (value: T) => T | Promise<T>
type Resolver<T> = (options: ApiRequestOptions) => Promise<T>
type Resolver<T> = (options: ApiRequestOptions<T>) => Promise<T>
export class Interceptors<T> {
_fns: Middleware<T>[]
@@ -13,14 +12,14 @@ export class Interceptors<T> {
this._fns = []
}
eject(fn: Middleware<T>) {
eject(fn: Middleware<T>): void {
const index = this._fns.indexOf(fn)
if (index !== -1) {
this._fns = [...this._fns.slice(0, index), ...this._fns.slice(index + 1)]
}
}
use(fn: Middleware<T>) {
use(fn: Middleware<T>): void {
this._fns = [...this._fns, fn]
}
}
@@ -31,7 +30,6 @@ export type OpenAPIConfig = {
ENCODE_PATH?: ((path: string) => string) | undefined
HEADERS?: Headers | Resolver<Headers> | undefined
PASSWORD?: string | Resolver<string> | undefined
RESULT?: TResult
TOKEN?: string | Resolver<string> | undefined
USERNAME?: string | Resolver<string> | undefined
VERSION: string
@@ -48,10 +46,12 @@ export const OpenAPI: OpenAPIConfig = {
ENCODE_PATH: undefined,
HEADERS: undefined,
PASSWORD: undefined,
RESULT: "body",
TOKEN: undefined,
USERNAME: undefined,
VERSION: "0.1.0",
WITH_CREDENTIALS: false,
interceptors: { request: new Interceptors(), response: new Interceptors() },
interceptors: {
request: new Interceptors(),
response: new Interceptors(),
},
}

View File

@@ -54,7 +54,9 @@ export const getQueryString = (params: Record<string, unknown>): string => {
return
}
if (Array.isArray(value)) {
if (value instanceof Date) {
append(key, value.toISOString())
} else if (Array.isArray(value)) {
value.forEach((v) => encodePair(key, v))
} else if (typeof value === "object") {
Object.entries(value).forEach(([k, v]) => encodePair(`${key}[${k}]`, v))
@@ -113,10 +115,10 @@ export const getFormData = (
return undefined
}
type Resolver<T> = (options: ApiRequestOptions) => Promise<T>
type Resolver<T> = (options: ApiRequestOptions<T>) => Promise<T>
export const resolve = async <T>(
options: ApiRequestOptions,
options: ApiRequestOptions<T>,
resolver?: T | Resolver<T>,
): Promise<T | undefined> => {
if (typeof resolver === "function") {
@@ -125,14 +127,18 @@ export const resolve = async <T>(
return resolver
}
export const getHeaders = async (
export const getHeaders = async <T>(
config: OpenAPIConfig,
options: ApiRequestOptions,
options: ApiRequestOptions<T>,
): Promise<Record<string, string>> => {
const [token, username, password, additionalHeaders] = await Promise.all([
// @ts-ignore
resolve(options, config.TOKEN),
// @ts-ignore
resolve(options, config.USERNAME),
// @ts-ignore
resolve(options, config.PASSWORD),
// @ts-ignore
resolve(options, config.HEADERS),
])
@@ -187,7 +193,7 @@ export const getRequestBody = (options: ApiRequestOptions): unknown => {
export const sendRequest = async <T>(
config: OpenAPIConfig,
options: ApiRequestOptions,
options: ApiRequestOptions<T>,
url: string,
body: unknown,
formData: FormData | undefined,
@@ -325,7 +331,7 @@ export const catchErrorCodes = (
*/
export const request = <T>(
config: OpenAPIConfig,
options: ApiRequestOptions,
options: ApiRequestOptions<T>,
axiosClient: AxiosInstance = axios,
): CancelablePromise<T> => {
return new CancelablePromise(async (resolve, reject, onCancel) => {
@@ -357,12 +363,17 @@ export const request = <T>(
options.responseHeader,
)
let transformedBody = responseBody
if (options.responseTransformer && isSuccess(response.status)) {
transformedBody = await options.responseTransformer(responseBody)
}
const result: ApiResult = {
url,
ok: isSuccess(response.status),
status: response.status,
statusText: response.statusText,
body: responseHeader ?? responseBody,
body: responseHeader ?? transformedBody,
}
catchErrorCodes(options, result)

View File

@@ -1,14 +0,0 @@
import type { ApiResult } from "./ApiResult"
export type TResult = "body" | "raw"
export type TApiResponse<T extends TResult, TData> = Exclude<
T,
"raw"
> extends never
? ApiResult<TData>
: ApiResult<TData>["body"]
export type TConfig<T extends TResult> = {
_result?: T
}

View File

@@ -1,8 +1,6 @@
// This file is auto-generated by @hey-api/openapi-ts
export { ApiError } from "./core/ApiError"
export { CancelablePromise, CancelError } from "./core/CancelablePromise"
export { OpenAPI } from "./core/OpenAPI"
export type { OpenAPIConfig } from "./core/OpenAPI"
export * from "./models"
export * from "./schemas"
export * from "./services"
export { OpenAPI, type OpenAPIConfig } from "./core/OpenAPI"
export * from "./sdk.gen"
export * from "./types.gen"

View File

@@ -1,99 +0,0 @@
export type Body_login_login_access_token = {
grant_type?: string | null
username: string
password: string
scope?: string
client_id?: string | null
client_secret?: string | null
}
export type HTTPValidationError = {
detail?: Array<ValidationError>
}
export type ItemCreate = {
title: string
description?: string | null
}
export type ItemPublic = {
title: string
description?: string | null
id: string
owner_id: string
}
export type ItemUpdate = {
title?: string | null
description?: string | null
}
export type ItemsPublic = {
data: Array<ItemPublic>
count: number
}
export type Message = {
message: string
}
export type NewPassword = {
token: string
new_password: string
}
export type Token = {
access_token: string
token_type?: string
}
export type UpdatePassword = {
current_password: string
new_password: string
}
export type UserCreate = {
email: string
is_active?: boolean
is_superuser?: boolean
full_name?: string | null
password: string
}
export type UserPublic = {
email: string
is_active?: boolean
is_superuser?: boolean
full_name?: string | null
id: string
}
export type UserRegister = {
email: string
password: string
full_name?: string | null
}
export type UserUpdate = {
email?: string | null
is_active?: boolean
is_superuser?: boolean
full_name?: string | null
password?: string | null
}
export type UserUpdateMe = {
full_name?: string | null
email?: string | null
}
export type UsersPublic = {
data: Array<UserPublic>
count: number
}
export type ValidationError = {
loc: Array<string | number>
msg: string
type: string
}

View File

@@ -1,8 +1,9 @@
export const $Body_login_login_access_token = {
// This file is auto-generated by @hey-api/openapi-ts
export const Body_login_login_access_tokenSchema = {
properties: {
grant_type: {
type: "any-of",
contains: [
anyOf: [
{
type: "string",
pattern: "password",
@@ -11,22 +12,23 @@ export const $Body_login_login_access_token = {
type: "null",
},
],
title: "Grant Type",
},
username: {
type: "string",
isRequired: true,
title: "Username",
},
password: {
type: "string",
isRequired: true,
title: "Password",
},
scope: {
type: "string",
title: "Scope",
default: "",
},
client_id: {
type: "any-of",
contains: [
anyOf: [
{
type: "string",
},
@@ -34,10 +36,10 @@ export const $Body_login_login_access_token = {
type: "null",
},
],
title: "Client Id",
},
client_secret: {
type: "any-of",
contains: [
anyOf: [
{
type: "string",
},
@@ -45,32 +47,38 @@ export const $Body_login_login_access_token = {
type: "null",
},
],
title: "Client Secret",
},
},
type: "object",
required: ["username", "password"],
title: "Body_login-login_access_token",
} as const
export const $HTTPValidationError = {
export const HTTPValidationErrorSchema = {
properties: {
detail: {
type: "array",
contains: {
type: "ValidationError",
items: {
$ref: "#/components/schemas/ValidationError",
},
type: "array",
title: "Detail",
},
},
type: "object",
title: "HTTPValidationError",
} as const
export const $ItemCreate = {
export const ItemCreateSchema = {
properties: {
title: {
type: "string",
isRequired: true,
maxLength: 255,
minLength: 1,
title: "Title",
},
description: {
type: "any-of",
contains: [
anyOf: [
{
type: "string",
maxLength: 255,
@@ -79,21 +87,24 @@ export const $ItemCreate = {
type: "null",
},
],
title: "Description",
},
},
type: "object",
required: ["title"],
title: "ItemCreate",
} as const
export const $ItemPublic = {
export const ItemPublicSchema = {
properties: {
title: {
type: "string",
isRequired: true,
maxLength: 255,
minLength: 1,
title: "Title",
},
description: {
type: "any-of",
contains: [
anyOf: [
{
type: "string",
maxLength: 255,
@@ -102,25 +113,28 @@ export const $ItemPublic = {
type: "null",
},
],
title: "Description",
},
id: {
type: "string",
isRequired: true,
format: "uuid",
title: "Id",
},
owner_id: {
type: "string",
isRequired: true,
format: "uuid",
title: "Owner Id",
},
},
type: "object",
required: ["title", "id", "owner_id"],
title: "ItemPublic",
} as const
export const $ItemUpdate = {
export const ItemUpdateSchema = {
properties: {
title: {
type: "any-of",
contains: [
anyOf: [
{
type: "string",
maxLength: 255,
@@ -130,10 +144,10 @@ export const $ItemUpdate = {
type: "null",
},
],
title: "Title",
},
description: {
type: "any-of",
contains: [
anyOf: [
{
type: "string",
maxLength: 255,
@@ -142,99 +156,119 @@ export const $ItemUpdate = {
type: "null",
},
],
title: "Description",
},
},
type: "object",
title: "ItemUpdate",
} as const
export const $ItemsPublic = {
export const ItemsPublicSchema = {
properties: {
data: {
type: "array",
contains: {
type: "ItemPublic",
items: {
$ref: "#/components/schemas/ItemPublic",
},
isRequired: true,
type: "array",
title: "Data",
},
count: {
type: "number",
isRequired: true,
type: "integer",
title: "Count",
},
},
type: "object",
required: ["data", "count"],
title: "ItemsPublic",
} as const
export const $Message = {
export const MessageSchema = {
properties: {
message: {
type: "string",
isRequired: true,
title: "Message",
},
},
type: "object",
required: ["message"],
title: "Message",
} as const
export const $NewPassword = {
export const NewPasswordSchema = {
properties: {
token: {
type: "string",
isRequired: true,
title: "Token",
},
new_password: {
type: "string",
isRequired: true,
maxLength: 40,
minLength: 8,
title: "New Password",
},
},
type: "object",
required: ["token", "new_password"],
title: "NewPassword",
} as const
export const $Token = {
export const TokenSchema = {
properties: {
access_token: {
type: "string",
isRequired: true,
title: "Access Token",
},
token_type: {
type: "string",
title: "Token Type",
default: "bearer",
},
},
type: "object",
required: ["access_token"],
title: "Token",
} as const
export const $UpdatePassword = {
export const UpdatePasswordSchema = {
properties: {
current_password: {
type: "string",
isRequired: true,
maxLength: 40,
minLength: 8,
title: "Current Password",
},
new_password: {
type: "string",
isRequired: true,
maxLength: 40,
minLength: 8,
title: "New Password",
},
},
type: "object",
required: ["current_password", "new_password"],
title: "UpdatePassword",
} as const
export const $UserCreate = {
export const UserCreateSchema = {
properties: {
email: {
type: "string",
isRequired: true,
format: "email",
maxLength: 255,
format: "email",
title: "Email",
},
is_active: {
type: "boolean",
title: "Is Active",
default: true,
},
is_superuser: {
type: "boolean",
title: "Is Superuser",
default: false,
},
full_name: {
type: "any-of",
contains: [
anyOf: [
{
type: "string",
maxLength: 255,
@@ -243,35 +277,40 @@ export const $UserCreate = {
type: "null",
},
],
title: "Full Name",
},
password: {
type: "string",
isRequired: true,
maxLength: 40,
minLength: 8,
title: "Password",
},
},
type: "object",
required: ["email", "password"],
title: "UserCreate",
} as const
export const $UserPublic = {
export const UserPublicSchema = {
properties: {
email: {
type: "string",
isRequired: true,
format: "email",
maxLength: 255,
format: "email",
title: "Email",
},
is_active: {
type: "boolean",
title: "Is Active",
default: true,
},
is_superuser: {
type: "boolean",
title: "Is Superuser",
default: false,
},
full_name: {
type: "any-of",
contains: [
anyOf: [
{
type: "string",
maxLength: 255,
@@ -280,32 +319,35 @@ export const $UserPublic = {
type: "null",
},
],
title: "Full Name",
},
id: {
type: "string",
isRequired: true,
format: "uuid",
title: "Id",
},
},
type: "object",
required: ["email", "id"],
title: "UserPublic",
} as const
export const $UserRegister = {
export const UserRegisterSchema = {
properties: {
email: {
type: "string",
isRequired: true,
format: "email",
maxLength: 255,
format: "email",
title: "Email",
},
password: {
type: "string",
isRequired: true,
maxLength: 40,
minLength: 8,
title: "Password",
},
full_name: {
type: "any-of",
contains: [
anyOf: [
{
type: "string",
maxLength: 255,
@@ -314,36 +356,41 @@ export const $UserRegister = {
type: "null",
},
],
title: "Full Name",
},
},
type: "object",
required: ["email", "password"],
title: "UserRegister",
} as const
export const $UserUpdate = {
export const UserUpdateSchema = {
properties: {
email: {
type: "any-of",
contains: [
anyOf: [
{
type: "string",
format: "email",
maxLength: 255,
format: "email",
},
{
type: "null",
},
],
title: "Email",
},
is_active: {
type: "boolean",
title: "Is Active",
default: true,
},
is_superuser: {
type: "boolean",
title: "Is Superuser",
default: false,
},
full_name: {
type: "any-of",
contains: [
anyOf: [
{
type: "string",
maxLength: 255,
@@ -352,10 +399,10 @@ export const $UserUpdate = {
type: "null",
},
],
title: "Full Name",
},
password: {
type: "any-of",
contains: [
anyOf: [
{
type: "string",
maxLength: 40,
@@ -365,15 +412,17 @@ export const $UserUpdate = {
type: "null",
},
],
title: "Password",
},
},
type: "object",
title: "UserUpdate",
} as const
export const $UserUpdateMe = {
export const UserUpdateMeSchema = {
properties: {
full_name: {
type: "any-of",
contains: [
anyOf: [
{
type: "string",
maxLength: 255,
@@ -382,63 +431,71 @@ export const $UserUpdateMe = {
type: "null",
},
],
title: "Full Name",
},
email: {
type: "any-of",
contains: [
anyOf: [
{
type: "string",
format: "email",
maxLength: 255,
format: "email",
},
{
type: "null",
},
],
title: "Email",
},
},
type: "object",
title: "UserUpdateMe",
} as const
export const $UsersPublic = {
export const UsersPublicSchema = {
properties: {
data: {
type: "array",
contains: {
type: "UserPublic",
items: {
$ref: "#/components/schemas/UserPublic",
},
isRequired: true,
type: "array",
title: "Data",
},
count: {
type: "number",
isRequired: true,
type: "integer",
title: "Count",
},
},
type: "object",
required: ["data", "count"],
title: "UsersPublic",
} as const
export const $ValidationError = {
export const ValidationErrorSchema = {
properties: {
loc: {
type: "array",
contains: {
type: "any-of",
contains: [
items: {
anyOf: [
{
type: "string",
},
{
type: "number",
type: "integer",
},
],
},
isRequired: true,
type: "array",
title: "Location",
},
msg: {
type: "string",
isRequired: true,
title: "Message",
},
type: {
type: "string",
isRequired: true,
title: "Error Type",
},
},
type: "object",
required: ["loc", "msg", "type"],
title: "ValidationError",
} as const

View File

@@ -1,56 +1,191 @@
// This file is auto-generated by @hey-api/openapi-ts
import type { CancelablePromise } from "./core/CancelablePromise"
import { OpenAPI } from "./core/OpenAPI"
import { request as __request } from "./core/request"
import type {
Body_login_login_access_token,
Message,
NewPassword,
Token,
UserPublic,
UpdatePassword,
UserCreate,
UserRegister,
UsersPublic,
UserUpdate,
UserUpdateMe,
ItemCreate,
ItemPublic,
ItemsPublic,
ItemUpdate,
} from "./models"
ReadItemsData,
ReadItemsResponse,
CreateItemData,
CreateItemResponse,
ReadItemData,
ReadItemResponse,
UpdateItemData,
UpdateItemResponse,
DeleteItemData,
DeleteItemResponse,
LoginAccessTokenData,
LoginAccessTokenResponse,
TestTokenResponse,
RecoverPasswordData,
RecoverPasswordResponse,
ResetPasswordData,
ResetPasswordResponse,
RecoverPasswordHtmlContentData,
RecoverPasswordHtmlContentResponse,
ReadUsersData,
ReadUsersResponse,
CreateUserData,
CreateUserResponse,
ReadUserMeResponse,
DeleteUserMeResponse,
UpdateUserMeData,
UpdateUserMeResponse,
UpdatePasswordMeData,
UpdatePasswordMeResponse,
RegisterUserData,
RegisterUserResponse,
ReadUserByIdData,
ReadUserByIdResponse,
UpdateUserData,
UpdateUserResponse,
DeleteUserData,
DeleteUserResponse,
TestEmailData,
TestEmailResponse,
HealthCheckResponse,
} from "./types.gen"
export type TDataLoginAccessToken = {
formData: Body_login_login_access_token
}
export type TDataRecoverPassword = {
email: string
}
export type TDataResetPassword = {
requestBody: NewPassword
}
export type TDataRecoverPasswordHtmlContent = {
email: string
export class ItemsService {
/**
* Read Items
* Retrieve items.
* @param data The data for the request.
* @param data.skip
* @param data.limit
* @returns ItemsPublic Successful Response
* @throws ApiError
*/
public static readItems(
data: ReadItemsData = {},
): CancelablePromise<ReadItemsResponse> {
return __request(OpenAPI, {
method: "GET",
url: "/api/v1/items/",
query: {
skip: data.skip,
limit: data.limit,
},
errors: {
422: "Validation Error",
},
})
}
/**
* Create Item
* Create new item.
* @param data The data for the request.
* @param data.requestBody
* @returns ItemPublic Successful Response
* @throws ApiError
*/
public static createItem(
data: CreateItemData,
): CancelablePromise<CreateItemResponse> {
return __request(OpenAPI, {
method: "POST",
url: "/api/v1/items/",
body: data.requestBody,
mediaType: "application/json",
errors: {
422: "Validation Error",
},
})
}
/**
* Read Item
* Get item by ID.
* @param data The data for the request.
* @param data.id
* @returns ItemPublic Successful Response
* @throws ApiError
*/
public static readItem(
data: ReadItemData,
): CancelablePromise<ReadItemResponse> {
return __request(OpenAPI, {
method: "GET",
url: "/api/v1/items/{id}",
path: {
id: data.id,
},
errors: {
422: "Validation Error",
},
})
}
/**
* Update Item
* Update an item.
* @param data The data for the request.
* @param data.id
* @param data.requestBody
* @returns ItemPublic Successful Response
* @throws ApiError
*/
public static updateItem(
data: UpdateItemData,
): CancelablePromise<UpdateItemResponse> {
return __request(OpenAPI, {
method: "PUT",
url: "/api/v1/items/{id}",
path: {
id: data.id,
},
body: data.requestBody,
mediaType: "application/json",
errors: {
422: "Validation Error",
},
})
}
/**
* Delete Item
* Delete an item.
* @param data The data for the request.
* @param data.id
* @returns Message Successful Response
* @throws ApiError
*/
public static deleteItem(
data: DeleteItemData,
): CancelablePromise<DeleteItemResponse> {
return __request(OpenAPI, {
method: "DELETE",
url: "/api/v1/items/{id}",
path: {
id: data.id,
},
errors: {
422: "Validation Error",
},
})
}
}
export class LoginService {
/**
* Login Access Token
* OAuth2 compatible token login, get an access token for future requests
* @param data The data for the request.
* @param data.formData
* @returns Token Successful Response
* @throws ApiError
*/
public static loginAccessToken(
data: TDataLoginAccessToken,
): CancelablePromise<Token> {
const { formData } = data
data: LoginAccessTokenData,
): CancelablePromise<LoginAccessTokenResponse> {
return __request(OpenAPI, {
method: "POST",
url: "/api/v1/login/access-token",
formData: formData,
formData: data.formData,
mediaType: "application/x-www-form-urlencoded",
errors: {
422: `Validation Error`,
422: "Validation Error",
},
})
}
@@ -61,7 +196,7 @@ export class LoginService {
* @returns UserPublic Successful Response
* @throws ApiError
*/
public static testToken(): CancelablePromise<UserPublic> {
public static testToken(): CancelablePromise<TestTokenResponse> {
return __request(OpenAPI, {
method: "POST",
url: "/api/v1/login/test-token",
@@ -71,21 +206,22 @@ export class LoginService {
/**
* Recover Password
* Password Recovery
* @param data The data for the request.
* @param data.email
* @returns Message Successful Response
* @throws ApiError
*/
public static recoverPassword(
data: TDataRecoverPassword,
): CancelablePromise<Message> {
const { email } = data
data: RecoverPasswordData,
): CancelablePromise<RecoverPasswordResponse> {
return __request(OpenAPI, {
method: "POST",
url: "/api/v1/password-recovery/{email}",
path: {
email,
email: data.email,
},
errors: {
422: `Validation Error`,
422: "Validation Error",
},
})
}
@@ -93,20 +229,21 @@ export class LoginService {
/**
* Reset Password
* Reset password
* @param data The data for the request.
* @param data.requestBody
* @returns Message Successful Response
* @throws ApiError
*/
public static resetPassword(
data: TDataResetPassword,
): CancelablePromise<Message> {
const { requestBody } = data
data: ResetPasswordData,
): CancelablePromise<ResetPasswordResponse> {
return __request(OpenAPI, {
method: "POST",
url: "/api/v1/reset-password/",
body: requestBody,
body: data.requestBody,
mediaType: "application/json",
errors: {
422: `Validation Error`,
422: "Validation Error",
},
})
}
@@ -114,73 +251,49 @@ export class LoginService {
/**
* Recover Password Html Content
* HTML Content for Password Recovery
* @param data The data for the request.
* @param data.email
* @returns string Successful Response
* @throws ApiError
*/
public static recoverPasswordHtmlContent(
data: TDataRecoverPasswordHtmlContent,
): CancelablePromise<string> {
const { email } = data
data: RecoverPasswordHtmlContentData,
): CancelablePromise<RecoverPasswordHtmlContentResponse> {
return __request(OpenAPI, {
method: "POST",
url: "/api/v1/password-recovery-html-content/{email}",
path: {
email,
email: data.email,
},
errors: {
422: `Validation Error`,
422: "Validation Error",
},
})
}
}
export type TDataReadUsers = {
limit?: number
skip?: number
}
export type TDataCreateUser = {
requestBody: UserCreate
}
export type TDataUpdateUserMe = {
requestBody: UserUpdateMe
}
export type TDataUpdatePasswordMe = {
requestBody: UpdatePassword
}
export type TDataRegisterUser = {
requestBody: UserRegister
}
export type TDataReadUserById = {
userId: string
}
export type TDataUpdateUser = {
requestBody: UserUpdate
userId: string
}
export type TDataDeleteUser = {
userId: string
}
export class UsersService {
/**
* Read Users
* Retrieve users.
* @param data The data for the request.
* @param data.skip
* @param data.limit
* @returns UsersPublic Successful Response
* @throws ApiError
*/
public static readUsers(
data: TDataReadUsers = {},
): CancelablePromise<UsersPublic> {
const { limit = 100, skip = 0 } = data
data: ReadUsersData = {},
): CancelablePromise<ReadUsersResponse> {
return __request(OpenAPI, {
method: "GET",
url: "/api/v1/users/",
query: {
skip,
limit,
skip: data.skip,
limit: data.limit,
},
errors: {
422: `Validation Error`,
422: "Validation Error",
},
})
}
@@ -188,20 +301,21 @@ export class UsersService {
/**
* Create User
* Create new user.
* @param data The data for the request.
* @param data.requestBody
* @returns UserPublic Successful Response
* @throws ApiError
*/
public static createUser(
data: TDataCreateUser,
): CancelablePromise<UserPublic> {
const { requestBody } = data
data: CreateUserData,
): CancelablePromise<CreateUserResponse> {
return __request(OpenAPI, {
method: "POST",
url: "/api/v1/users/",
body: requestBody,
body: data.requestBody,
mediaType: "application/json",
errors: {
422: `Validation Error`,
422: "Validation Error",
},
})
}
@@ -212,7 +326,7 @@ export class UsersService {
* @returns UserPublic Successful Response
* @throws ApiError
*/
public static readUserMe(): CancelablePromise<UserPublic> {
public static readUserMe(): CancelablePromise<ReadUserMeResponse> {
return __request(OpenAPI, {
method: "GET",
url: "/api/v1/users/me",
@@ -225,7 +339,7 @@ export class UsersService {
* @returns Message Successful Response
* @throws ApiError
*/
public static deleteUserMe(): CancelablePromise<Message> {
public static deleteUserMe(): CancelablePromise<DeleteUserMeResponse> {
return __request(OpenAPI, {
method: "DELETE",
url: "/api/v1/users/me",
@@ -235,20 +349,21 @@ export class UsersService {
/**
* Update User Me
* Update own user.
* @param data The data for the request.
* @param data.requestBody
* @returns UserPublic Successful Response
* @throws ApiError
*/
public static updateUserMe(
data: TDataUpdateUserMe,
): CancelablePromise<UserPublic> {
const { requestBody } = data
data: UpdateUserMeData,
): CancelablePromise<UpdateUserMeResponse> {
return __request(OpenAPI, {
method: "PATCH",
url: "/api/v1/users/me",
body: requestBody,
body: data.requestBody,
mediaType: "application/json",
errors: {
422: `Validation Error`,
422: "Validation Error",
},
})
}
@@ -256,20 +371,21 @@ export class UsersService {
/**
* Update Password Me
* Update own password.
* @param data The data for the request.
* @param data.requestBody
* @returns Message Successful Response
* @throws ApiError
*/
public static updatePasswordMe(
data: TDataUpdatePasswordMe,
): CancelablePromise<Message> {
const { requestBody } = data
data: UpdatePasswordMeData,
): CancelablePromise<UpdatePasswordMeResponse> {
return __request(OpenAPI, {
method: "PATCH",
url: "/api/v1/users/me/password",
body: requestBody,
body: data.requestBody,
mediaType: "application/json",
errors: {
422: `Validation Error`,
422: "Validation Error",
},
})
}
@@ -277,20 +393,21 @@ export class UsersService {
/**
* Register User
* Create new user without the need to be logged in.
* @param data The data for the request.
* @param data.requestBody
* @returns UserPublic Successful Response
* @throws ApiError
*/
public static registerUser(
data: TDataRegisterUser,
): CancelablePromise<UserPublic> {
const { requestBody } = data
data: RegisterUserData,
): CancelablePromise<RegisterUserResponse> {
return __request(OpenAPI, {
method: "POST",
url: "/api/v1/users/signup",
body: requestBody,
body: data.requestBody,
mediaType: "application/json",
errors: {
422: `Validation Error`,
422: "Validation Error",
},
})
}
@@ -298,21 +415,22 @@ export class UsersService {
/**
* Read User By Id
* Get a specific user by id.
* @param data The data for the request.
* @param data.userId
* @returns UserPublic Successful Response
* @throws ApiError
*/
public static readUserById(
data: TDataReadUserById,
): CancelablePromise<UserPublic> {
const { userId } = data
data: ReadUserByIdData,
): CancelablePromise<ReadUserByIdResponse> {
return __request(OpenAPI, {
method: "GET",
url: "/api/v1/users/{user_id}",
path: {
user_id: userId,
user_id: data.userId,
},
errors: {
422: `Validation Error`,
422: "Validation Error",
},
})
}
@@ -320,23 +438,25 @@ export class UsersService {
/**
* Update User
* Update a user.
* @param data The data for the request.
* @param data.userId
* @param data.requestBody
* @returns UserPublic Successful Response
* @throws ApiError
*/
public static updateUser(
data: TDataUpdateUser,
): CancelablePromise<UserPublic> {
const { requestBody, userId } = data
data: UpdateUserData,
): CancelablePromise<UpdateUserResponse> {
return __request(OpenAPI, {
method: "PATCH",
url: "/api/v1/users/{user_id}",
path: {
user_id: userId,
user_id: data.userId,
},
body: requestBody,
body: data.requestBody,
mediaType: "application/json",
errors: {
422: `Validation Error`,
422: "Validation Error",
},
})
}
@@ -344,45 +464,47 @@ export class UsersService {
/**
* Delete User
* Delete a user.
* @param data The data for the request.
* @param data.userId
* @returns Message Successful Response
* @throws ApiError
*/
public static deleteUser(data: TDataDeleteUser): CancelablePromise<Message> {
const { userId } = data
public static deleteUser(
data: DeleteUserData,
): CancelablePromise<DeleteUserResponse> {
return __request(OpenAPI, {
method: "DELETE",
url: "/api/v1/users/{user_id}",
path: {
user_id: userId,
user_id: data.userId,
},
errors: {
422: `Validation Error`,
422: "Validation Error",
},
})
}
}
export type TDataTestEmail = {
emailTo: string
}
export class UtilsService {
/**
* Test Email
* Test emails.
* @param data The data for the request.
* @param data.emailTo
* @returns Message Successful Response
* @throws ApiError
*/
public static testEmail(data: TDataTestEmail): CancelablePromise<Message> {
const { emailTo } = data
public static testEmail(
data: TestEmailData,
): CancelablePromise<TestEmailResponse> {
return __request(OpenAPI, {
method: "POST",
url: "/api/v1/utils/test-email/",
query: {
email_to: emailTo,
email_to: data.emailTo,
},
errors: {
422: `Validation Error`,
422: "Validation Error",
},
})
}
@@ -392,138 +514,10 @@ export class UtilsService {
* @returns boolean Successful Response
* @throws ApiError
*/
public static healthCheck(): CancelablePromise<boolean> {
public static healthCheck(): CancelablePromise<HealthCheckResponse> {
return __request(OpenAPI, {
method: "GET",
url: "/api/v1/utils/health-check/",
})
}
}
export type TDataReadItems = {
limit?: number
skip?: number
}
export type TDataCreateItem = {
requestBody: ItemCreate
}
export type TDataReadItem = {
id: string
}
export type TDataUpdateItem = {
id: string
requestBody: ItemUpdate
}
export type TDataDeleteItem = {
id: string
}
export class ItemsService {
/**
* Read Items
* Retrieve items.
* @returns ItemsPublic Successful Response
* @throws ApiError
*/
public static readItems(
data: TDataReadItems = {},
): CancelablePromise<ItemsPublic> {
const { limit = 100, skip = 0 } = data
return __request(OpenAPI, {
method: "GET",
url: "/api/v1/items/",
query: {
skip,
limit,
},
errors: {
422: `Validation Error`,
},
})
}
/**
* Create Item
* Create new item.
* @returns ItemPublic Successful Response
* @throws ApiError
*/
public static createItem(
data: TDataCreateItem,
): CancelablePromise<ItemPublic> {
const { requestBody } = data
return __request(OpenAPI, {
method: "POST",
url: "/api/v1/items/",
body: requestBody,
mediaType: "application/json",
errors: {
422: `Validation Error`,
},
})
}
/**
* Read Item
* Get item by ID.
* @returns ItemPublic Successful Response
* @throws ApiError
*/
public static readItem(data: TDataReadItem): CancelablePromise<ItemPublic> {
const { id } = data
return __request(OpenAPI, {
method: "GET",
url: "/api/v1/items/{id}",
path: {
id,
},
errors: {
422: `Validation Error`,
},
})
}
/**
* Update Item
* Update an item.
* @returns ItemPublic Successful Response
* @throws ApiError
*/
public static updateItem(
data: TDataUpdateItem,
): CancelablePromise<ItemPublic> {
const { id, requestBody } = data
return __request(OpenAPI, {
method: "PUT",
url: "/api/v1/items/{id}",
path: {
id,
},
body: requestBody,
mediaType: "application/json",
errors: {
422: `Validation Error`,
},
})
}
/**
* Delete Item
* Delete an item.
* @returns Message Successful Response
* @throws ApiError
*/
public static deleteItem(data: TDataDeleteItem): CancelablePromise<Message> {
const { id } = data
return __request(OpenAPI, {
method: "DELETE",
url: "/api/v1/items/{id}",
path: {
id,
},
errors: {
422: `Validation Error`,
},
})
}
}

View File

@@ -0,0 +1,221 @@
// This file is auto-generated by @hey-api/openapi-ts
export type Body_login_login_access_token = {
grant_type?: string | null
username: string
password: string
scope?: string
client_id?: string | null
client_secret?: string | null
}
export type HTTPValidationError = {
detail?: Array<ValidationError>
}
export type ItemCreate = {
title: string
description?: string | null
}
export type ItemPublic = {
title: string
description?: string | null
id: string
owner_id: string
}
export type ItemsPublic = {
data: Array<ItemPublic>
count: number
}
export type ItemUpdate = {
title?: string | null
description?: string | null
}
export type Message = {
message: string
}
export type NewPassword = {
token: string
new_password: string
}
export type Token = {
access_token: string
token_type?: string
}
export type UpdatePassword = {
current_password: string
new_password: string
}
export type UserCreate = {
email: string
is_active?: boolean
is_superuser?: boolean
full_name?: string | null
password: string
}
export type UserPublic = {
email: string
is_active?: boolean
is_superuser?: boolean
full_name?: string | null
id: string
}
export type UserRegister = {
email: string
password: string
full_name?: string | null
}
export type UsersPublic = {
data: Array<UserPublic>
count: number
}
export type UserUpdate = {
email?: string | null
is_active?: boolean
is_superuser?: boolean
full_name?: string | null
password?: string | null
}
export type UserUpdateMe = {
full_name?: string | null
email?: string | null
}
export type ValidationError = {
loc: Array<string | number>
msg: string
type: string
}
export type ReadItemsData = {
limit?: number
skip?: number
}
export type ReadItemsResponse = ItemsPublic
export type CreateItemData = {
requestBody: ItemCreate
}
export type CreateItemResponse = ItemPublic
export type ReadItemData = {
id: string
}
export type ReadItemResponse = ItemPublic
export type UpdateItemData = {
id: string
requestBody: ItemUpdate
}
export type UpdateItemResponse = ItemPublic
export type DeleteItemData = {
id: string
}
export type DeleteItemResponse = Message
export type LoginAccessTokenData = {
formData: Body_login_login_access_token
}
export type LoginAccessTokenResponse = Token
export type TestTokenResponse = UserPublic
export type RecoverPasswordData = {
email: string
}
export type RecoverPasswordResponse = Message
export type ResetPasswordData = {
requestBody: NewPassword
}
export type ResetPasswordResponse = Message
export type RecoverPasswordHtmlContentData = {
email: string
}
export type RecoverPasswordHtmlContentResponse = string
export type ReadUsersData = {
limit?: number
skip?: number
}
export type ReadUsersResponse = UsersPublic
export type CreateUserData = {
requestBody: UserCreate
}
export type CreateUserResponse = UserPublic
export type ReadUserMeResponse = UserPublic
export type DeleteUserMeResponse = Message
export type UpdateUserMeData = {
requestBody: UserUpdateMe
}
export type UpdateUserMeResponse = UserPublic
export type UpdatePasswordMeData = {
requestBody: UpdatePassword
}
export type UpdatePasswordMeResponse = Message
export type RegisterUserData = {
requestBody: UserRegister
}
export type RegisterUserResponse = UserPublic
export type ReadUserByIdData = {
userId: string
}
export type ReadUserByIdResponse = UserPublic
export type UpdateUserData = {
requestBody: UserUpdate
userId: string
}
export type UpdateUserResponse = UserPublic
export type DeleteUserData = {
userId: string
}
export type DeleteUserResponse = Message
export type TestEmailData = {
emailTo: string
}
export type TestEmailResponse = Message
export type HealthCheckResponse = boolean