Repository navigation
Conversation
An OpenAPI 3.1 property with additionalProperties and no type is an AnyType schema, so setTypeProperties never marks it as a map. It still goes through updatePropertyForMap, which makes it a map container (containerType "map") but leaves isMap false. Templates that branch on isMap then skip it: the python client serialized the field but dropped it in from_dict. Fixes OpenAPITools#25054
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 4 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
This branch has not been deployed
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.
Fixes #25054
In an OpenAPI 3.1 spec, a property with
additionalPropertiesand notypeis an AnyType schema, sosetTypePropertiesmarks itisAnyTypeand neverisMap.fromPropertystill sends it throughupdatePropertyForAnyType→updatePropertyForMap, which setsisContainerandcontainerType = "map"but leavesisMapfalse. The pythonfrom_dicttemplate only hasisArrayandisMapbranches insideisContainer, so the field matches neither and is dropped, which is themap=Nonefrom the issue. Serialization works becauseto_dictdoesn't need the flag.updatePropertyForMapnow also setsisMap, the same wayupdateParameterForMapalready does for parameters, so a property that is a map container is always flagged as one. For a schema that already hadtype: objectthis changes nothing, sinceisMapwas already true. The new case is an untyped schema withadditionalProperties(3.1 here, or an untyped composed schema withadditionalProperties), which now carriesisMaptogether withisAnyTypein every generator, not only python.Tests:
DefaultCodegenTest#testUntypedMapPropertyIsMap: untyped, typed and$ref-valued map properties all come out withisMap. The untyped ones fail onmaster.PythonClientCodegenTest#testUntypedMapPropertyIsDeserialized: the generatedfrom_dictreadsmap,typedMapandmodelMap. Fails onmaster.src/test/resources/3_1/issue_25054.yaml.mvn testonmodules/openapi-generatorpasses (5270 tests)../bin/generate-samples.sh ./bin/configs/*.yaml(814 generators) and./bin/utils/export_docs_generators.shproduce no changes, so no sample in the repo depends on the old behaviour.cc Python technical committee: @cbornet @tomplus @krjakbrjak @fa0311
PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
Summary by cubic
updatePropertyForMapnow setsisMap, matching whatupdateParameterForMapalready does, so OpenAPI 3.1 properties with onlyadditionalPropertiesare flagged as maps.This fixes the Python client dropping such fields in
from_dict, since the template only handlesisArrayandisMapinsideisContainer. Typedobjectmap properties are unaffected.Tests:
DefaultCodegenTest#testUntypedMapPropertyIsMap: untyped, typed and$ref-valued map properties all come out withisMapandcontainerType = "map"; the untyped ones fail onmaster.PythonClientCodegenTest#testUntypedMapPropertyIsDeserialized: the generatedfrom_dictreadsmap,typedMapandmodelMapasDict[str, ...]; fails onmaster.src/test/resources/3_1/issue_25054.yaml.Written for commit 7842096. Summary will update on new commits.