OpenAPITools / OpenAPITools/openapi-generator
[BUG] [Python-Flask] to_dict() return _auth_settings instead of auth_settings
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?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
We have a model as below which is the response of /test API
TestResponse:
type: object
properties:
auth_settings:
type: object
When we execute to_dict() function on above modal we get below response
{
"_auth_settings": {}
}
Instead of this
{
"auth_settings": {}
}
openapi-generator version
5.1.0
OpenAPI declaration file content or url
openapi: 3.0.0
info:
title: Bug
version: 0.1.9
components:
schemas:
TestResponse:
type: object
properties:
auth_settings:
type: object
paths:
/test:
get:
summary: Test api to reproduce the bug
responses:
'200':
description: Response object
content:
application/json:
schema:
$ref: '#/components/schemas/TestResponse'
Generation Details
Install & Generate server code
npx @openapitools/openapi-generator-cli generate -i openapi.yaml -g python-flask
Code to be added
In the controller/default_controller.py file replace the test_get function with below function
def test_get(): # noqa: E501
"""Test api to reproduce the bug
# noqa: E501
:rtype: TestResponse
"""
payload = TestResponse.from_dict(
{
"auth_settings": {}
}
)
return payload.to_dict(), 200
Steps to reproduce
- Use the YAML file given and generate to follow the steps given in the Generation Detail section
- Make the code changes mentioned in the code to be added section
- Run the Flask server using this command
python -m openapi_server - Now trigger a GET request to this URL
http://localhost:8080/test - Now we can notice that instead of
auth_settingswe get_auth_settingsin the returned response
Related issues/PRs
Suggest a fix
By looking at the model file we notice that attribute_map hold the mapping
self.attribute_map = {
'_auth_settings': 'auth_settings'
}
and in to_dict() function we can use the attribute_map to convert _auth_settings to auth_settings
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
Generate the Python-Flask server from the supplied OpenAPI YAML, then inspect the generated TestResponse model and controller/default_controller.py. Start with the model's to_dict() and attribute_map behavior, reproduce the GET response, and confirm the returned key matches the schema's auth_settings name.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- flask, python
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100