diff --git a/aiohttp_pydantic/__init__.py b/aiohttp_pydantic/__init__.py index 91b5e3c..e4c4db7 100644 --- a/aiohttp_pydantic/__init__.py +++ b/aiohttp_pydantic/__init__.py @@ -1,5 +1,5 @@ from .view import PydanticView -__version__ = "1.7.1" +__version__ = "1.7.2" __all__ = ("PydanticView", "__version__") diff --git a/aiohttp_pydantic/oas/view.py b/aiohttp_pydantic/oas/view.py index b2e22af..4aab93f 100644 --- a/aiohttp_pydantic/oas/view.py +++ b/aiohttp_pydantic/oas/view.py @@ -44,7 +44,9 @@ class _OASResponseBuilder: def _handle_pydantic_base_model(self, obj): if is_pydantic_base_model(obj): - response_schema = obj.schema(ref_template="#/components/schemas/{model}") + response_schema = obj.schema( + ref_template="#/components/schemas/{model}" + ).copy() if def_sub_schemas := response_schema.pop("definitions", None): self._oas.components.schemas.update(def_sub_schemas) return response_schema @@ -104,8 +106,10 @@ def _add_http_method_to_oas( status_code_descriptions = {} if body_args: - body_schema = next(iter(body_args.values())).schema( - ref_template="#/components/schemas/{model}" + body_schema = ( + next(iter(body_args.values())) + .schema(ref_template="#/components/schemas/{model}") + .copy() ) if def_sub_schemas := body_schema.pop("definitions", None): oas.components.schemas.update(def_sub_schemas) diff --git a/tests/test_oas/test_view.py b/tests/test_oas/test_view.py index f8b233e..acdbe83 100644 --- a/tests/test_oas/test_view.py +++ b/tests/test_oas/test_view.py @@ -77,10 +77,19 @@ async def generated_oas(aiohttp_client, loop) -> web.Application: oas.setup(app) client = await aiohttp_client(app) - response = await client.get("/oas/spec") - assert response.status == 200 - assert response.content_type == "application/json" - return await response.json() + response_1 = await client.get("/oas/spec") + assert response_1.content_type == "application/json" + assert response_1.status == 200 + content_1 = await response_1.json() + + # Reload the page to ensure that content is always the same + # note: pydantic can return a cached dict, if a view updates + # the dict the output will be incoherent + response_2 = await client.get("/oas/spec") + content_2 = await response_2.json() + assert content_1 == content_2 + + return content_2 async def test_generated_oas_should_have_components_schemas(generated_oas):