Repository navigation
[python] Use generated model names in examples and plain dicts for free-form objects - #25153
Merged
wing328 merged 2 commits intoOct 7, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 16 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
…es become dicts too
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.
Follow-up to #25106 (the example path oddity noted there).
Problem.
toExampleValueRecursiveinAbstractPythonCodegenbuilds the example for an object schema as<package>.models.<underscore(title)>.<title>(. The title is whatever the inline model resolver or the parent property set, so for inline models the path points at a module and class that do not exist, e.g.openapi_client.models._a_post_request_object1_prop2._a_post_request_object1_prop2(for files that are actuallya_post_request_object1_prop2.py/APostRequestObject1Prop2. For a free-formtype: objectproperty there is no model at all, which is why the petstore samples containa_property = petstore_api.models.a_property.aProperty()intest_parent.pyandtest_parent_with_optional_dict.py(the generated field isDict[str, Any]).Fix.
toModelFilename(title)andtoModelName(title), the same functions that name the generated files, so the example matches the real module and class.ModelUtils.isFreeFormObjectis true, the example is a plain{ }instead of a non-existent model.Tests.
PythonClientCodegenTest.testExampleValueForInlineObjectscovering both cases; fails on master, passes with the change.PythonClientCodegenTest: 99 tests pass.aPropertyexample would have stayed in the samples forever. For the seven petstore Python variants I removed onlytest/test_parent.pyandtest/test_parent_with_optional_dict.py(both generator output, no manual edits) and regenerated each config one at a time. The diff is exactly the onea_propertyline per file; the regenerated files compile withpy_compileand the example parses withast.parse.PR checklist
Summary by cubic
Fixes Python example generation so inline models reference real generated modules and classes, and free-form objects use plain dicts instead of non-existent models.
toModelFilenameandtoModelNameso inline model references match generated files.{ }for free-form objects, checking before the title so untitled ones like bare array items also become dicts instead ofNone.Written for commit fe24834. Summary will update on new commits.