Merged
requested to merge github/fork/spacether/issue_1991_folds_non_object_models_into_models into master
Created by: spacether
PR checklist
-
Read the contribution guidelines. -
Ran the shell script under ./bin/
to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.sh
,./bin/openapi3/{LANG}-petstore.sh
if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in.\bin\windows\
. -
Filed the PR against the correct branch: master
,. Default:3.4.x
,4.0.x
master
. -
Copied the technical committee to review the pull request if your PR is targeting a particular programming language.
@taxpon (2017/07) @frol (2017/07) @mbohlool (2017/07) @cbornet (2017/09) @kenjones-cisco (2017/11) @tomplus (2018/10) @Jyhess (2019/01)
Description of the PR
This PR makes it so models whose type != "object" are generated in python if the model has validations or enums. Those models are then used for serialization and deserialization when communicating with an API.
Why is this necessary?
- If we do not add this generation of non-object model types, when deserializing a response where type="str" with regex validations and enums invalid server values can be be ingested and used by the client. Our current python client does not store any of the validation or enum info. It just stores the response as type string. From now on, it will store the response type as the model class name. That model class will store and the validations and enums and use them when serializing + deserializing.
- The purpose of this diff is to work towards completion of the "additionalProperties support, Option2" feature in the python client https://github.com/OpenAPITools/openapi-generator/pull/2049
- This PR lays the ground work for a future PR where types in python can be described with classes rather than a string description of a class.
Description of Updates:
- models whose type != object with validations and/or enums are now generated in the python client
- an Endpoint class has been created in the api_client to store api parameters inside each endpoint in a way that can be accessed by a user.
- the interface to access enums and validations has been made the same for models and endpoints
- enums can be accessed by
- api_name.endpoint_name.allowable_values[('var_name',)] = {'ENUM_VAL': 'enum_val'}
- model_class.allowable_values[('var_name',)] = {'ENUM_VAL': 'enum_val'}
- validations can be accessed by
-
api_name.endpoint_name.validations[('var_name',)] = {'inclusive_maximum': 100}
-
model_class.validations[('var_name',)] = {'inclusive_maximum': 100}
-
- enums can be accessed by
- there are now 2 types of python models:
- ModeSimple based models which are ones where type != "object" which have validations and/or enums
- ModelNormal based models which are ones where type == "object"
Note: merging this PR will close this issue: https://github.com/OpenAPITools/openapi-generator/issues/1991