-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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] Support for per-operation servers #6557
[Python] Support for per-operation servers #6557
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some minor nits, looks good otherwise!
modules/openapi-generator/src/main/resources/python/configuration.mustache
Outdated
Show resolved
Hide resolved
@@ -561,14 +571,14 @@ conf = {{{packageName}}}.Configuration( | |||
{{/servers}} | |||
] | |||
|
|||
def get_host_from_settings(self, index, variables=None): | |||
def get_host_from_settings(self, index, variables=None, servers=None): | |||
"""Gets host URL based on the index and variables | |||
:param index: array index of the host settings | |||
:param variables: hash of variable and the corresponding value |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
modules/openapi-generator/src/main/resources/python/python-experimental/api.mustache
Outdated
Show resolved
Hide resolved
modules/openapi-generator/src/main/resources/python/configuration.mustache
Show resolved
Hide resolved
Co-authored-by: Thomas Hervé <[email protected]>
Can anyone please review this PR? Thank you! @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) |
@jimschubert @spacether how can I get more info on failed Travis job?
|
It looks like this this error is unrelated to your update. I am closing and reopening this PR to kick of the CI tests again. Sometimes we have transient failures in CI and kicking off the jobs again can sometime solve them. |
modules/openapi-generator/src/main/resources/python/configuration.mustache
Outdated
Show resolved
Hide resolved
modules/openapi-generator/src/main/resources/python/configuration.mustache
Show resolved
Hide resolved
modules/openapi-generator/src/main/resources/python/python-experimental/api.mustache
Show resolved
Hide resolved
modules/openapi-generator/src/main/resources/python/configuration.mustache
Outdated
Show resolved
Hide resolved
modules/openapi-generator/src/main/resources/python/configuration.mustache
Show resolved
Hide resolved
try: | ||
api.add_pet({'name': 'pet', 'photo_urls': []}) | ||
except RuntimeError as e: | ||
assert "pass" == str(e) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possible improvement:
This works and a more standard python way to do it is to use
assert_called_with
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we remove support for Python 2, then yes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's still declared in
EXTRAS = {':python_version <= "2.7"': ['future']} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can drop Python 2.x support in the upcoming 5.x release. (not saying you need to do it as part of this PR though)
samples/openapi3/client/petstore/python-experimental/tests/test_api_validation.py
Show resolved
Hide resolved
modules/openapi-generator/src/main/resources/python/configuration.mustache
Outdated
Show resolved
Hide resolved
modules/openapi-generator/src/main/resources/python/python-experimental/api.mustache
Outdated
Show resolved
Hide resolved
modules/openapi-generator/src/main/resources/python/configuration.mustache
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this PR. Over all it looks good. I have one tweak that I need and an optional request to add a test:
- Our configuration class init method is growing to accept too many arguments when fewer arguments would provide an easier to use and understand interface for our users. Your PR proposal increases the number of non-self arguments to 12. There are actually only 8 types of information being loaded in. If we keep storing every parameter at the init level, this function will end up with 20+ inputs. You mentioned that you are trying to keep the usage similar to other languages. Looking at the Go PR, a single servers property is stored in the server configuration struct rather than storing 4 or more new parameters in the struct. That is in the direction of what I am asking here which is to minimize the number of init parameters. Python style tools like pylint try to prevent too many inputs from being used in functions/methods with the error too-many-arguments (R0913). If you look at how we built signing_info we pass in one class instance rather than adding 6 parameters to the init method. Please structure this input so it adds one or two init parameters for this information. That lets us keep this method easy to understand, use, and maintain. How about something like:
server_info=None
# which is a dict like: {index:1, variables={}}
operation_server_info=None:
# which is a dict like {index_by_operation_id: {'get_pet': 0}, variables_by_operation_id: {'get_pet': blah}}
- Nice to have: Please consider adding a sample that exercises the server_operation_index and server_operation_variables inputs. These features are added but have not yet been tested.
@@ -0,0 +1,92 @@ | |||
openapi: 3.0.0 | |||
info: | |||
description: This specification shows how to use dynamic servers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jimschubert I have tried to create a minimal specification on which we can showcase the dynamic server configuration to avoid modifications of default "Petstore" example. This should follow the work for extensions from #6469.
All tests are passing. cc @jimschubert @spacether |
The changes requested point that I brought up has not been addressed. Can you please address it? |
@spacether which one? |
The configuration object could be a mapping with defined schema. I am trying to keep the configuration similar between different clients Go/Java/Python/... I don't see why passing |
The unaddressed point is
Will it help if we discuss this? I can be available over Slack if you want to chat. |
The problem with Python configuration object is that it acts both as Go configuration and context at the same time. We will have the same problem in the future. |
So in my mind that's not the problem. Here's my thought process on what is the problem. New users want to use the configuration instance. They go to read its init method, if they only need to use one feature, they should only have to pass in one argument. If I am a new user and I want to use one feature, and I have to read through 20+ variables to try to understand which specific input I should be passing in when those 20+ variables are inputs for 10 features, then we have made using this class unnecessarily complex and hard to understand. Many users will not be using the configurable servers feature. It is easier for them if they can skip over the 1 or 2 inputs because they are not relevant vs reading these 4 variables and thinking hey do I need this input for feature X. What do you think? |
@spacether it's more complex than you describe. It's not really a single feature. One could break it into:
Based on usage in other libraries:
Nesting is not more user friendly! Moreover we have the same pattern in other languages and I want to make sure that it's consistent. All parameters have reasonable defaults so users do not have to specify them if they are not planning to use these features. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Group consensus is that keeping these as non nested inputs is preferred.
Can you resolve the conflicts then I can merge it in? |
…al/dynamic-servers
Support
servers:
definition.See:
go-experimental
[Go] Add multiple servers support to Go(-experimental) client #4635java
[java] Support templated servers #4998PR checklist
./bin/
(or Windows batch scripts under.\bin\windows
) to update Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit, and these must match the expectations made by your contribution. You only need to run./bin/{LANG}-petstore.sh
,./bin/openapi3/{LANG}-petstore.sh
if updating the code or mustache templates for a language ({LANG}
) (e.g. php, ruby, python, etc).master
,4.3.x
,5.0.x
. Default:master
.