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.66k stars 6.53k forks source link

[BUG][PYTHON] Generated python-flask server stub enum strings don't have quotes #13689

Open renxinhe opened 2 years ago

renxinhe commented 2 years ago

Bug Report Checklist

Description

Generated python server stub doesn't have quotes around the enum values. This generates python code with syntax errors.

OpenAPI 3.0 YAML input:

status:
    type: string
    description: status
    enum:
      - local
      - invited
      - accepted
      - confirmed
      - rejected

Generated python model stub code:

    @status.setter
    def status(self, status):
        """<omitted>
        """
        allowed_values = [None,local, invited, accepted, confirmed, rejected]  # noqa: E501
        if status not in allowed_values:
            raise ValueError(
                "Invalid value for `status` ({0}), must be one of {1}"
                .format(status, allowed_values)
            )

        self._status = status

Notice that the line allowed_values = ... isn't valid python code. The enum values need to be surrounded by quotes because they are string types.

openapi-generator version

6.2.0

OpenAPI declaration file content or url
status:
    type: string
    description: status
    enum:
      - local
      - invited
      - accepted
      - confirmed
      - rejected
Generation Details
 java -jar openapi-generator-cli.jar generate -g python-flask -i '/tmp/api.yaml' -o '/tmp/codegen_test'
Steps to reproduce

Simply run the codegen CLI and check the output file to see the missing quotes in the stub.

Related issues/PRs

This issue is similar to https://github.com/OpenAPITools/openapi-generator/issues/3196, but the opposite direction. Here we have manually defined an OpenAPI 3.0 YAML, and want to generate python server stub.

Suggest a fix

I'd imagine this bug is specific to the python flask server generator. I'm not too familiar with the code base to navigate to the culprit.

OJFord commented 1 year ago

This seems to be a regression in 6.1.0, downgrade to 6.0.0 to work around.