issues with nestJS/swagger

Originally posted by topachi on May 24, 2024

Hello, i have a few issues regarding NESTJS/SWAGGER

  1. missing namespace in swagger UI

when it should be

  1. if there are different classes/namespaces with the same class name, swagger will not show the schema anymore:

if i have more than one class with the same name although different interface implementation, swagger will not show up the schema properly. it will result empty:

  1. when generating json/yaml from nestjs/swagger, we get all “object” instead of real class names AND description/class of body/params don’t show, but response does.

Can you please help me? It is for our project very important to know why of those issues.

Cheers

Originally posted by Humashankar on May 27, 2024

Hi topachi

Ensure you’re using the latest versions of both packages. Double-check custom configurations that might interfere with namespace handling and consider reverting to default settings will sort namespace recognition issues

Use the @ApiOperation decorator with unique operationId properties for each endpoint to help Swagger distinguish between operations. Instead, consider renaming classes to avoid confusion and enhance code readability.

Set the SWAGGER_AUTO_SCHEMA_OPTIONS environment variable to true to instruct NestJS/Swagger to leverage class information for schema generation. Explore @nestjs/swagger configuration options to control the level of detail in generated records, including descriptions and class names

Hope this helps - Happy to help further!!
Thank you very much and have a great one!
Warm regards

Originally posted by topachi on May 27, 2024

Hello, thanks for the reply.

the operationId is not working as intended, and the SWAGGER_AUTO_SCHEMA_OPTIONS cannot be found anywhere on nestjs/swagger. any hint?

Originally posted by Humashankar on May 28, 2024

Hi topachi

Thanks for adding your clarification points:

Verify that the decorator is being used correctly and double-check for any typos in the operationId property. If operationId isn’t functioning as anticipated, try using separate path names for your controllers and methods to distinguish them in the Swagger UI. Also, make sure to check the version of NestJS and Swagger you’re using, as the behavior may have changed in earlier versions

To enable automatic generation of Swagger schema files from class information, set the environment variable SWAGGER_AUTO_SCHEMA_FILE to true.

This will initiate NestJS/Swagger to create the schema files automatically.

Regards