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

17 statements  

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

1from typing import Union 1hijklmn

2 

3from fastapi import Depends, FastAPI 1hijklmn

4 

5app = FastAPI() 1hijklmn

6 

7 

8fake_items_db = [{"item_name": "Foo"}, {"item_name": "Bar"}, {"item_name": "Baz"}] 1hijklmn

9 

10 

11class CommonQueryParams: 1hijklmn

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

13 self.q = q 1abcdefg

14 self.skip = skip 1abcdefg

15 self.limit = limit 1abcdefg

16 

17 

18@app.get("/items/") 1hijklmn

19async def read_items(commons: CommonQueryParams = Depends()): 1hijklmn

20 response = {} 1abcdefg

21 if commons.q: 1abcdefg

22 response.update({"q": commons.q}) 1abcdefg

23 items = fake_items_db[commons.skip : commons.skip + commons.limit] 1abcdefg

24 response.update({"items": items}) 1abcdefg

25 return response 1abcdefg