Skip to content
Merged
Prev Previous commit
Next Next commit
various fixes
  • Loading branch information
wing328 committed Jan 23, 2019
commit b14fb18dc2b0e18a330d17bc1201a9e0ab10d081
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)):
:return: URL based on host settings
"""

servers = get_host_settings
servers = self.get_host_settings()

# check array index out of bound
if index < 0 or index > len(servers):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the second expression should be >=

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Just pushed out a fix.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI. I'm also reviewing other clients and filing a fix accordingly if the same issue is found.

Expand All @@ -301,14 +301,13 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)):

# go through variable and assign a value
for variable_name in server['variables']:
if name in variables[varible_name]:
if variable_name in variables:
if variables[variable_name] in variables[variable_name]['enum_values']:
url = url.replace("{" + variable_name + "}", variables[variable_name])
else:
raise ValueError("The variable `%s` in the host URL has invalid value %s. Must be %s." % variable_name % variables[variable_name] % variables[variable_name]['enum_values'])
raise ValueError("The variable `%s` in the host URL has invalid value %s. Must be %s." % variable_name % variables[variable_name] % variables[variable_name]['enum_values']) # noqa: E501
else:
# use default value
url = url.replace("{" + variable_name + "}", variables[variable_name]['default_value'])
end
url = url.replace("{" + variable_name + "}", variables[variable_name]['default_value']) # noqa: E501

return url
9 changes: 4 additions & 5 deletions samples/client/petstore/python/petstore_api/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def get_host_from_settings(self, index, variables={}):
:return: URL based on host settings
"""

servers = get_host_settings
servers = self.get_host_settings()

# check array index out of bound
if index < 0 or index > len(servers):
Expand All @@ -289,14 +289,13 @@ def get_host_from_settings(self, index, variables={}):

# go through variable and assign a value
for variable_name in server['variables']:
if name in variables[varible_name]:
if variable_name in variables:
if variables[variable_name] in variables[variable_name]['enum_values']:
url = url.replace("{" + variable_name + "}", variables[variable_name])
else:
raise ValueError("The variable `%s` in the host URL has invalid value %s. Must be %s." % variable_name % variables[variable_name] % variables[variable_name]['enum_values'])
raise ValueError("The variable `%s` in the host URL has invalid value %s. Must be %s." % variable_name % variables[variable_name] % variables[variable_name]['enum_values']) # noqa: E501
else:
# use default value
url = url.replace("{" + variable_name + "}", variables[variable_name]['default_value'])
end
url = url.replace("{" + variable_name + "}", variables[variable_name]['default_value']) # noqa: E501

return url
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ def get_host_from_settings(self, index, variables={}):
:return: URL based on host settings
"""

servers = get_host_settings
servers = self.get_host_settings()

# check array index out of bound
if index < 0 or index > len(servers):
Expand All @@ -322,14 +322,13 @@ def get_host_from_settings(self, index, variables={}):

# go through variable and assign a value
for variable_name in server['variables']:
if name in variables[varible_name]:
if variable_name in variables:
if variables[variable_name] in variables[variable_name]['enum_values']:
url = url.replace("{" + variable_name + "}", variables[variable_name])
else:
raise ValueError("The variable `%s` in the host URL has invalid value %s. Must be %s." % variable_name % variables[variable_name] % variables[variable_name]['enum_values'])
raise ValueError("The variable `%s` in the host URL has invalid value %s. Must be %s." % variable_name % variables[variable_name] % variables[variable_name]['enum_values']) # noqa: E501
else:
# use default value
url = url.replace("{" + variable_name + "}", variables[variable_name]['default_value'])
end
url = url.replace("{" + variable_name + "}", variables[variable_name]['default_value']) # noqa: E501

return url