Allow to change body parameter name derived from @Body()
See original GitHub issueI’m submitting a…
[ ] Regression
[ ] Bug report
[x] 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 wrote a controller like this:
@Post('/')
@ApiImplicitBody({ name: 'body', type: MemberCreatePayloadApi })
public async create(@Body() payload: MemberCreatePayloadApi): Promise<Member> {
}
SwaggerModule produces the below api from my controller.
"post": {
"parameters": [
{
"name": "body",
"required": true,
"in": "body",
"isArray": false,
"schema": {
"$ref": "#/definitions/MemberCreatePayloadApi"
}
},
{
"name": "MemberCreatePayloadApi",
"required": true,
"in": "body",
"schema": {
"$ref": "#/definitions/MemberCreatePayloadApi"
}
},
],
Expected behavior
@Body()
makes a parameter named by argument type. But I want to change parameter name as I like.
# Expected output
"post": {
"parameters": [
{
"name": "body",
"required": true,
"in": "body",
"isArray": false,
"schema": {
"$ref": "#/definitions/MemberCreatePayloadApi"
}
},
],
I try to modify explorer, the below code is expected to me but it may lose backward compatibility.
https://github.com/nestjs/swagger/blob/master/lib/explorers/api-parameters.explorer.ts#L90
- val => val.in === DEFAULT_PARAM_TOKEN || (val.name && val.in === 'body')
+ val => val.in === DEFAULT_PARAM_TOKEN || (val.in === 'body')
What is the motivation / use case for changing the behavior?
A client library swagger-js users should name request body parameter body
.
Environment
@nestjs/core: 5.5.0
@nestjs/swagger: 2.5.1
Thanks.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:4
- Comments:12 (3 by maintainers)
Top Results From Across the Web
c# - How can I change the parameter name in the request body?
I have this model 'LoginModel'. I use this class on the controller tho get the values from the body like this. So to...
Read more >Describing Request Body - Swagger
The POST, PUT and PATCH requests can have the request body (payload), such as JSON or XML data. In Swagger terms, the request...
Read more >Body - Multiple Parameters - FastAPI
First, of course, you can mix Path , Query and request body parameter ... BaseModel app = FastAPI() class Item(BaseModel): name: str description:...
Read more >Parameter Binding in ASP.NET Web API - ASP.NET 4.x
In this example, Web API will use a media-type formatter to read the value of name from the request body. Here is an...
Read more >Request Handling — Connexion 3.0.dev0 documentation
In the OpenAPI 3.x.x spec, the requestBody does not have a name. By default it will be passed in as 'body'. You can...
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
@kamilmysliwiec Hi, I fixed this issue as above. Can I get your opinion?
Added in the
next
version (to install runnpm i @nestjs/swagger@next
). Note: remember to update@nestjs/common
,@nestjs/core
andtypescript
as well to ensure that you’re using the latest versions.Steps to migrate: https://github.com/nestjs/swagger/pull/355#issuecomment-547925879