-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG][Python-Flask] Missing required argument on PUT, POST, PATCH #1666
Comments
On the suggested fixes in the petstore example. def add_pet(body): # noqa: E501 which worked fine.
post:
description: Creates a new pet in the store. Duplicates are allowed
operationId: addPet
requestBody:
description: Pet to add to the store
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/NewPet'
x-body-name: new_pet or the components/schemas/NewPet NewPet:
required:
- name
properties:
name:
type: string
tag:
type: string
x-body-name: new_pet the x-body-name isn't copied through to the generated spec in openapi_server/openapi/openaip.yaml. If I manually add it to this file here schema:
x-body-name: new_pet
$ref: '#/components/schemas/NewPet' everything works fine. Thanks for the information above. It helped me get past a sticky spot on my project. |
I just ran into the same problem. |
If you look at the source code for connexion, it tries to send the requestBody content to the operation as a named argument. The argument's name is defaulted to "body" in the absence of "x-body-name" in the I've discovered the third workaround below works if you want to be able to re-generate your code without manually editing either the
|
following up on the earlier comment by @nathan5280, And this is related to issue 3345 which refers back to this issue. |
so maybe this is a fourth workaround, but what I see is that the calling code in return function(**kwargs) … where but in my controller there's: def myfunc(myobj):
#…
if connexion.request.is_json:
myobj = MyObj.from_dict(connexion.request.get_json()) # noqa: E501 so a workaround is to change the signature to |
The problem is that the existing placement of x-body-name is not compliant with OAS3 and so tools will reject it or drop it on the floor like Openapi Generator. Once that's incorporated then the setting will be preserved from the source into the generated code base. |
Since Connexion defaults to using 'body' as the argument name for the requestBody, the controller's argument name is adjusted accordingly.
Description
PUT /data
fails to provide positional argument whenData
is anobject
type.I've seen this also fails with
POST
andPATCH
.Please note that this does work fine when the
Data
is not anobject
type. For example when using:openapi-generator version
I used OpenAPI generator CLI version
4.0.0-SNAPSHOT
:https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/4.0.0-SNAPSHOT/openapi-generator-cli-4.0.0-20181210.103357-85.jar
OpenAPI declaration file content or url
See
python-flask-required-body.yaml
in the attached zip-file:python-flask-required-body.zip
Command line used for generation
Steps to reproduce
Generate the server code
Start the server
Perform a client request
Returns:
Related issues/PRs
Related issues/PRs for
openapi-generator
:I found a similar issue in connexion:
Suggest a fix
Either:
Workaround as used in Remove self-reference import #1758 (commit 39e4441#diff-23008aab5bc1adc4749f4fa8e9ebb94c):
Set the
x-codegen-request-body-name: body
in therequestBody
'sschema
.You need to provide the
x-body-name
in therequestBody
'sschema
so it matches the (positional) function argument name.See also Automatic Parameter Handling at connexion:
Keep name
body
for the (single?) (positional) argument.The text was updated successfully, but these errors were encountered: