swagger
swagger copied to clipboard
@Body() decorator with param broke swagger, swagger plugin auto @ApiProperty() doesn't work
I'm submitting a...
[ x ] Regression
[ x ] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Current behavior
I faced 2 issues when I use NestCLI to start my application with swagger plugin in nest-cli.json:
-
@Body('param')
is not part of the request, I have to write wrapper DTO or use schema - The auto
@ApiProperty()
doesn't work. I have to use @ApiProperty in all of my DTO files.
I tried to reproduce nest-example-cats-swagger in my own repository, but it doesn't work like the Docs mentions here
Expected behavior
- When I use
@Body('param')
, swagger maybe could wrap the type inside that parameter name.
@Post('noDoc/param/scheme')
@ApiBody({
schema: {
type: 'object',
properties: {
user: { // the `user` word comes from @Body('user')
properties: { // these properties are coming from `UserDto`
id: { type: 'number' },
username: { type: 'string' },
email: { type: 'string' },
},
},
},
},
})
async noDocParamScheme(@Body('user') user: UserDto) {
return user;
}
- Swagger plugin should properly create
@ApiProperty
Minimal reproduction of the problem with instructions
You can check it in my test-repository: https://github.com/PoOwAa/nestjs-swagger-body-param-bug
What is the motivation / use case for changing the behavior?
At least @Body()
without params should work like in the documentation.
Environment
[System Information]
OS Version : Linux 5.3
NodeJS Version : v12.16.1
NPM Version : 6.14.4
[Nest CLI]
Nest CLI Version : 7.1.2
[Nest Platform Information]
platform-express version : 7.0.0
swagger version : 4.5.1
common version : 7.0.0
core version : 7.0.0
I noticed today that SOME of my DTO schemas are not described completely in Swagger (they were a few days ago). I went through all the settings in docs again, updated dep., I have my plugin configured correctly. I checked that the swagger description works again when I add ApiProperty()
.
I will try to add more info later.
[System Information]
OS Version : Windows 10
NodeJS Version : v12.16.1
NPM Version : 6.14.4
[Nest CLI]
Nest CLI Version : 7.1.1
[Nest Platform Information]
platform-express version : 7.0.8
swagger version : 4.5.3
common version : 7.0.8
config version : 0.4.0
core version : 7.0.8
I tried to nest update
from these versions today to solve the issue..
"@nestjs/common": "^7.0.7",
"@nestjs/config": "0.4.0",
"@nestjs/core": "^7.0.7",
"@nestjs/platform-express": "^7.0.7",
"@nestjs/swagger": "^4.5.1",
I also have same issue
I'm encountering the same behavior as well.
I also have this issue.
I also have same issue
I also have same issue
I also have same issue
having the same issue, swagger-cli does not work as expected.
Exact same problem here, need to use @ApiProperty() directly for it to work.
I also have same issue
I also have same issue
I also have same issue
Any news on this? I have the same issue.
I want a little bit to promote this issue, as my company is also catching it.
I had the same issue and could resolve it by including ExtraModels to swagger main configuration: docs
@Akhouad Docs mention that you need to use it for models, which are not referenced by any controllers. But my controller is using the DTO, and I can create manually with ApiProperty decorator, but nest-cli promises, that it can find out automagically without manual description.
Did you add the ApiExtraModels decorator to a DTO, which is already referenced in a controller?
@PoOwAa , i basically had this issue after trying to create a new decorator for a paginated response, following the steps in this docs page and the error I had was complaining about PaginatedDto schema which couldn't be resolved, so I added the extraModels in swagger main configuration with PaginatedDto, it looked like this:
const document = SwaggerModule.createDocument(app, config, {
extraModels: [PaginatedDto]
});
Any update on this issue?
I am facing the same thing. As described this happened when setting the property attribute like @Body(‘property’)
@PoOwAa , i basically had this issue after trying to create a new decorator for a paginated response, following the steps in this docs page and the error I had was complaining about PaginatedDto schema which couldn't be resolved, so I added the extraModels in swagger main configuration with PaginatedDto, it looked like this:
const document = SwaggerModule.createDocument(app, config, { extraModels: [PaginatedDto] });
It's works for me!
same issue.
It doesn't work without adding the @ApiPropterty()
decorator.
IT does give error for circular dependency if we add the model in API extra models.
I was following along with the docs on using a Generic schema + using the CLI Plugin. This was giving me the circular dep error that @ankibalyan mentioned above. I was able to fix this by manually setting an @ApiProperty
for the generic property, so PaginatedDto
would look like this:
export class PaginatedDto<TData = unknown> {
total: number;
limit: number;
offset: number;
@ApiProperty({ type: () => Array })
results: TData[];
}