You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Our team has been experiencing this issue since we upgraded from @nestjs/swagger@4.8.2, it is a weird one and took time to find. It appears that there is an issue with with multiple specifications. It fails to create the enum for specifications for the following specifications. It will show the enum only in the first specification when the enum is define with both ApiQuery and ApiProperty.
import{NestFactory}from'@nestjs/core';import{DocumentBuilder,SwaggerModule}from'@nestjs/swagger';import{AppModule}from'./app.module';import{CatsModule}from'./cats/cats.module';asyncfunctionbootstrap(){constapp=awaitNestFactory.create(AppModule);constoptions=newDocumentBuilder().setTitle('Cats example').setDescription('The cats API description').setVersion('1.0').addTag('cats').build();constcatDocument=SwaggerModule.createDocument(app,options,{include: [CatsModule],});SwaggerModule.setup('api/cats',app,catDocument);constsecondOptions=newDocumentBuilder().setTitle('Broken example').setDescription('The cats API with missing enum').setVersion('1.0').addTag('broken').build();constdocument=SwaggerModule.createDocument(app,secondOptions,{include: [CatsModule],});SwaggerModule.setup('api',app,document);awaitapp.listen(3000);}bootstrap();
npm run start:dev
Go to http://localhost:3000/api-json
Expected behavior
The enum schema CollarColor should be defined with enum values and not only appear as type string in the specification. It should be expected that both the http://localhost:3000/api-json specification and http://localhost:3000/api/cats-json should be identical.
Package version
6.1.3
NestJS version
9.1.5
Node.js version
v18.12.1
In which operating systems have you tested?
macOS
Windows
Linux
Other
No response
The text was updated successfully, but these errors were encountered:
Is there an existing issue for this?
Current behavior
Our team has been experiencing this issue since we upgraded from
@nestjs/swagger@4.8.2
, it is a weird one and took time to find. It appears that there is an issue with with multiple specifications. It fails to create the enum for specifications for the following specifications. It will show the enum only in the first specification when the enum is define with bothApiQuery
andApiProperty
.Minimum reproduction code
https://github.com/DJCrossman/nest-swagger-multi-spec-enums-bug
Steps to reproduce
nest new project-name
cd project-name
npm install @nestjs/swagger
nest g module cats
nest g class cats/cat --flat
Edit
src/cats/cat.ts
, to haveCollarColorEnum
andApiProperty
:nest g controller cats
Edit
src\cat\cat.controller.ts
, to havefind
endpoint:Initialize Swagger with multiple specifications:
npm run start:dev
Go to
http://localhost:3000/api-json
Expected behavior
The enum schema
CollarColor
should be defined with enum values and not only appear as typestring
in the specification. It should be expected that both thehttp://localhost:3000/api-json
specification andhttp://localhost:3000/api/cats-json
should be identical.Package version
6.1.3
NestJS version
9.1.5
Node.js version
v18.12.1
In which operating systems have you tested?
Other
No response
The text was updated successfully, but these errors were encountered: