OpenAPITools/openapi-generator

[Python] boolean query parameter capitalization

Chiusa

#1260 aperta il 17 ott 2018

 (16 commenti) (0 reazioni) (0 assegnatari)Java (7516 fork)batch import
Client: PythonGood First IssueIssue: Bug

Metriche repository

Star
 (26.243 stelle)
Metriche merge PR
 (Merge medio 9g 1h) (123 PR mergiate in 30 g)

Descrizione

(Copy of https://github.com/swagger-api/swagger-codegen/issues/8433)

Description

The generated python client translates boolean query parameters in Python case - i.e. "True"/"False" rather than "true"/"false".

I am dealing with a case-sensitive API endpoint, which expects a boolean query parameter, and treats anything except "0" and "false" as true - including "False" evaluating to true.

Per RFC 3986, the query part of a URI should be treated as case-sensitive. I suspect many (most?) servers in the wild expect "false", in line with the variable names in most languages.

Is this expected behavior?

Swagger-codegen version

2.4.0-SNAPSHOT

Swagger declaration file content or url

        "parameters": [
          {
            "name": "reverse",
            "in": "query",
            "description": "If true, will sort results newest first.",
            "required": false,
            "default": false,
            "type": "boolean"
          }
        ],

Command line used for generation

java -jar ./swagger-codegen/modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i ./swagger.json -l python -o generated/python

Steps to reproduce

# given an API endpoint which accepts a boolean query parameter
>>> foo_list = client.Foo.Foo_get(reverse=True)
>>> foo_list.future.request.prepare()
>>> print(foo_list.url)
http://example.com/api/foo?reverse=True

Suggest a fix/enhancement

Suggestion: instead of "True" or "False", convert to the string "true" or "false".

Guida contributor