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)
Nobody has claimed this yet.
- 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
- Save the above OpenAPI YAML as openapi.yaml.
- Run the docker command above.
- Inspect the generated README (test_client/docs/DefaultApi.md) or example code. The
order_byparameter is shown as unquoted in the example assignment.
Related issues/PRs
- https://github.com/OpenAPITools/openapi-generator/issues/21849 (HTML-encoded defaults)
- https://github.com/OpenAPITools/openapi-generator/issues/20397 (enum value naming error)
- https://github.com/OpenAPITools/openapi-generator/issues/18843 (default not applied for $ref enum)
- https://github.com/OpenAPITools/openapi-generator/issues/16071 (enum usage bug)
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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