OpenAPITools / OpenAPITools/openapi-generator
[BUG] Generator python-flask generates parameters for header parameters and body request data
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 validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
Description
The OpenAPI spec bellow contains a header parameter (in:header) named dateTimeLastModified.
According to the docs, header parameters should be supported by the generator.
The generated controller looks like this:
def patientinfo_id_put(id, date_time_last_modified, patient_info_dto): # noqa: E501
date_time_last_modified = util.deserialize_datetime(date_time_last_modified)
if connexion.request.is_json:
patient_info_dto = PatientInfoDto.from_dict(connexion.request.get_json()) # noqa: E501
return 'do some magic!'
With reference to the parameters of the generated handler function above:
- The
date_time_last_modifiedis passed as a parameter to the handler function. The flask documentation states that this is not supported and the header parameter should be accessed via theconnexion.request.headersobject. - The
patient_info_dtoobviously reflects the request body data. Whiledate_time_last_modifiedis actually used in the generated code,patient_info_dtois ignored completely and overwritten by the correct way to access the body data.
Request error out with:
TypeError: api_v1_patientinfo_id_put() missing 2 required positional arguments: 'dateTimeLastModified' and 'patient_info_dto'
I guess the expected behaviour is to generate the handler function without header parameters and request body parameter and change the default code to accessing the header parameters directly from the connexion.request.headers object.
openapi-generator version
- openapi-generator-cli: 5.1.0
- commit: e023eaa
- built: 2021-03-20T09:44:04Z
OpenAPI declaration file content or url
put:
tags:
- Patient Information
summary: "..."
description: "..."
parameters:
- name: id
in: path
description: The patient info identifier.
required: true
schema:
type: string
- name: dateTimeLastModified
in: header
description: The date and time when the patient information was last modified.
required: true
schema:
type: string
format: date-time
requestBody:
description: The patient information to update.
content:
application/json:
schema:
$ref: "#/components/schemas/PatientInfoDto"
required: true
responses:
"200":
description: successful update of the patient information.
content:
application/json:
schema:
$ref: "#/components/schemas/PatientInfoMetadataDto"
"400":
description: operation failed due to missing or invalid input parameters.
"401":
description: client cannot be authenticated.
"403":
description: client is not allowed to execute the operation.
content:
application/json:
schema:
$ref: "#/components/schemas/StatusMessageDto"
"404":
description: patient information identifier not found.
"409":
description: operation cannot be processed, patient information is outdated.
Generation Details
docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli:v5.1.0 generate \
-i /local/api_spec_v1.yml \
-g python-flask \
--minimal-update \
-o /local/server
Steps to reproduce
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 by running the provided Docker generation command with the YAML declaration and inspect the generated Python Flask controller. Trace how the header parameter and requestBody become handler arguments, then compare the result with connexion.request.headers and connexion.request.get_json(). Done means the generated handler no longer requires those incorrectly generated arguments and the request succeeds.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- flask, openapi, python
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100