[PYTHON] Setting default value for Required variables#10767
Closed
the-akhil-nair wants to merge 3 commits intoOpenAPITools:masterfrom
Closed
[PYTHON] Setting default value for Required variables#10767the-akhil-nair wants to merge 3 commits intoOpenAPITools:masterfrom
the-akhil-nair wants to merge 3 commits intoOpenAPITools:masterfrom
Conversation
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.
Followed the checklist commands: ./mvnw clean package ./bin/generate-samples.sh ./bin/utils/export_docs_generators.sh
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.
Problem:
In the following PR:
#8802
The requiredVars have been moved out of the composed schema
__init__and_from_openapi_datasignature because the required vars were probably defined in the composed oneOf/anyOf/allOf schemas and this schema does not know about them.We understand that each schema should be validated separately and required vars of a schema should not be present in composed schema, but while doing the validation of input payload in allOf schema the schema is expecting those requiredVars
to be set and sent in the input payload itself.
For Example, consider the following snippet from the specification file:
As we can see in the above case Dog class contain the Mammals class as part of allOf composed schema.
Now if we will not specify the className in Dog class as payload and when the payload will be validated against Mammals class and Animal class, Mammal class will throw an error.
Code used to test:
Error Captured:
And because of this now it will become the user's responsibility to add the requiredVars as a mandatory input in the payload.
That is user need to always specify the className in their payload like the following:
Since in our application end users may not be know these requiredVars always, the SDK failure creates 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 used to set the default value of requiredVars in
__init__and_from_openapi_dataas positional arguments.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 bypassing 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.3.0),6.0.x@taxpon (2017/07) @frol (2017/07) @mbohlool (2017/07) @cbornet (2017/09) @kenjones-cisco (2017/11) @tomplus (2018/10) @Jyhess (2019/01) @arun-nalla (2019/11) @spacether (2019/11) @wing328