Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
81e594d
Dynamic server support
jirikuncar Jun 5, 2020
4985f27
regenerated
jirikuncar Jun 5, 2020
1fd2e65
Apply suggestions from code review
jirikuncar Jun 5, 2020
6caf66f
regenerated
jirikuncar Jun 5, 2020
5eec729
Add ParameterizedServer feature to Python experimental
jirikuncar Jun 5, 2020
df1c324
Fix lookup of server variables
jirikuncar Jun 5, 2020
3920645
Add tests and change default value for servers
jirikuncar Jun 8, 2020
7420edb
Fix server variables
jirikuncar Jun 8, 2020
5422cfd
Return base path when index is None
jirikuncar Jun 8, 2020
280837f
Merge remote-tracking branch 'upstream/master' into python-experiment…
jirikuncar Jun 8, 2020
294d164
Use HOST
jirikuncar Jun 8, 2020
f38fc72
Apply suggestions from code review
jirikuncar Jun 11, 2020
8ec2cb7
Apply suggestions from code review
jirikuncar Jun 11, 2020
655ecd0
Merge remote-tracking branch 'upstream/master' into python-experiment…
jirikuncar Jun 11, 2020
6e97360
regenerated
jirikuncar Jun 11, 2020
0a57b4c
Add specific tests for dynamic servers
jirikuncar Jun 12, 2020
5788068
Merge remote-tracking branch 'upstream/master' into python-experiment…
jirikuncar Jun 12, 2020
1d19097
regenerated
jirikuncar Jun 12, 2020
ff976a4
add docstring
jirikuncar Jun 14, 2020
032533d
Merge remote-tracking branch 'upstream/master' into python-experiment…
jirikuncar Jun 14, 2020
3706f4d
regenerated
jirikuncar Jun 15, 2020
3a1d0ca
Merge remote-tracking branch 'upstream/master' into python-experiment…
jirikuncar Jun 23, 2020
66df647
Fix wrong merge resolution
jirikuncar Jun 23, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Dynamic server support
  • Loading branch information
jirikuncar committed Jun 5, 2020
commit 81e594d319a5e76549e8f4aa45c4200f67b3f646
Original file line number Diff line number Diff line change
Expand Up @@ -155,20 +155,30 @@ conf = {{{packageName}}}.Configuration(

_default = None

def __init__(self, host="{{{basePath}}}",
def __init__(self, host=None,
api_key=None, api_key_prefix=None,
username=None, password=None,
discard_unknown_keys=False,
disabled_client_side_validations="",
{{#hasHttpSignatureMethods}}
signing_info=None,
{{/hasHttpSignatureMethods}}
server_index=None, server_variables=None,
server_operation_index=None, server_operation_variables=None,
):
"""Constructor
"""
self.host = host
self._base_path = "{{{basePath}}}" if host is None else host
"""Default Base url
"""
self.server_index = 0 if server_index is None and host is None else server_index
self.server_operation_index = server_operation_index or {}
"""Default server index
"""
self.server_variables = server_variables or {}
self.server_operation_variables = server_operation_variables or {}
"""Default sever variables
"""
self.temp_folder_path = None
"""Temp file folder for downloading files
"""
Expand Down Expand Up @@ -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.

:return: URL based on host settings
"""
variables = {} if variables is None else variables
servers = self.get_host_settings()
servers = self.get_host_settings() if servers is None else servers

try:
server = servers[index]
Expand All @@ -595,3 +605,17 @@ conf = {{{packageName}}}.Configuration(
url = url.replace("{" + variable_name + "}", used_value)

return url

@property
def host(self):
"""Return generated host."""
if self.server_index is None:
return self._base_path

return self.get_host_from_settings(self.server_index, variables=self.server_variables)

@host.setter
def host(self, value):
"""Fix base path."""
self._base_path = value
self.server_index = None
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class {{classname}}(object):
Default is True.
_host_index (int): specifies the index of the server
that we want to use.
Default is 0.
Default is read from the configuration.
async_req (bool): execute request asynchronously

Returns:
Expand All @@ -131,7 +131,7 @@ class {{classname}}(object):
kwargs['_check_return_type'] = kwargs.get(
'_check_return_type', True
)
kwargs['_host_index'] = kwargs.get('_host_index', 0)
kwargs['_host_index'] = kwargs.get('_host_index', None)
{{#requiredParams}}
kwargs['{{paramName}}'] = \
{{paramName}}
Expand Down Expand Up @@ -160,7 +160,31 @@ class {{classname}}(object):
{{#-first}}
'servers': [
{{/-first}}
'{{{url}}}'{{^-last}},{{/-last}}
{
'url': "{{{url}}}",
'description': "{{{description}}}{{^description}}No description provided{{/description}}",
{{#variables}}
{{#-first}}
'variables': {
{{/-first}}
'{{{name}}}': {
'description': "{{{description}}}{{^description}}No description provided{{/description}}",
'default_value': "{{{defaultValue}}}",
{{#enumValues}}
{{#-first}}
'enum_values': [
{{/-first}}
"{{{.}}}"{{^-last}},{{/-last}}
{{#-last}}
]
{{/-last}}
{{/enumValues}}
}{{^-last}},{{/-last}}
{{#-last}}
}
{{/-last}}
{{/variables}}
},
{{#-last}}
]
{{/-last}}
Expand Down Expand Up @@ -348,7 +372,7 @@ class Endpoint(object):
self.openapi_types = root_map['openapi_types']
extra_types = {
'async_req': (bool,),
'_host_index': (int,),
'_host_index': (none_type, int),
'_preload_content': (bool,),
'_request_timeout': (none_type, int, (int,), [int]),
'_return_http_data_only': (bool,),
Expand Down Expand Up @@ -447,7 +471,15 @@ class Endpoint(object):
def call_with_http_info(self, **kwargs):

try:
_host = self.settings['servers'][kwargs['_host_index']]
index = self.api_client.configuration.server_operation_index.get(
self.settings['operation_id'], self.api_client.configuration.server_index
) if kwargs['_host_index'] is None else kwargs['_host_index']
server_variables = self.api_client.configuration.server_operation_variables.get(
self.settings['operation_id']
)
_host = self.api_client.configuration.get_host_from_settings(
index, variables=server_variables, servers=self.settings['servers']
)
except IndexError:
if self.settings['servers']:
raise ApiValueError(
Expand Down