Add a section about body parameter name (#170)

This commit is contained in:
William Cheng
2018-05-29 00:35:37 +08:00
committed by GitHub
parent 0fadea9986
commit 917b6e0105

View File

@@ -166,5 +166,64 @@ If you have extended some generators in your project, and you are looking for a
Example: `org.openapitools.codegen.DefaultGenerator`
### Body parameter name
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:
OpenAPI Spec v3:
```
paths:
/pet:
post:
tags:
- pet
summary: Add a new pet to the store
description: ''
operationId: addPet
x-codegen-request-body-name: new_body_name
responses:
'405':
description: Invalid input
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
requestBody:
$ref: '#/components/requestBodies/Pet'
```
OpenAPI Spec v2:
```
paths:
/pet:
post:
tags:
- pet
summary: Add a new pet to the store
description: ''
operationId: addPet
x-codegen-request-body-name: new_body_name
consumes:
- application/json
- application/xml
produces:
- application/xml
- application/json
parameters:
- in: body
name: body
description: Pet object that needs to be added to the store
required: true
schema:
$ref: '#/definitions/Pet'
responses:
'405':
description: Invalid input
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
```
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.
[Back to OpenAPI-Generator's README page](../README.md)