Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #9332
Closed
Open
Issue created Apr 24, 2021 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[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
  1. Use the YAML file given and generate to follow the steps given in the Generation Detail section
  2. Make the code changes mentioned in the code to be added section
  3. Run the Flask server using this command python -m openapi_server
  4. Now trigger a GET request to this URL http://localhost:8080/test
  5. 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

Assignee
Assign to
Time tracking