Open ricogmacedo opened 1 year ago
The description of a response is given in the schema definition and this description is ignored when the json is transformed by jsonSchemaTransform.
Schema definition
const healthcheckSchema: FastifySchema = { response: { 200: { description: "Healthy", properties: z.object({ status: z.boolean(), }), }, }, };
swagger config with jsonSchemaTransform
fastify.register(fastifySwagger, { openapi: { info: { title: packageJsom.name, description: packageJsom.description, version: packageJsom.version, }, servers: [ { url: "http://localhost:3000", description: "Local", }, ] } transform: jsonSchemaTransform })
Description Healthy is missing when SwaggerUI is rendering based on transformed JSON:
Healthy
Transformed JSON:
{ "openapi":"3.0.3", "info":{ "title":"some-title", "description":"some-description", "version":"1.0.0" }, "components":{ "schemas":{ } }, "paths":{ "/":{ "get":{ "responses":{ "200":{ "description":"Default Response", "content":{ "application/json":{ "schema":{ "type":"object", "properties":{ "status":{ "type":"boolean" } }, "required":[ "status" ], "additionalProperties":false } } } } } } } }, "servers":[ { "url":"http://localhost:3000", "description":"Local" } ] }
you can use the .describe() function in your zod schema. for example:
const healthcheckSchema: FastifySchema = { response: { 200: z.object({ status: z.boolean() }).describe('Healthy'), }, };
The description of a response is given in the schema definition and this description is ignored when the json is transformed by jsonSchemaTransform.
Schema definition
swagger config with jsonSchemaTransform
Description
Healthy
is missing when SwaggerUI is rendering based on transformed JSON:Transformed JSON: