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