Coverage for docs_src/dependencies/tutorial004_an.py: 100%

18 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2025-12-04 08:29 +0000

1from typing import Union 1abcdefg

2 

3from fastapi import Depends, FastAPI 1abcdefg

4from typing_extensions import Annotated 1abcdefg

5 

6app = FastAPI() 1abcdefg

7 

8 

9fake_items_db = [{"item_name": "Foo"}, {"item_name": "Bar"}, {"item_name": "Baz"}] 1abcdefg

10 

11 

12class CommonQueryParams: 1abcdefg

13 def __init__(self, q: Union[str, None] = None, skip: int = 0, limit: int = 100): 1abcdefg

14 self.q = q 1hijklmn

15 self.skip = skip 1hijklmn

16 self.limit = limit 1hijklmn

17 

18 

19@app.get("/items/") 1abcdefg

20async def read_items(commons: Annotated[CommonQueryParams, Depends()]): 1abcdefg

21 response = {} 1hijklmn

22 if commons.q: 1hijklmn

23 response.update({"q": commons.q}) 1hijklmn

24 items = fake_items_db[commons.skip : commons.skip + commons.limit] 1hijklmn

25 response.update({"items": items}) 1hijklmn

26 return response 1hijklmn