Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

swagger: response description is ignored with jsonSchemaTransform #47

Open
ricogmacedo opened this issue Mar 30, 2023 · 1 comment
Open

Comments

@ricogmacedo
Copy link

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:
image

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"
      }
   ]
}
@sergiopastan
Copy link

you can use the .describe() function in your zod schema. for example:

const healthcheckSchema: FastifySchema = {
  response: {
    200: z.object({
      status: z.boolean()
    }).describe('Healthy'),
  },
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants