Share Python legacy model helpers across generated models - #24730
Open
Abhinav0905 wants to merge 2 commits into
Open
Share Python legacy model helpers across generated models#24730Abhinav0905 wants to merge 2 commits into
Abhinav0905 wants to merge 2 commits into
Conversation
…n-legacy-model-helpers
Abhinav0905
marked this pull request as ready for review
August 19, 2026 17:08
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.
What changed
_legacy_model_helpers.pypackage module for full client generation.anyOf, andoneOfmodels and fromApiClient.Why
compatibleWithPythonLegacycurrently expands the same helper partial into every generated model andApiClient. In kubernetes-client/python#2677, this accounts for roughly 1,538 repeated model copies and about 3.4 MB of duplicated source across the synchronous and asynchronous clients.This fixes the duplication at its source without adding a generator option or changing the generated public API. The small checked-in sample drops from 151,102 to 140,230 Python source bytes (7.20%) and from seven copies of
_get_openapi_to_dictto one.Closes #24729.
Downstream follow-up: kubernetes-client/python#2677
Validation
mvn -ntp -pl modules/openapi-generator -am -Dtest=PythonClientCodegenTest#testLegacyModelToDictRendering+testLegacyModelToDictSupportsModelOnlyGeneration -Dsurefire.failIfNoSpecifiedTests=false test— 2 passedmvn -ntp -pl modules/openapi-generator-cli -am package -DskipTests=true -Dmaven.javadoc.skip=true -Djacoco.skip=true— build succeeded./bin/generate-samples.sh bin/configs/python-legacy-model-dictionaries.yamlpython -m pytest -q testsin the regenerated sample — 11 passedpython -m flake8 legacy_model_dict_client/_legacy_model_helpers.pygit diff --checkPR checklist
Summary by cubic
Shares Python legacy model conversion helpers across generated models to remove duplication without changing the public API. Previously each model and
ApiClientinlined the helpers; now full client generation emits a single private_legacy_model_helpers.pythat models andApiClientimport, with a model-only fallback to inline helpers._legacy_model_helpers.pywhen legacy compatibility is enabled and supporting files are generated or explicitly requested viaCodegenConstants.SUPPORTING_FILES; exposeCodegenConstants.GENERATE_SUPPORTING_FILESto templates.PythonClientCodegentemplates (model_generic,model_oneof,model_anyof,api_client) to import the shared helpers whenuseLegacyModelHelpersModuleis set; add_legacy_model_helpers.mustache.python-legacy-model-dictionariessample; source size drops by ~7%.Written for commit 0c1bee9. Summary will update on new commits.