OpenAPITools / OpenAPITools/openapi-generator

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

Open
#22,239 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

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.

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 the OpenAPI YAML example and run the provided Docker generation command, then inspect test_client/docs/DefaultApi.md for the unquoted enum default. Trace the Python generator template responsible for the parameter example and compare its output with the v5.4 example. Done means the generated Python assignment and accompanying default description quote string enum values.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, python
Domain
documentation, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.