-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[python-experimental] automatically use values for enums of length1 #3118
[python-experimental] automatically use values for enums of length1 #3118
Conversation
...penapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml
Outdated
Show resolved
Hide resolved
I am not sure why this test
EDIT: the below commit |
@spacether Is it correct to say |
This will be a breaking change (without fallback). To get it merged into master, likely we will need an option. |
Correct we will be hard coding in that required params come before optional ones and that flag will no longer be used. |
What does we will need an option mean? |
I think only optional parameters can have default values. Usually, we don't include the default value in the client as it should be done in the server side instead. |
What makes you think that this will be a breaking change? I do not think that this is a breaking change for the below reasons.
But we are loading in values in using a default value, won't that be a breaking change? No it will not, because we are only loafing in values for REQUIRED parameters which have an enum of length one defined.
The new code will:
|
Let me try to describe this more clearly. Assigning default values in our function signatures is a way of passing in data. This is conceptually different than the swagger concept of a defualt value. There are 4 swagger spec parameter use cases here:
|
Is that some sort of default header that must be included in every requests? |
Is that some sort of default header that must be included in every request? |
Thanks for the detailed explanation. |
My use case is headers with set values. But it could be any field where the value must be held constant and the filed is required. |
Thanks for bringing up this particular use case about the required parameter (enum) with exactly 1 allowable value. Technically it's allowed to have such parameter. But I want to step back to understand why there's such a need to include the parameter (required, enum with 1 possible value) in the request. If the parameter (input from the client's request) is expected to be included in every single request, what value (or additional information) does it provide to the backend as the backend expects the same thing in every request? I want to make the client as simple, easy-to-use as possible and having a required parameter with one possible value does not seem to be a good idea to me. |
This is a use case which routinely exists when headers are required. |
Per a discussion with @wing328 we should merge this into a new generator, python-client-experimental Note to self: see a similar-to spec file here: https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/test/resources/2_0/swift/petstore-with-fake-endpoints-models-for-testing.yaml |
0b5f299
to
73c7dfa
Compare
…ments, linting fixes to pass python tests
639b6b3
to
2600010
Compare
2600010
to
9926969
Compare
@wing328 this PR has been changed so it now updates the python-experimental generator |
Gentle reminder that this PR needs a review. What's the status on it? |
@spacether thanks for the PR, which has been included in the 4.1.0 release: https://twitter.com/oas_generator/status/1160000504455319553 |
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.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\
. If contributing template-only or documentation-only changes which will change sample output, be sure to build the project first.master
,4.1.x
,5.0.x
. Default:master
.@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 updates the function signatures for models and endpoints
FROM
(req_arg1=None, req_arg2_with_default=None, optional_arg1=None):
TO:
(req_arg1, req_arg2_with_default=default_value, optional_arg1=None):
So required arguments without defaults are now positional
Required arguments with defaults are now named arguments which use the default value
This is helpful because:
Note about invoking functions with positional args:
In python2 and python3 if a function has a signature:
So if people are invoking these functions with keyword arguments, they will continue working.
Positional vs Keyword Arguments:
If we do not like making these required arguments positional, and we want to keep them as keyword arguments, I can:
This PR also adds a windows tool at bin/windows/python-experimental-petstore.bat to generate the python-experimental sample client on windows machines.
If merged, this PR will close out #1812