feat: add api client

This commit is contained in:
Zotov Ivan Yuryevich
2026-04-05 15:05:17 +03:00
parent 56f6ce41c1
commit 2bb1c896c0
6 changed files with 5714 additions and 1 deletions

7
src/api/client.ts Normal file
View 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

File diff suppressed because it is too large Load Diff

28
src/api/schema.ts Normal file
View 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]
}
}