Coverage for docs_src/path_operation_advanced_configuration/tutorial006.py: 100%

9 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-08-08 03:53 +0000

1from fastapi import FastAPI, Request 1abcde

2 

3app = FastAPI() 1abcde

4 

5 

6def magic_data_reader(raw_body: bytes): 1abcde

7 return { 1abcde

8 "size": len(raw_body), 

9 "content": { 

10 "name": "Maaaagic", 

11 "price": 42, 

12 "description": "Just kiddin', no magic here. ✨", 

13 }, 

14 } 

15 

16 

17@app.post( 1abcde

18 "/items/", 

19 openapi_extra={ 

20 "requestBody": { 

21 "content": { 

22 "application/json": { 

23 "schema": { 

24 "required": ["name", "price"], 

25 "type": "object", 

26 "properties": { 

27 "name": {"type": "string"}, 

28 "price": {"type": "number"}, 

29 "description": {"type": "string"}, 

30 }, 

31 } 

32 } 

33 }, 

34 "required": True, 

35 }, 

36 }, 

37) 

38async def create_item(request: Request): 1abcde

39 raw_body = await request.body() 1abcde

40 data = magic_data_reader(raw_body) 1abcde

41 return data 1abcde