Skip to content

[BUG][PYTHON] Enum default values in generated Python client are not quoted in README example (regression from v5.4 to v7.16) #22239

Description

@soGit

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • 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?
Description

After migrating from openapi-generator v5.4 to v7.16.0 (Docker image: openapitools/openapi-generator-cli:v7.16.0), the generated Python client's README example for string enum parameters no longer quotes the default value. In v5.4, the example showed:

order_by = "date_status_changed" # str | ... (default to "date_status_changed")

but in v7.16, the output is:

order_by = date_status_changed # str | ... (default to date_status_changed)

This is not valid Python and breaks copy-paste experience. There are no custom templates used.

openapi-generator version

Tested:

  • v5.4 (previously worked as expected)
  • v7.16.0 (regression)
OpenAPI declaration file content or url
openapi: 3.0.0
info:
  title: Test Enum Default Value
  version: 1.0.0
servers:
  - url: https://api.example.com
paths:
  /test:
    get:
      summary: Test endpoint with enum parameter
      operationId: testEnum
      parameters:
        - name: order_by
          in: query
          schema:
            type: string
            enum:
              - 'name'
              - 'date_created'
              - 'date_status_changed'
            default: 'date_status_changed'
          description: Test ordering parameter
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                properties:
                  result:
                    type: string
Generation Details
docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli:v7.16.0 generate -i /local/openapi.yaml -g python -o /local/test_client
Steps to reproduce
  1. Save the above OpenAPI YAML as openapi.yaml.
  2. Run the docker command above.
  3. Inspect the generated README (test_client/docs/DefaultApi.md) or example code. The order_by parameter is shown as unquoted in the example assignment.
Related issues/PRs

But none specifically address the unquoted string default in Python README/example.

Suggest a fix

Enum parameter default values should be rendered as quoted strings in generated Python examples and documentation, restoring the previous correct behavior. Please update the template so string defaults are always quoted in the example assignment and README.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions