Decorator APIProduces doesn't work
See original GitHub issueI’m submitting a Potential bug
[ ] Regression
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request
Current behavior
I use nestjs/swagger
with swagger-ui-express
.
I set the decorator @ApiProduces("text/csv")
but nothing is displayed in Swagger-ui.
I check the produced specs using F12 on Swagger-UI and nothing, in the specs, involved “Produces”.
Expected behavior
The user can choose the Content-Type of the Response in Swagger-UI. As shown on the image below. This image is generated with YAML.
The GET
attribute has :
produces:
- application/json
- text/csv
Minimal reproduction of the problem with instructions
Insert this function in a controller.
@Get('thing')
@ApiProduces("text/csv")
// @ApiProduces("text/csv", "application/json")
public test(): any {
return {
id: "id",
name: "name"
};
}
Environment
Last version.
"@nestjs/common": "^6.7.2",
"@nestjs/config": "0.0.9",
"@nestjs/core": "^6.7.2",
"@nestjs/platform-express": "^6.7.2",
"@nestjs/swagger": "^4.4.0",
"swagger-ui-express": "^4.1.4"
For Tooling issues:
- Platform: Windows
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Specify the return content type of a Controller - Stack Overflow
I found out the solution is to import ApiProduces from '@nestjs/swagger' like so: import { ApiOperation, ApiResponse, ApiUseTags, ...
Read more >OpenAPI (Swagger) | NestJS - A progressive Node.js framework
While the application is running, open your browser and navigate to http://localhost:3000/api . You should see the Swagger UI.
Read more >Downloading files with NestJS - notiz.dev
The decorators for the job are @ApiResponse and @ApiProduces . ... Websites and APIs and develop Open Source tools.
Read more >Describing Responses - Swagger
Note that an API specification does not necessarily need to cover all ... To indicate the response body is empty, do not specify...
Read more >OpenAPI (Swagger) - 《Nest.js v7.0 Document》 - 书栈网
Let's open the browser and verify the generated CreateCatDto model: OpenAPI (Swagger) - 图3. In addition, the @ApiProperty() decorator ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@zachgoll I found a way.
MyModel is a classic Typescript class containing attribute
id
andbody
.Result.
I made a tweak to make this work for Swagger 3 with the JS Codegen tool:
The Swagger JSON produced looks like this:
Which matches the Swagger 3 Docs for Binary Files: https://swagger.io/docs/specification/basic-structure/