Uh oh!
There was an error while loading. Please reload this page.
[python-experimental] generate model if type != object if enums/validations exist - #2757
Conversation
Uh oh!
There was an error while loading. Please reload this page.
5ad7737 to
8541d2fCompareAll tests pass, ready for final review @wing328 |
6052c0e to
fdfc6ddComparewing328
commented
May 9, 2019
@spacether thanks for the PR. Let me review later today |
aa6ae98 to
49e4124Comparespacether
commented
May 9, 2019
The travis ci failure is because the Cat and Dog models somehow invoked two templates to generate instances of ModelNormal. I will look into this. This is a new problem and was not happening before my 49e4124 rebase. |
spacether
commented
May 10, 2019
@wing328 I fixed the bug. All tests now pass. This PR is ready for review. |
spacether
commented
May 17, 2019
Hi @wing328 |
wing328
commented
May 17, 2019
@spacether Yup, very busy as usual. Thanks again for the PR and keeping it up-to-date. I'll review over the weekend and let you know if I've any question. |
wing328
commented
May 17, 2019
cc @OpenAPITools/generator-core-team since the change covers default codegen as well. |
ackintosh
left a comment
There was a problem hiding this comment.
I'm not familiar with Python but reviewed the changes on DefaultCodegen.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
c3d6bd2 to
c427de6CompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
spacether
commented
May 21, 2019
I still need to tweak the python generator so it handles the below models better: |
If publicclassStringBooleanMapextendsHashMap<String, Boolean> {If
The above explanation applies to AnimalFarm as well: If you have any questions about "alias", please let me know and I'll try my best to explain. |
spacether
commented
May 21, 2019
Thanks for that explanation. I think that StringBooleanMap is being generated correctly in python. |
Using the command line argument to stop generation of alias models requires removing files from 29 generator sample folders. I am working through them. |
wing328
commented
May 23, 2019
@spacether you mean this change will generate additional files and require the switch (generateAliasAsModel) to stop those files from being generated? |
@wing328 nope. So far this is file removal. |
8f12836 to
03bd6edCompare@wing328 all better and ready for reviews. |
7bbd5aa to
f886098CompareThere was a problem hiding this comment.
All of this code was moved and not changed in any way
There was a problem hiding this comment.
@spacether without && !ModelUtils.isGenerateAliasAsModel() it won't work in your case right?
There was a problem hiding this comment.
FYI. I've filed #3951 as && !ModelUtils.isGenerateAliasAsModel() impacts all other generators as well.
f886098 to
762bc06CompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
spacether
commented
Sep 22, 2019
@wing328 all feedback has been addressed. This PR is ready for another review. |
wing328
commented
Sep 24, 2019
Tested the generateAliasAsModel option and worked as expected. |
* master: (207 commits) Add missing enum processing in C++ codegen, already present for Qt5 (#3986) [C++] [Pistache] Removed deprecated warnings (#3985) [C++][Pistache] Simplified model template (#3417) add go oas3 petstore to ensure up-to-date (#3979) replace gitter with slack in the doc (#3977) Fix wrong variable name in LessThan and LessThanOrEqual asserts (#3971) #3957 - Removed hardcoded baseUrl (#3964) Regenerate go openapi3 samples (#3975) [rust] Make it easier to test rust client generator (#3543) Fix issue3635 (#3948) add gradle repository (#3867) [java] allow to use setArtifactVersion() programmatically (#3907) Add a link to DevRelCon SF 2019 (#3961) Add a link to a medium blog post (#3960) update maven-compiler-plugin version (#3956) fix generateAliasAsModels in default generator (#3951) Implement BigDecimal to Decimal in swift4 for currency data as type=string format=number (#3910) Add F# Functions server generator (#3933) [python-experimental] generate model if type != object if enums/validations exist (#2757) [scala] add [date-time] field to codegen unit test (#3939) ...
…ations exist (OpenAPITools#2757) * Python-experimental adds model_utils module, refactors python api class * Fixes python-experimental so the sample sare generated in the petstore_api folder * FIxes python samples tests * Updates python and python-experimental tests * Fixes python-experimental tests * Adds newlines back to python templates + samples * Reverts files with newline tweaks back to master branch versions * Fixes indentation errors in python-experimental api_client * Removes unused files * Python files now generated in correct folders * Adds logging when the user tries to set generateAliasAsModel in python-experimental * Fixes typo
hleb-albau
commented
Jul 27, 2020
wow, why not to make this behavior tweakable? Also, how client users should import enums right now? |
What way do you want it to be tweakable? Then we need to produce the StringWithValidation model to contain the StringWithValidation validation logic. For now, about your enums question, yes using |
hleb-albau
commented
Jul 27, 2020
I just want to mention enums part of PR. Also, right now enum client serialization is broken and produce Also, in some cases you want to have behavior described there #6828 (as does current generator). Can't find property, how to disable enums value check while initializing class during de-serialization on |
Enum serialization issueHi, can you create a new issue describing how enums are not working with a sample spec? Enum checking allowed valuesRight now there is no way to disable checking allowed values per: Why would you want to disable it? What if the server sends an invalid value because your client spec document is out of date? Enum Constants
Would your needs for a static enum be met with Enum classes like: where the value that you send or receive would be |
hleb-albau
commented
Jul 27, 2020
I think my problem do not related to enums directly, but it is lack of static constants description in openapi. Thus, if I have integer field, that have set of 100 predefined values, i want to have:
currently, for java client, i use 2 cycle generation. on first run, I produce from modified enum template file with constants. On a second run I use type-mappings to replaces openapi enum model with primitive values. btw, will try to provide full same of wrong enum serialization tomorrow |
PR checklist
./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.shif 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\.master,. Default:3.4.x,4.0.xmaster.@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?
Description of Updates:
api_name.endpoint_name.validations[('var_name',)] = {'inclusive_maximum': 100}
model_class.validations[('var_name',)] = {'inclusive_maximum': 100}
Note: merging this PR will close this issue: #1991