Add sub-app to generate open api spec

This commit is contained in:
Vincent Maillol
2020-10-23 19:44:44 +02:00
parent 1ffde607c9
commit d6b5fc26f3
24 changed files with 932 additions and 124 deletions

28
demo/view.py Normal file
View File

@@ -0,0 +1,28 @@
from aiohttp_pydantic import PydanticView
from aiohttp import web
from .model import Pet
class PetCollectionView(PydanticView):
async def get(self):
pets = self.request.app["model"].list_pets()
return web.json_response([pet.dict() for pet in pets])
async def post(self, pet: Pet):
self.request.app["model"].add_pet(pet)
return web.json_response(pet.dict())
class PetItemView(PydanticView):
async def get(self, id: int, /):
pet = self.request.app["model"].find_pet(id)
return web.json_response(pet.dict())
async def put(self, id: int, /, pet: Pet):
self.request.app["model"].update_pet(id, pet)
return web.json_response(pet.dict())
async def delete(self, id: int, /):
self.request.app["model"].remove_pet(id)
return web.json_response(id)