OpenAPITools / OpenAPITools/openapi-generator

[BUG] python-flask controller test uses true instead of True

Open
#4,953 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug Server: Python
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Boolean values get parsed badly in flask.

openapi: 3.0.0
info:
  title: Bar
  description: Foo
  version: 0.1.0
paths:
  /foo:
    post:
      summary: Bar
      description: desc
      requestBody:
        description: Optional description in *Markdown*
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ScenarioParameters'
      responses:
        '200':    # status code
          description: A JSON object containing the result data
          content:
            application/json:
              schema: 
                type: string

components: 
  schemas:
    ScenarioParameters:
      type: object
      properties:
        foo:
          type: boolean

leads to

class TestDefaultController(BaseTestCase):
    """DefaultController integration test stubs"""

    def test_foo_post(self):
        """Test case for foo_post

        Bar
        """
        scenario_parameters = {
  "foo" : true
}
        headers = { 
            'Accept': 'application/json',
            'Content-Type': 'application/json',
        }
        response = self.client.open(
            '/foo',
            method='POST',
            headers=headers,
            data=json.dumps(scenario_parameters),
            content_type='application/json')
        self.assert200(response,
                       'Response body is : ' + response.data.decode('utf-8'))

in the test_default_controller.py. Note the true instead of True

I believe a fix is to wrap this line the {{{example}}} which is a JSON document into a

"""
{{{example}}}
"""

multi line python string and then set data=json.dumps(...) to the value directly

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with modules/openapi-generator/src/main/resources/python-flask/controller_test.mustache around the linked line, then compare its output with the generated test_default_controller.py shown in the issue. Regenerate a Python Flask controller test and verify that the boolean example is valid Python and the resulting test runs successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
flask, python
Domain
backend, testing
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.