feat: add api client
This commit is contained in:
7
src/api/client.ts
Normal file
7
src/api/client.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import createClient from 'openapi-fetch'
|
||||
|
||||
import { type schema } from './schema'
|
||||
|
||||
export const client = createClient<schema>({
|
||||
baseUrl: 'http://localhost:1337/api/',
|
||||
})
|
||||
5400
src/api/paths.ts
Normal file
5400
src/api/paths.ts
Normal file
File diff suppressed because it is too large
Load Diff
28
src/api/schema.ts
Normal file
28
src/api/schema.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import type { paths } from './paths'
|
||||
|
||||
/**
|
||||
* Strapi REST accepts bracket-style query keys (populate[0], populate[x][populate], …)
|
||||
* that are not present in the OpenAPI document, so openapi-typescript cannot emit them.
|
||||
* This widens `parameters.query` for each HTTP method while keeping known keys typed.
|
||||
*/
|
||||
type LooseStrapiQuery<Q> = [Q] extends [never]
|
||||
? never
|
||||
: Q extends object
|
||||
? Q & { [key: string]: string | string[] | number | boolean | undefined }
|
||||
: Q
|
||||
|
||||
type WidenParameters<Params> = Params extends { query?: infer Q }
|
||||
? Omit<Params, 'query'> & { query?: LooseStrapiQuery<Q> }
|
||||
: Params
|
||||
|
||||
type WidenOperation<Op> = Op extends { parameters: infer P }
|
||||
? Omit<Op, 'parameters'> & { parameters: WidenParameters<P> }
|
||||
: Op
|
||||
|
||||
type HttpMethod = 'get' | 'put' | 'post' | 'delete' | 'options' | 'head' | 'patch' | 'trace'
|
||||
|
||||
export type schema = {
|
||||
[P in keyof paths]: {
|
||||
[K in keyof paths[P]]: K extends HttpMethod ? WidenOperation<paths[P][K]> : paths[P][K]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user