Generate one zodios endpoint per const to keep API package declarations under the TypeScript limit

This commit is contained in:
Gregor Vostrak
2026-12-04 13:24:52 +01:00
parent 61865f699d
commit d56a6ff056
3 changed files with 4986 additions and 4584 deletions

View File

@@ -16,7 +16,7 @@
"test:unit": "vitest run",
"test:unit:watch": "vitest",
"test:e2e": "rm -rf test-results/.auth && npx playwright test",
"zod:generate": "npx openapi-zod-client http://localhost:80/docs/api.json --output resources/js/packages/api/src/openapi.json.client.ts --base-url /api",
"zod:generate": "npx openapi-zod-client http://localhost:80/docs/api.json --output resources/js/packages/api/src/openapi.json.client.ts --base-url /api --template resources/js/packages/api/openapi-zod-client.hbs",
"format": "prettier --write './**/*.{js,jsx,cjs,mjs,ts,tsx,cts,mts,vue}'",
"format:check": "prettier --check './**/*.{js,jsx,cjs,mjs,ts,tsx,cts,mts,vue}'",
"build:ui": "npm run build --workspace=@solidtime/ui",

View File

@@ -0,0 +1,99 @@
import { makeEndpoint, Zodios, type ZodiosInstance, type ZodiosOptions } from "@zodios/core";
import { z } from "zod";
{{#if imports}}
{{#each imports}}
import { {{{@key}}} } from "./{{{this}}}"
{{/each}}
{{/if}}
{{#if types}}
{{#each types}}
{{{this}}};
{{/each}}
{{/if}}
{{#each schemas}}
const {{@key}}{{#if (lookup ../emittedType @key)}}: z.ZodType<{{@key}}>{{/if}} = {{{this}}};
{{/each}}
{{#ifNotEmptyObj schemas}}
export const schemas = {
{{#each schemas}}
{{@key}},
{{/each}}
};
{{/ifNotEmptyObj}}
{{#each endpoints}}
const endpoint{{@index}} = makeEndpoint({
method: "{{method}}",
path: "{{path}}",
{{#if @root.options.withAlias}}
{{#if alias}}
alias: "{{alias}}",
{{/if}}
{{/if}}
{{#if description}}
description: `{{description}}`,
{{/if}}
{{#if requestFormat}}
requestFormat: "{{requestFormat}}",
{{/if}}
{{#if parameters}}
parameters: [
{{#each parameters}}
{
name: "{{name}}",
{{#if description}}
description: `{{description}}`,
{{/if}}
{{#if type}}
type: "{{type}}",
{{/if}}
schema: {{{schema}}}
},
{{/each}}
],
{{/if}}
response: {{{response}}},
{{#if errors.length}}
errors: [
{{#each errors}}
{
{{#ifeq status "default" }}
status: "default",
{{else}}
status: {{status}},
{{/ifeq}}
{{#if description}}
description: `{{description}}`,
{{/if}}
schema: {{{schema}}}
},
{{/each}}
]
{{/if}}
});
{{/each}}
// One const per endpoint keeps each emitted declaration small; a single
// makeApi([...]) tuple exceeds what TypeScript can serialize (TS7056).
type Endpoints = [
{{#each endpoints}}
typeof endpoint{{@index}},
{{/each}}
];
const endpoints: Endpoints = [
{{#each endpoints}}
endpoint{{@index}},
{{/each}}
];
export const {{options.apiClientName}}: ZodiosInstance<Endpoints> = new Zodios({{#if options.baseUrl}}"{{options.baseUrl}}", {{/if}}endpoints);
export function createApiClient(baseUrl: string, options?: ZodiosOptions): ZodiosInstance<Endpoints> {
return new Zodios(baseUrl, endpoints, options);
}

File diff suppressed because it is too large Load Diff