OpenAPITools / OpenAPITools/openapi-generator
[BUG][python-flask] actual operation argument not passed to implementation function
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists? - NO - I've been using the online code generator at api.openapi-generator.tech/api/gen/servers to create the python-flask server code.
- Have you searched for related issues/PRs?
- What's the actual output vs expected output? - I would expect the 'additionalMetadata' request body property to be passed as a kwargs argument to the operation's implementation function.
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
While the file property of the request body payload (in the below OpenAPI specification yaml snippet) is properly conveyed from the api client, the additionalMetadata property is not passed as an argument to the operation's implementation function. Stepping through the Connexion code in a debugging session shows me that the actual argument is received from the client and all is good up until the connexion.decorators.parameter.py (lines 101..121) code that builds up the kwargs dictionary that is eventually unpacked as part of the invocation of the operation's implementation function at line 121 (at that point, kwargs is missing the 'additionalMetadata' key that is found within the request_body dictionary that's passed to operation.get_arguments() at line 102.
What I suspect the issue is (& I don't yet know why): has_kwargs is false, causing connexion.operations.abstract.py's _get_body_arguments() to
not populate the resulting dictionary with the contents of the body dictionary argument.
Or it's more likely that I'm not doing something correctly as I'm quite new to using the entire openapi-generator ecosystem.
Perhaps my specification is incomplete, thus causing the has_kwargs to be false?
MTIA for any feedback on what I'm doing wrong.
openapi-generator version
Using the online generator - downloaded .openapi-generator/VERSION => 5.0.0-beta3
OpenAPI declaration file content or url
most of my OpenAPI yaml is excluded for brevity's sake
# the POST's
requestBody:
required: true
content:
multipart/form-data:
schema:
$ref: '#/components/schemas/uploadFile'
components:
schemas:
uploadFile:
type: object
properties:
additionalMetadata:
description: Additional data to pass to server
type: string
file:
description: file to upload
format: binary
type: string
Generation Details
I'm using the online generator at api.openapi-generator.tech, providing the "options": { "packageName": "swagger_client", "library": "urllib3" }
^^^ using swagger_client to preserve the naming used when I initially started using Swagger codegen generated code prior to switching to openapi-generator.tech and using the /api/gen/servers/python-flask endpoint.
Steps to reproduce
Related issues/PRs
Suggest a fix
I have to assume it's something I've managed to do wrong as this seems like a pretty simple use case and the connexion.operations.openapi.py OpenAPIOperation._get_body_argument() must be pretty thoroughly verified for such a use case.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the generated python-flask server and the Connexion paths mentioned: connexion.decorators.parameter.py and connexion.operations.abstract.py, especially _get_body_arguments(), plus connexion.operations.openapi.py. Reproduce the multipart/form-data request using the uploadFile schema, then trace operation.get_arguments() through invocation; done means additionalMetadata reaches the implementation function as an argument.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- flask, python
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 28/100