/** * Fastify type-provider-zod emitter for openapi-server. * * Replaces the hand-rolled Fastify branch in router.ts with a dedicated module * that uses fastify-type-provider-zod for request validation and type inference. * * Key design points (decided, not re-litigated): * - createRouter(service) returns a FastifyPluginAsyncZod; mount via app.register(createRouter(service), { prefix }) * - FastifyPluginAsyncZod carries ZodTypeProvider: no withTypeProvider() call needed inside the plugin * - setValidatorCompiler, setSerializerCompiler, setErrorHandler are scoped to the plugin instance * - Per route: schema.body, schema.params, schema.querystring, schema.headers, schema.response, config.operationId * - preValidation hook for deepObject and delimiter-style query params (emitted per-route, not globally) * - Cookie params use manual _ckv safeParse: Fastify 5's FastifySchema only exposes body/querystring/params/headers/response, so there is no cookie slot in the type-provider path * - No per-route generic type arguments; req.body/req.query/req.params infer from schemas * - No (reply as FastifyReply) casts */ import type { OpenAPIV3_1 } from 'openapi-types'; import type { GeneratedFile } from 'openapi-zod-ts'; interface RouterOptions { schemaNames?: Set; schemaImportPath?: string; /** * When true, emit the zero-cast router: body is passed as req.body (no cast), * response is sent without a cast, and model imports are skipped. The router * imports alias types from schema-types.js (emitted separately by generateFastifyTypes). * Enabled by the generator when framework=fastify and input_schema is configured. */ zeroCast?: boolean; contextType?: string; /** * When true, synthesize inline Zod response schema expressions for schema.response * when the response schema is flat (no $ref, allOf, oneOf, anyOf, nested objects). * Falls back to z.unknown() for complex shapes. Default: false. * For best coverage, use input_schema to wire your own Zod schemas instead. */ emitResponseValidation?: boolean; /** * Relative import path (from the generated router.ts) to the shared `_shared/errors.js` * module. Defaults to `./_shared/errors.js` when not provided. * The generator always passes the correct path based on the shared dir derivation logic. */ errorsImportPath?: string; } export declare function generateFastifyRouter(spec: OpenAPIV3_1.Document, options?: RouterOptions): GeneratedFile; export {}; //# sourceMappingURL=fastify-type-provider.d.ts.map