Coverage for docs_src/dependencies/tutorial004_an_py39.py: 100%
17 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-08-08 03:53 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-08-08 03:53 +0000
1from typing import Annotated, Union 1abcd
3from fastapi import Depends, FastAPI 1abcd
5app = FastAPI() 1abcd
8fake_items_db = [{"item_name": "Foo"}, {"item_name": "Bar"}, {"item_name": "Baz"}] 1abcd
11class CommonQueryParams: 1abcd
12 def __init__(self, q: Union[str, None] = None, skip: int = 0, limit: int = 100): 1abcd
13 self.q = q 1abcd
14 self.skip = skip 1abcd
15 self.limit = limit 1abcd
18@app.get("/items/") 1abcd
19async def read_items(commons: Annotated[CommonQueryParams, Depends()]): 1abcd
20 response = {} 1abcd
21 if commons.q: 1abcd
22 response.update({"q": commons.q}) 1abcd
23 items = fake_items_db[commons.skip : commons.skip + commons.limit] 1abcd
24 response.update({"items": items}) 1abcd
25 return response 1abcd