[python] Fix unquoted string enum defaults causing NameError in python-fastapi#24268
Merged
Conversation
…rameters String enums with a default were emitted as bare identifiers (e.g. Query(uploadTime, ...)), causing NameError at import. Quote defaults like plain strings and unwrap before enum member matching so model property defaults still resolve correctly. Fixes OpenAPITools#23774
Update FakeApi.md examples to show quoted enum default values in Python client docs, matching the corrected toDefaultValue() output. Co-authored-by: Cursor <cursoragent@cursor.com>
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 8 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Use a test subclass to call protected helpers so forbiddenapis passes. Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
AbstractPythonCodegen.toDefaultValue()sopython-fastapiemits valid Python inQuery()/Header()/Cookie()(fixes [BUG][PYTHON-fastapi] string enum defaults are not quoted in generated fastapi code #23774).getEnumDefaultValue()so model enum member resolution still works.parameter-test-spec.yaml.Test plan
./mvnw clean package -DskipTests./bin/generate-samples.sh ./bin/configs/python*.yaml./bin/utils/export_docs_generators.shmvn -pl modules/openapi-generator -am -Dtest=PythonFastapiCodegenTest#testStringEnumQueryParameterDefaultsAreQuoted,PythonClientCodegenTest#testStringEnumDefaultIsQuoted,PythonClientCodegenTest#testStringEnumDefaultFalseIsQuoted -Dsurefire.failIfNoSpecifiedTests=false testcc Python technical committee: @cbornet @tomplus @krjakbrjak @fa0311
cc Python FastAPI: @krjakbrjak
Fixes #23774
Summary by cubic
Quote string enum defaults in
python-fastapiparameters to prevent NameError from bare identifiers. Ensure enum default resolution works for single- and triple-quoted cases. Fixes #23774.AbstractPythonCodegen.toDefaultValue()soQuery()/Header()/Cookie()receive string literals.getEnumDefaultValue()viaunwrapPythonStringLiteral, reversing apostrophe/backslash escapes for triple-quoted values so enum matching works.formatPythonStringLiteral(), update tests (including a subclass-based test to avoid reflection), and regenerate Python client docs to show quoted defaults inFakeApi.md.Written for commit 6a90bae. Summary will update on new commits.