From 76b1be47c04067d621edeff599031c2186622491 Mon Sep 17 00:00:00 2001 From: OM HASE <138221910+OM-HASE@users.noreply.github.com> Date: Wed, 4 Dec 2024 22:44:45 +0530 Subject: [PATCH 1/3] Update exceptions.mustache --- .../main/resources/python/exceptions.mustache | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/modules/openapi-generator/src/main/resources/python/exceptions.mustache b/modules/openapi-generator/src/main/resources/python/exceptions.mustache index a690ceb926cb..fb2ebae0eefa 100644 --- a/modules/openapi-generator/src/main/resources/python/exceptions.mustache +++ b/modules/openapi-generator/src/main/resources/python/exceptions.mustache @@ -140,6 +140,13 @@ class ApiException(OpenApiException): if http_resp.status == 404: raise NotFoundException(http_resp=http_resp, body=body, data=data) + # Added new conditions for 409 and 422 + if http_resp.status == 409: + raise ConflictException(http_resp=http_resp, body=body, data=data) + + if http_resp.status == 422: + raise UnprocessableEntityException(http_resp=http_resp, body=body, data=data) + if 500 <= http_resp.status <= 599: raise ServiceException(http_resp=http_resp, body=body, data=data) raise ApiException(http_resp=http_resp, body=body, data=data) @@ -178,6 +185,16 @@ class ServiceException(ApiException): pass +class ConflictException(ApiException): + """Exception for HTTP 409 Conflict.""" + pass + + +class UnprocessableEntityException(ApiException): + """Exception for HTTP 422 Unprocessable Entity.""" + pass + + def render_path(path_to_item): """Returns a string representation of a path""" result = "" From 65f1084036a3132d61b36ec4e6f9c33aabe241d0 Mon Sep 17 00:00:00 2001 From: OM HASE <138221910+OM-HASE@users.noreply.github.com> Date: Thu, 5 Dec 2024 15:44:30 +0530 Subject: [PATCH 2/3] Fix(Python): Add custom exceptions for HTTP status codes 409 (Conflict) and 422 (Unprocessable Entity) #20244 --- .../petstore/python/petstore_api/exceptions.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/samples/openapi3/client/petstore/python/petstore_api/exceptions.py b/samples/openapi3/client/petstore/python/petstore_api/exceptions.py index 0cb484becbdb..81d2d590712f 100755 --- a/samples/openapi3/client/petstore/python/petstore_api/exceptions.py +++ b/samples/openapi3/client/petstore/python/petstore_api/exceptions.py @@ -150,6 +150,14 @@ def from_response( if http_resp.status == 404: raise NotFoundException(http_resp=http_resp, body=body, data=data) + # Added new exception classes for 409 and 422 + + if http_resp.status == 409: + raise ConflictException(http_resp=http_resp, body=body, data=data) + + if http_resp.status == 422: + raise UnprocessableEntityException(http_resp=http_resp, body=body, data=data) + if 500 <= http_resp.status <= 599: raise ServiceException(http_resp=http_resp, body=body, data=data) raise ApiException(http_resp=http_resp, body=body, data=data) @@ -183,6 +191,14 @@ class UnauthorizedException(ApiException): class ForbiddenException(ApiException): pass +class ConflictException(ApiException): + """Exception raised for HTTP 409 Conflict errors.""" + pass + + +class UnprocessableEntityException(ApiException): + """Exception raised for HTTP 422 Unprocessable Entity errors.""" + pass class ServiceException(ApiException): pass From 65edf7da776d12500fc3d229785f4a0ee1d49c7c Mon Sep 17 00:00:00 2001 From: William Cheng Date: Mon, 30 Dec 2024 11:29:10 +0800 Subject: [PATCH 3/3] update samples --- .../openapi_client/exceptions.py | 17 +++++++++++++++++ .../python/openapi_client/exceptions.py | 17 +++++++++++++++++ .../python-aiohttp/petstore_api/exceptions.py | 17 +++++++++++++++++ .../petstore/python/petstore_api/exceptions.py | 17 +++++++++-------- 4 files changed, 60 insertions(+), 8 deletions(-) diff --git a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/exceptions.py b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/exceptions.py index bd5561d241ed..f38ce4018036 100644 --- a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/exceptions.py +++ b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/exceptions.py @@ -151,6 +151,13 @@ def from_response( if http_resp.status == 404: raise NotFoundException(http_resp=http_resp, body=body, data=data) + # Added new conditions for 409 and 422 + if http_resp.status == 409: + raise ConflictException(http_resp=http_resp, body=body, data=data) + + if http_resp.status == 422: + raise UnprocessableEntityException(http_resp=http_resp, body=body, data=data) + if 500 <= http_resp.status <= 599: raise ServiceException(http_resp=http_resp, body=body, data=data) raise ApiException(http_resp=http_resp, body=body, data=data) @@ -189,6 +196,16 @@ class ServiceException(ApiException): pass +class ConflictException(ApiException): + """Exception for HTTP 409 Conflict.""" + pass + + +class UnprocessableEntityException(ApiException): + """Exception for HTTP 422 Unprocessable Entity.""" + pass + + def render_path(path_to_item): """Returns a string representation of a path""" result = "" diff --git a/samples/client/echo_api/python/openapi_client/exceptions.py b/samples/client/echo_api/python/openapi_client/exceptions.py index bd5561d241ed..f38ce4018036 100644 --- a/samples/client/echo_api/python/openapi_client/exceptions.py +++ b/samples/client/echo_api/python/openapi_client/exceptions.py @@ -151,6 +151,13 @@ def from_response( if http_resp.status == 404: raise NotFoundException(http_resp=http_resp, body=body, data=data) + # Added new conditions for 409 and 422 + if http_resp.status == 409: + raise ConflictException(http_resp=http_resp, body=body, data=data) + + if http_resp.status == 422: + raise UnprocessableEntityException(http_resp=http_resp, body=body, data=data) + if 500 <= http_resp.status <= 599: raise ServiceException(http_resp=http_resp, body=body, data=data) raise ApiException(http_resp=http_resp, body=body, data=data) @@ -189,6 +196,16 @@ class ServiceException(ApiException): pass +class ConflictException(ApiException): + """Exception for HTTP 409 Conflict.""" + pass + + +class UnprocessableEntityException(ApiException): + """Exception for HTTP 422 Unprocessable Entity.""" + pass + + def render_path(path_to_item): """Returns a string representation of a path""" result = "" diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/exceptions.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/exceptions.py index 0cb484becbdb..195e150623d2 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/exceptions.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/exceptions.py @@ -150,6 +150,13 @@ def from_response( if http_resp.status == 404: raise NotFoundException(http_resp=http_resp, body=body, data=data) + # Added new conditions for 409 and 422 + if http_resp.status == 409: + raise ConflictException(http_resp=http_resp, body=body, data=data) + + if http_resp.status == 422: + raise UnprocessableEntityException(http_resp=http_resp, body=body, data=data) + if 500 <= http_resp.status <= 599: raise ServiceException(http_resp=http_resp, body=body, data=data) raise ApiException(http_resp=http_resp, body=body, data=data) @@ -188,6 +195,16 @@ class ServiceException(ApiException): pass +class ConflictException(ApiException): + """Exception for HTTP 409 Conflict.""" + pass + + +class UnprocessableEntityException(ApiException): + """Exception for HTTP 422 Unprocessable Entity.""" + pass + + def render_path(path_to_item): """Returns a string representation of a path""" result = "" diff --git a/samples/openapi3/client/petstore/python/petstore_api/exceptions.py b/samples/openapi3/client/petstore/python/petstore_api/exceptions.py index 81d2d590712f..195e150623d2 100755 --- a/samples/openapi3/client/petstore/python/petstore_api/exceptions.py +++ b/samples/openapi3/client/petstore/python/petstore_api/exceptions.py @@ -150,12 +150,11 @@ def from_response( if http_resp.status == 404: raise NotFoundException(http_resp=http_resp, body=body, data=data) - # Added new exception classes for 409 and 422 - + # Added new conditions for 409 and 422 if http_resp.status == 409: raise ConflictException(http_resp=http_resp, body=body, data=data) - if http_resp.status == 422: + if http_resp.status == 422: raise UnprocessableEntityException(http_resp=http_resp, body=body, data=data) if 500 <= http_resp.status <= 599: @@ -191,16 +190,18 @@ class UnauthorizedException(ApiException): class ForbiddenException(ApiException): pass -class ConflictException(ApiException): - """Exception raised for HTTP 409 Conflict errors.""" + +class ServiceException(ApiException): pass -class UnprocessableEntityException(ApiException): - """Exception raised for HTTP 422 Unprocessable Entity errors.""" +class ConflictException(ApiException): + """Exception for HTTP 409 Conflict.""" pass -class ServiceException(ApiException): + +class UnprocessableEntityException(ApiException): + """Exception for HTTP 422 Unprocessable Entity.""" pass