diff --git a/aiohttp_pydantic/oas/view.py b/aiohttp_pydantic/oas/view.py index 7d0473f..5d184f5 100644 --- a/aiohttp_pydantic/oas/view.py +++ b/aiohttp_pydantic/oas/view.py @@ -34,7 +34,8 @@ class _OASResponseBuilder: ).copy() if def_sub_schemas := response_schema.pop("definitions", None): self._oas.components.schemas.update(def_sub_schemas) - return response_schema + self._oas.components.schemas.update({response_schema['title']: response_schema}) + return {'$ref': f'#/components/schemas/{response_schema["title"]}'} return {} def _handle_list(self, obj): diff --git a/tests/test_oas/test_view.py b/tests/test_oas/test_view.py index 5ad6ea5..c30267b 100644 --- a/tests/test_oas/test_view.py +++ b/tests/test_oas/test_view.py @@ -11,7 +11,7 @@ from pydantic.main import BaseModel from aiohttp_pydantic import PydanticView, oas from aiohttp_pydantic.injectors import Group -from aiohttp_pydantic.oas.typing import r200, r201, r204, r404 +from aiohttp_pydantic.oas.typing import r200, r201, r204, r404, r400 from aiohttp_pydantic.oas.view import generate_oas @@ -37,6 +37,11 @@ class Pet(BaseModel): toys: List[Toy] +class Error(BaseModel): + code: int + text: str + + class PetCollectionView(PydanticView): async def get( self, format: str, lang: Lang = Lang.EN, name: Optional[str] = None, *, promo: Optional[UUID] = None @@ -63,7 +68,7 @@ class PetItemView(PydanticView): /, size: Union[int, Literal["x", "l", "s"]], day: Union[int, Literal["now"]] = "now", - ) -> Union[r200[Pet], r404]: + ) -> Union[r200[Pet], r404[Error], r400[Error]]: return web.json_response() async def put(self, id: int, /, pet: Pet):