✨ 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
+7 -7
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(),
},
}