When sending a GET request, an additional body keyword argument is sent to the handling function, causing it to fail with TypeError: some_function() got an unexpected keyword argument 'body'.
Only the described parameters should be forwarded to the function. Also, according to the spec, it seems that there should be no body provided on GET and DELETE.
A body keyword argument is added as a function parameter.
requirements.txt
flask==1.0.2
requests==2.20.0
connexion==2.0.1
api.yaml
openapi: 3.0.0
info:
version: '1'
title: Sample HTTP GET endpoint
paths:
'/{some_param}':
get:
description: Testing
operationId: app.sample_get
parameters:
- name: some_param
in: path
required: true
schema:
type: string
responses:
default:
description: OK
app.py
def sample_get(**kwargs):
return kwargs
Run application and send request
connexion run api.yaml
python -c 'import requests; print(requests.get("http://localhost:5000/testing").text)'
Returns
{
"body": {},
"some_param": "testing"
}
Expected return:
{
"some_param": "testing"
}
Unfortunately in OpenAPI 3 specs the request body does not have a name.
We support assigning it a name with the 'x-body-name' key, but by default
it is called body.
x-body-name works like this:
requestBody:
content:
application/json:
schema:
x-body-name: pet
$ref: '#/components/schemas/Pet'
On Wed, Nov 7, 2018, 6:16 AM PÃ¥l Nes notifications@github.com wrote:
Description
When sending a GET request, an additional empty body keyword argument is
sent to the handling function.
Expected behaviourOnly the described parameters should be forwarded to the function. Also,
according to the spec, it seems that there should be no body provided on
GET and DELETE.
Actual behaviourAn empty body keyword argument is added as a function parameter.
Steps to reproducerequirements.txt
flask==1.0.2
requests==2.20.0
connexion==2.0.1api.yaml
openapi: 3.0.0info:
version: '1'
title: Sample HTTP GET endpoint
paths:
'/{some_param}':
get:
description: Testing
operationId: app.sample_get
parameters:
- name: some_param
in: path
required: true
schema:
type: string
responses:
'200':
description: OK
'400':
description: Bad request.
default:
description: Errorapp.py
def sample_get(**kwargs):
return kwargsRun application and send request
connexion run api.yaml
python -c 'import requests; print requests.get("http://localhost:5000/testing").text'Returns
{
"body": {},
"some_param": "testing"
}Additional info:
- Python 2.7.10
- connexion 2.0.1
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/zalando/connexion/issues/757, or mute the thread
https://github.com/notifications/unsubscribe-auth/AAlPSbuxJssbT0cEj8yyLVk5RasVu0Exks5ususugaJpZM4YSglU
.
oops I misread your ticket. body should definitely not be passed in on GET
requests!
On Wed, Nov 7, 2018, 7:13 AM Daniel Grossmann-Kavanagh me@danielgk.com
wrote:
Unfortunately in OpenAPI 3 specs the request body does not have a name.
We support assigning it a name with the 'x-body-name' key, but by default
it is called body.x-body-name works like this:
requestBody: content: application/json: schema: x-body-name: pet $ref: '#/components/schemas/Pet'On Wed, Nov 7, 2018, 6:16 AM PÃ¥l Nes notifications@github.com wrote:
Description
When sending a GET request, an additional empty body keyword argument is
sent to the handling function.
Expected behaviourOnly the described parameters should be forwarded to the function. Also,
according to the spec, it seems that there should be no body provided on
GET and DELETE.
Actual behaviourAn empty body keyword argument is added as a function parameter.
Steps to reproducerequirements.txt
flask==1.0.2
requests==2.20.0
connexion==2.0.1api.yaml
openapi: 3.0.0info:
version: '1'
title: Sample HTTP GET endpoint
paths:
'/{some_param}':
get:
description: Testing
operationId: app.sample_get
parameters:
- name: some_param
in: path
required: true
schema:
type: string
responses:
'200':
description: OK
'400':
description: Bad request.
default:
description: Errorapp.py
def sample_get(**kwargs):
return kwargsRun application and send request
connexion run api.yaml
python -c 'import requests; print requests.get("http://localhost:5000/testing").text'Returns
{
"body": {},
"some_param": "testing"
}Additional info:
- Python 2.7.10
- connexion 2.0.1
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/zalando/connexion/issues/757, or mute the thread
https://github.com/notifications/unsubscribe-auth/AAlPSbuxJssbT0cEj8yyLVk5RasVu0Exks5ususugaJpZM4YSglU
.
@palnes can you take a look at #761 please?
Cool beans! That works for me. :)
Unfortunately in OpenAPI 3 specs the request body does not have a name. We support assigning it a name with the 'x-body-name' key, but by default it is called body. x-body-name works like this:
requestBody:
content:
application/json:
schema:
x-body-name: pet
$ref: '#/components/schemas/Pet'
This doesn't seem valid OAS to me though. @dtkav
@ioggstream which part is invalid?
iirc siblings values alongside $refs are ignored, and other processors could strip that field.
I know this issue is closed but others reading this might find it useful to know that while the OpenAPI & Swagger code generators don't include the x-body-name property as shown above nor do those tools preserve the x-body-name property in the resulting run-time specification YAML, if added manually prior to running a server utilizing the spec, the OpenAPI 5.0.1 OpenAPIOperation._get_body_arguments function will make use of the property.
If the x-body-name is placed in the actual schema type definition (so the usage follows the restriction as mentioned above by @ioggstream and in the docs at :
schemas:
ParseModelRequest:
type: object
x-body-name: parse_model_request
properties:
modelRequest:
$ref: '#/components/schemas/ProjectDataRequest'
elements:
$ref: '#/components/schemas/Elements'
The OpenAPI python-flask code generator will keep the x-body-name there & the run-time usage works.
I need to evaluate any effect on the generated python client code.