Skip to content

Commit 917b6e0

Browse files
authored
Add a section about body parameter name (#170)
1 parent 0fadea9 commit 917b6e0

1 file changed

Lines changed: 59 additions & 0 deletions

File tree

docs/migration-from-swagger-codegen.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,5 +166,64 @@ If you have extended some generators in your project, and you are looking for a
166166

167167
Example: `org.openapitools.codegen.DefaultGenerator`
168168

169+
### Body parameter name
170+
171+
In OpenAPI spec v3, there's no body parameter, which is replaced by [Request Body Object](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#request-body-object). The parameter name for Request Body is named automatically based on the model name (e.g. User). To control how the "Request Body" parmaeter is named, please add the vendor extension `x-codegen-request-body-name` to the operation:
172+
173+
OpenAPI Spec v3:
174+
```
175+
paths:
176+
/pet:
177+
post:
178+
tags:
179+
- pet
180+
summary: Add a new pet to the store
181+
description: ''
182+
operationId: addPet
183+
x-codegen-request-body-name: new_body_name
184+
responses:
185+
'405':
186+
description: Invalid input
187+
security:
188+
- petstore_auth:
189+
- 'write:pets'
190+
- 'read:pets'
191+
requestBody:
192+
$ref: '#/components/requestBodies/Pet'
193+
```
194+
195+
OpenAPI Spec v2:
196+
```
197+
paths:
198+
/pet:
199+
post:
200+
tags:
201+
- pet
202+
summary: Add a new pet to the store
203+
description: ''
204+
operationId: addPet
205+
x-codegen-request-body-name: new_body_name
206+
consumes:
207+
- application/json
208+
- application/xml
209+
produces:
210+
- application/xml
211+
- application/json
212+
parameters:
213+
- in: body
214+
name: body
215+
description: Pet object that needs to be added to the store
216+
required: true
217+
schema:
218+
$ref: '#/definitions/Pet'
219+
responses:
220+
'405':
221+
description: Invalid input
222+
security:
223+
- petstore_auth:
224+
- 'write:pets'
225+
- 'read:pets'
226+
```
227+
If your API client is using named parameters in the function call (e.g. Perl required & optional parameters, Ruby optional parameters), you will need to add `x-codegen-request-body-name` to the spec to restore the original body parameter name.
169228

170229
[Back to OpenAPI-Generator's README page](../README.md)

0 commit comments

Comments
 (0)