OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.49k stars 6.5k forks source link

[python-flask] controller_test generates syntactically invalid python when given an example of type (string) to URL params #5819

Open at3560k opened 4 years ago

at3560k commented 4 years ago
Description

When I supply a configuration in the style of:

"paths": {
    "/a/{artifact_id}/b" : {
      "post" : {
        "parameters" : [ {
          "description" : "xyz",
          "example" : "some string",
          "explode" : false,
          "in" : "path",
          "name" : "artifact_id",
          "required" : true,
          "schema" : {
            "type" : "string"
          },
          "style" : "simple"
        } ],
...

and run openapi-generator, $output/$package/test/test_a_controller.py is generated containing python that reads:

        response = self.client.open(
            '/api/v1/a/{artifact_id}/b'.format(artifact_id=some string),   # <-- my emphasis, bug
            method='POST',
            headers=headers,
            data=json.dumps(attestation),
            content_type='application/json')

the argument parameter artifact_id=some string) is invalid -- but not quoted as a string to python, and supplied very literally. Eg. if the example read:

   example: "url_encode: 0/0"

it would would render that as unquoted python.

openapi-generator version

4.2.3 (supplied via python/pip) -- I have seen this apparent bug in master

OpenAPI declaration file content or url

(I'll render a full test case if requested, I think it's apparent from the above and probably near existing fixtures)

Command line used for generation
openapi-generator generate \
   -c generator-config.yaml \
   -i openapi/openapi.yaml \
   -g python-flask -o serverstub
# generator-config.yaml
packageName: xxxx
packageVersion: 1.0.0
serverPort: 8080
enablePostProcessFile: true
generateAliasAsModel: true
Steps to reproduce
Related issues/PRs

(not found)

Suggest a fix/enhancement

https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/python-flask/controller_test.mustache#L42

I believe the issue is in this line of code, with a lack of quoting -- but I have not traced into how th example object is ... typed in or by mustache yet.

auto-labeler[bot] commented 4 years ago

👍 Thanks for opening this issue! 🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.