[Python] improved class reflection in deserialization and better model construction with mandatory attributes #5512
Conversation
easz
added
some commits
Apr 28, 2017
wing328
added the
Client: Python
label
May 1, 2017
wing328
added this to the
v2.2.3
milestone
May 1, 2017
|
Thanks for the PR. cc @frol @scottrw93 @taxpon @baartosz @easz btw, have you checked out the 2.3.0 branch in which Python API client has a lot of enhancements (with breaking changes)? |
wing328
added the
Enhancement: General
label
May 1, 2017
|
$ cd swagger-codegen/ $ git checkout remotes/swagger-api/2.3.0 // the last commit c01cb9e of this PR is not part of changes // delete 'test' for new code $ ./bin/python-petstore.sh $ cd samples/client/petstore/python/ Ran 100 tests in 11.110s OK (SKIP=1) |
Yes, that's the expected behaviour because we do not want to overwrite the test files as the users might have manually added a few test cases in the test files. |
|
that means actually I did assume 'test' folder is automated generated tests |
Yes, that's the current behaviour.
That's one way to do it. We plan to leverage .swagger-codegen-ignore to control which files not be overwritten during code generation. |
|
@easz if I understand correctly, these changes are backward-compatible with the existing auto-genreated Python API using the latest master. I'll merge this PR into master on coming Wed if no one has any further feedback. |
| @@ -23,6 +23,7 @@ packages/ | ||
| .pub | ||
| .packages | ||
| .vagrant/ | ||
| +.vscode/ |
frol
May 8, 2017
Contributor
I think, this should be added locally on your own machine to the global git ignore file: https://davidwalsh.name/global-gitignore
|
yes. the change (e.g. required attributes need to be defined when calling model constructor) is backward-compatible with the existing auto-genreated Python API. but some test cases has been changed to compatible with the change. and any existing client code by any user may break if they did not assign required attributes in the constructor. |
|
The change looks great to me. P.S. I have noticed that there are some places where 2 spaces are used for indentation while 4 spaces indentation is recommended. Is this worth to update in the scope of this PR? |
I don't think so. I'll create another issue to track the code format of Python API client similar to what we've done for the PHP API client (refactored): #5277 |
wing328
added the
Issue: Bug
label
May 16, 2017
@easz It's definitely the correct behaviour and I would imagine some applications using the upgraded Python API client will throw exception. May I know what the exception message looks like? If it's clear, I think it's fine for this enhancement to go into the current master. |
|
a ValueError, if a required attribute is not given in a model constructor Exception is thrown from files generated by model.mustache
before the change, the test cases under test/ just construct every possible model with null content |
|
@easz the error message looks good to me. We might revise it later to make it consistent with the error message shown by other API clients. |
easz commentedApr 29, 2017
•
edited
PR checklist
./bin/to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.shand./bin/security/{LANG}-petstore.shif updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates)2.3.0branch for breaking (non-backward compatible) changes.Description of the PR
(details of the change, additional tests that have been done, reference to the issue for tracking, etc)
try to improve python client generation.
See
#5375
#5421