[python] Fixes additional_properties_type for models#8802
Merged
spacether merged 38 commits intoOpenAPITools:5.2.xfrom Mar 31, 2021
Merged
[python] Fixes additional_properties_type for models#8802spacether merged 38 commits intoOpenAPITools:5.2.xfrom
spacether merged 38 commits intoOpenAPITools:5.2.xfrom
Conversation
6 tasks
5 tasks
5 tasks
spacether
commented
Mar 19, 2021
Contributor
Author
There was a problem hiding this comment.
requiredVars have been moved out of the init signature because the required vars were probably defined in the composed oneOf/anyOf/allOf schemas and this schema does not know about them. Please read why this was done in this PR's description.
8725fe3 to
106d6f4
Compare
Contributor
Author
|
This PR is blocked by the fact that v2 specs do not correctly set additionalProperties. Update: I merged my PR that sets model.additionalProperties in #9033 |
This was referenced Mar 21, 2021
…test of it, fixes frit and gmfruit tests
… presence of addprosp in schema, updates sample spec composed schemas to remove addprops False form two
…omposed schema init sig
…itional_properties_model_instances
Contributor
Author
|
Re-opening to run CI against the 5.2.X branch |
This was referenced Mar 28, 2021
6 tasks
6 tasks
the-akhil-nair
added a commit
to the-akhil-nair/openapi-generator
that referenced
this pull request
Oct 29, 2021
Problem: The following PR removed the logic for adding the default value for required_vars in composed model's __init__ and _from_openapi_data method due to which it is failing in allOf model class stating missing required positional argument. OpenAPITools#8802 Now it will become users responsibility to add the required_vars as it will become mandatory input in the payload. Since in our application end users may not be knowing these required_vars all the time, the SDK failure create an issue for us. Solution: The proposed solution is to add a configuration variable: setRequiredVars. If it is set to true, then the older logic will be used. The older logic was using to set the default value of required_vars in __init__ and _from_openapi_data as positional arguement.
This was referenced Nov 3, 2021
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.
Before this PR, master branch python client code incorrectly set the additional_properties_type of models to None when it was unset, when it should be set to allow any type. Allowing any type is the default behavior when additionalProperties is unset per openapi versions >= 2.
This PR fixes additionalProperties values for models #8771, correctly setting additional_properties_type.
requiredVars have been moved out of the composed schema init signature
requiredVars have been moved out of the composed schema init signature because the required vars were probably defined in the composed oneOf/anyOf/allOf schemas and this schema does not know about them. Every schema is validated separately. So that means that for a composed schema with no type required or properties or additionalProperties definition inside it:
This change is needed because in our java code, if a oneOf class include required variables, those variable are set in composed schema that includes them. This is incorrect because those variable are not required in the composed schema, they are optional there.
One can see this by looking at the Fruit is a oneOf apple, banana example.
This PR updates it so apple and banana include required parameters. Before making the composed schema init change, those parameters were incorrectly present as positional arguments in Fruit. That's because the java code added those apple and banana requiredVars into Fruit's requiredVars which is incorrect.
v2 Spec Implications
There is a bug in swagger-parser for v2 specs. With that bug, values of True, False, and unset are all seen as null additionalProperties which now becomes AnyType schema.
Previously, the default behavior was to treat all 3 conditions as setting additional_properties_type to None, which did not allow any additional properties to be sent for a given object payload.
In order to have additionalProperties True/False, and unset work correctly, users need to upgrade their specifications to v3.
If users still need the old behavior where additionalProperties was None for additionalProperties=True/False/unset, then they should set disallowAdditionalPropertiesIfNotPresent to True. Doing that will break composition usages oneOf/anyOf/allOf because for that to work, in the composed schema additionalProperties must be any type to allow in properties not defined in the composed schema.properties.
There's another bug where schemas with unset type (AnyType) have their type set to object. This PR works around that bug. If you need to differentiate between AnyType schemas and free form objects (type: object with no properties) then update your spec to v3 or higher.
Breaking Change with Fallback
For v2 specs that use compositiona and were setting disallowAdditionalPropertiesIfNotPresent=True this is a breaking change because composition (allOf schemas) will stop working. If you need composition to work, you must omit setting disallowAdditionalPropertiesIfNotPresent which will then default it to False. Composed schemas will then work. This conforms with the openapi tech spec.
Note: this different PR #8816 will fix it so the variables defined in any schema/model in python only include variables for schema.properties and do not include composed schema properties.
PR checklist
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*.For Windows users, please run the script in Git BASH.
master,5.1.x,6.0.x