[BUG] [Python-Flask] to_dict() return _auth_settings instead of auth_settings
Created by: mabhijith95a10
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_settings
we get_auth_settings
in 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