diff --git a/.swagger-codegen-ignore b/.swagger-codegen-ignore index 306f8c7b..70240175 100644 --- a/.swagger-codegen-ignore +++ b/.swagger-codegen-ignore @@ -27,3 +27,4 @@ git_push.sh tox.ini test/*.py +fingerprint_pro_server_api_sdk/models/many_requests_response.py diff --git a/fingerprint_pro_server_api_sdk/api/fingerprint_api.py b/fingerprint_pro_server_api_sdk/api/fingerprint_api.py index 21f79621..f4a69b64 100644 --- a/fingerprint_pro_server_api_sdk/api/fingerprint_api.py +++ b/fingerprint_pro_server_api_sdk/api/fingerprint_api.py @@ -16,9 +16,9 @@ # python 2 and python 3 compatibility library import six -from fingerprint_pro_server_api_sdk import rest from fingerprint_pro_server_api_sdk.api_client import ApiClient +from fingerprint_pro_server_api_sdk.extend_exception import extend_exception from fingerprint_pro_server_api_sdk.rest import ApiException @@ -133,10 +133,10 @@ def get_event_with_http_info(self, request_id, **kwargs): # noqa: E501 except ApiException as e: if e.status == 403: error = self.api_client.deserialize(e, 'ErrorEvent403Response', True) - raise rest.KnownApiException(e, error) + raise extend_exception(e, error) if e.status == 404: error = self.api_client.deserialize(e, 'ErrorEvent404Response', True) - raise rest.KnownApiException(e, error) + raise extend_exception(e, error) raise e def get_visits(self, visitor_id, **kwargs): # noqa: E501 @@ -254,8 +254,8 @@ def get_visits_with_http_info(self, visitor_id, **kwargs): # noqa: E501 except ApiException as e: if e.status == 403: error = self.api_client.deserialize(e, 'ErrorVisits403', True) - raise rest.KnownApiException(e, error) + raise extend_exception(e, error) if e.status == 429: error = self.api_client.deserialize(e, 'ManyRequestsResponse', True) - raise rest.KnownApiException(e, error) + raise extend_exception(e, error) raise e diff --git a/fingerprint_pro_server_api_sdk/extend_exception.py b/fingerprint_pro_server_api_sdk/extend_exception.py new file mode 100644 index 00000000..68b3e9f7 --- /dev/null +++ b/fingerprint_pro_server_api_sdk/extend_exception.py @@ -0,0 +1,7 @@ +from fingerprint_pro_server_api_sdk.rest import KnownApiException + + +def extend_exception(exception, error_object): + if exception.status == 429: + error_object.retry_after = int(exception.headers.get('retry-after')) + return KnownApiException(exception, error_object) diff --git a/fingerprint_pro_server_api_sdk/models/many_requests_response.py b/fingerprint_pro_server_api_sdk/models/many_requests_response.py index bda73fcf..92b50080 100644 --- a/fingerprint_pro_server_api_sdk/models/many_requests_response.py +++ b/fingerprint_pro_server_api_sdk/models/many_requests_response.py @@ -15,6 +15,7 @@ import six + class ManyRequestsResponse(object): """NOTE: This class is auto generated by the swagger code generator program. @@ -28,11 +29,13 @@ class ManyRequestsResponse(object): and the value is json key in definition. """ swagger_types = { - 'error': 'str' + 'error': 'str', + 'retry_after': 'int' } attribute_map = { - 'error': 'error' + 'error': 'error', + 'retry_after': 'retry_after' } def __init__(self, error=None): # noqa: E501 @@ -40,6 +43,7 @@ def __init__(self, error=None): # noqa: E501 self._error = None self.discriminator = None self.error = error + self._retry_after = 0 @property def error(self): @@ -66,6 +70,14 @@ def error(self, error): self._error = error + @property + def retry_after(self): + return self._retry_after + + @retry_after.setter + def retry_after(self, retry_after): + self._retry_after = retry_after + def to_dict(self): """Returns the model properties as a dict""" result = {} diff --git a/generate.sh b/generate.sh index ed5aa430..20f9f95b 100755 --- a/generate.sh +++ b/generate.sh @@ -13,5 +13,8 @@ done # jar was downloaded from here https://repo1.maven.org/maven2/io/swagger/codegen/v3/swagger-codegen-cli/3.0.34/ rm docs/* -rm -rf fingerprint_pro_server_api_sdk/* +cd fingerprint_pro_server_api_sdk/models +shopt -s extglob +rm !("many_requests_response.py") +cd ../.. java -jar ./bin/swagger-codegen-cli.jar generate -t ./template -l python -i ./res/fingerprint-server-api.yaml -o ./ -c config.json -DpackageVersion=$VERSION diff --git a/template/api.mustache b/template/api.mustache index 2e6927ad..abb3ffa0 100644 --- a/template/api.mustache +++ b/template/api.mustache @@ -8,9 +8,9 @@ import re # noqa: F401 # python 2 and python 3 compatibility library import six -from {{packageName}} import rest from {{packageName}}.api_client import ApiClient +from {{packageName}}.extend_exception import extend_exception from {{packageName}}.rest import ApiException @@ -213,7 +213,7 @@ class {{classname}}(object): {{^isDefault}} if e.status == {{code}}: error = self.api_client.deserialize(e, '{{dataType}}', True) - raise rest.KnownApiException(e, error) + raise extend_exception(e, error) {{/isDefault}} {{/responses}} raise e diff --git a/test/test_fingerprint_api.py b/test/test_fingerprint_api.py index 366bac5e..902bee63 100644 --- a/test/test_fingerprint_api.py +++ b/test/test_fingerprint_api.py @@ -147,8 +147,8 @@ def test_get_visits_error_429(self): with self.assertRaises(KnownApiException) as context: self.api.get_visits(mock_file) self.assertEqual(context.exception.status, 429) - self.assertIsNotNone(context.exception.headers.get('retry-after')) self.assertIsInstance(context.exception.structured_error, ManyRequestsResponse) + self.assertEqual(context.exception.structured_error.retry_after, 4) def test_get_event_correct_data(self): """Test checks correct code run result in default scenario"""