diff --git a/aiopenapi3/extra/cookies.py b/aiopenapi3/extra/cookies.py index 5be2df8e..c77f228b 100644 --- a/aiopenapi3/extra/cookies.py +++ b/aiopenapi3/extra/cookies.py @@ -43,6 +43,16 @@ def info(self) -> email.message.Message: def __init__( self, cookiejar: http.cookiejar.CookieJar = None, policy: Literal["jar", "securitySchemes"] = "jar" ) -> None: + """ + + :param cookiejar: a cookiejar.CookieJar instance + :param policy: There are two policies: + + * securitySchemes - only cookies whose name is in the securitySchemes are used. To match authentication \ + requirements credentials are set via OpenAPI.authenticate(name=value) + * jar - all cookies are used, basically like a browser would do. Cookies not mentioned in securitySchemes \ + are set besides OpenAPI.authenticate() to allow using them without adjusting the description document. + """ self.cookiejar: http.cookiejar.CookieJar = cookiejar or http.cookiejar.CookieJar() self.policy: Literal["jar", "securitySchemes"] = policy self.schemes: dict[str, str] = dict() diff --git a/aiopenapi3/v30/glue.py b/aiopenapi3/v30/glue.py index a059805e..468f2d9f 100644 --- a/aiopenapi3/v30/glue.py +++ b/aiopenapi3/v30/glue.py @@ -599,25 +599,31 @@ def _process_request(self, result: httpx.Response) -> tuple["ResponseHeadersType if content_type.lower() == "application/json": data = ctx.received + expected_type = getattr(expected_media.schema_, "_target", expected_media.schema_) + try: data = json.loads(data) except json.decoder.JSONDecodeError: raise ResponseDecodingError(self.operation, data, result) - data = self.api.plugins.message.parsed( + ctx = self.api.plugins.message.parsed( request=self, operationId=self.operation.operationId, + headers=headers, parsed=data, - expected_type=getattr(expected_media.schema_, "_target", expected_media.schema_), + expected_type=expected_type, status_code=status_code, - ).parsed + ) + + data = ctx.parsed + expected_type = ctx.expected_type - if expected_media.schema_ is None: - raise ResponseSchemaError(self.operation, expected_media, expected_media.schema_, result, None) + if expected_type is None: + raise ResponseSchemaError(self.operation, expected_media, expected_type, result, None) try: - data = expected_media.schema_.model(data) + data = expected_type.model(data) except pydantic.ValidationError as e: - raise ResponseSchemaError(self.operation, expected_media, expected_media.schema_, result, e) + raise ResponseSchemaError(self.operation, expected_media, expected_type, result, e) data = self.api.plugins.message.unmarshalled( request=self, operationId=self.operation.operationId, unmarshalled=data diff --git a/docs/source/api.rst b/docs/source/api.rst index 9b562a8e..bb0c42c3 100644 --- a/docs/source/api.rst +++ b/docs/source/api.rst @@ -378,6 +378,11 @@ Cull & Reduce Reduce & Cull are Plugins limiting the models built to the minimum required to match the requirements of the supplied Operations Code below will eleminate all schemas not required to serve the operations identified by the pattern/string match and http methods associated. +.. currentmodule:: aiopenapi3.extra +.. autoclass:: Reduce + :members: __init__ +.. autoclass:: Cull + .. code:: python api = OpenAPI.load_sync( @@ -392,10 +397,11 @@ Code below will eleminate all schemas not required to serve the operations ident ], ) -.. currentmodule:: aiopenapi3.extra -.. autoclass:: Reduce - :members: __init__ -.. autoclass:: Cull + + +.. inheritance-diagram:: aiopenapi3.plugin.Init aiopenapi3.plugin.Document aiopenapi3.extra.Cull aiopenapi3.extra.Reduce + :top-classes: aiopenapi3.plugin.Plugin + :parts: -2 Cookies @@ -403,9 +409,8 @@ Cookies This plugin deals with cookies from responses and adds in requests based on a policy. -There are two policies: -* securitySchemes - only cookies whose name is in the securitySchemes are used. To match authentication requirements credentials are set via OpenAPI.authenticate(name=value) -* jar - all cookies are used, basically like a browser would do. Cookies not mentioned in securitySchemes are set besides OpenAPI.authenticate() to allow using them without adjusting the description document. +.. autoclass:: Cookies + :members: __init__ .. code:: python @@ -416,4 +421,6 @@ There are two policies: ], ) -.. autoclass:: Cookies +.. inheritance-diagram:: aiopenapi3.plugin.Plugin aiopenapi3.plugin.Init aiopenapi3.plugin.Message aiopenapi3.extra.cookies.Cookies + :top-classes: aiopenapi3.plugin.Plugin + :parts: -2 diff --git a/pyproject.toml b/pyproject.toml index f652a133..7319ed85 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -69,7 +69,8 @@ packages = [ "aiopenapi3", "aiopenapi3.v20", "aiopenapi3.v30", - "aiopenapi3.v31" + "aiopenapi3.v31", + "aiopenapi3.extra" ] [tool.setuptools.dynamic]