jayalfredprufrock / nestjs-typebox

Various utilities for integrating Typebox and NestJs for both validation and OpenApi schema generation
MIT License
27 stars 4 forks source link

`description` prop from Typebox schema does not propagate to Swagger generation. #54

Closed Omri-Levy closed 7 months ago

Omri-Levy commented 7 months ago

Description

Missing fields from OpenAPI generation such as description or example, name is used as the description, if example is specified then its used as a description.

How it was reproduced

  1. The endpoint I created
    @HttpEndpoint({
    path: ':id',
    method: 'POST',
    validate: {
      request: [
        {
          type: 'param',
          name: 'id',
          schema: Type.String({
            description: 'The id of the user',
            example: '123',
          }),
        },
      ],
    },
    })
    create() {
    return;
    }
  2. Generated Swagger With example image Without example image

Thanks a lot for the package, your time, and your work. Please let me know if there is any more information I can provide. 🙏🏼

jayalfredprufrock commented 7 months ago

Thanks for reporting! This isn't expected behavior for sure so I'll definitely look into this. Most of the heavy lifting is being done by the NestJs ApiParam decorator. This library just passes on the typebox schema (which is just a JSON schema object at runtime) so it could be a problem downstream somewhere. I'm fairly positive this used to work so I'll have to do some experimentation on my end to see when/where its breaking down.

jayalfredprufrock commented 7 months ago

So quick followup - I just took a look at a generated openapi file for one of my projects and both the example and description are coming through as expected for request params. This is on typebox@0.32.15, nestjs-typebox@3.0.0-next.7, and @nestjs/swagger@7.3.0.

Which versions of the above packages are you on? Could you also post what the generated openapi file looks like for your examples above? At this point, all signs are pointing to some kind of legacy bug / version incompatibility or possibly the swagger UI generator itself.

Omri-Levy commented 7 months ago

Hey, I am using the same version for each of the packages you've listed. Here's the generated openapi file.

{
  "openapi": "3.0.0",
  "paths": {
    "/{id}": {
      "post": {
        "operationId": "AppController_create",
        "summary": "",
        "parameters": [
          {
            "name": "id",
            "required": true,
            "in": "path",
            "schema": {
              "description": "The id of the user",
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": ""
          }
        }
      }
    }
  },
  "info": {
    "title": "Cats example",
    "description": "The cats API description",
    "version": "1.0",
    "contact": {}
  },
  "tags": [
    {
      "name": "cats",
      "description": ""
    }
  ],
  "servers": [],
  "components": {
    "schemas": {}
  }
}
Omri-Levy commented 7 months ago

Hey, thanks for everything! The packages had ^ in their versions. The moment I removed the ^ it worked. Thanks for a great library. 🙂