Coverage for tests/test_additional_responses_default_validationerror.py: 100%

10 statements  

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

1from fastapi import FastAPI 1abcde

2from fastapi.testclient import TestClient 1abcde

3 

4app = FastAPI() 1abcde

5 

6 

7@app.get("/a/{id}") 1abcde

8async def a(id): 1abcde

9 pass # pragma: no cover 

10 

11 

12client = TestClient(app) 1abcde

13 

14 

15def test_openapi_schema(): 1abcde

16 response = client.get("/openapi.json") 1abcde

17 assert response.status_code == 200, response.text 1abcde

18 assert response.json() == { 1abcde

19 "openapi": "3.1.0", 

20 "info": {"title": "FastAPI", "version": "0.1.0"}, 

21 "paths": { 

22 "/a/{id}": { 

23 "get": { 

24 "responses": { 

25 "422": { 

26 "description": "Validation Error", 

27 "content": { 

28 "application/json": { 

29 "schema": { 

30 "$ref": "#/components/schemas/HTTPValidationError" 

31 } 

32 } 

33 }, 

34 }, 

35 "200": { 

36 "description": "Successful Response", 

37 "content": {"application/json": {"schema": {}}}, 

38 }, 

39 }, 

40 "summary": "A", 

41 "operationId": "a_a__id__get", 

42 "parameters": [ 

43 { 

44 "required": True, 

45 "schema": {"title": "Id"}, 

46 "name": "id", 

47 "in": "path", 

48 } 

49 ], 

50 } 

51 } 

52 }, 

53 "components": { 

54 "schemas": { 

55 "ValidationError": { 

56 "title": "ValidationError", 

57 "required": ["loc", "msg", "type"], 

58 "type": "object", 

59 "properties": { 

60 "loc": { 

61 "title": "Location", 

62 "type": "array", 

63 "items": { 

64 "anyOf": [{"type": "string"}, {"type": "integer"}] 

65 }, 

66 }, 

67 "msg": {"title": "Message", "type": "string"}, 

68 "type": {"title": "Error Type", "type": "string"}, 

69 }, 

70 }, 

71 "HTTPValidationError": { 

72 "title": "HTTPValidationError", 

73 "type": "object", 

74 "properties": { 

75 "detail": { 

76 "title": "Detail", 

77 "type": "array", 

78 "items": {"$ref": "#/components/schemas/ValidationError"}, 

79 } 

80 }, 

81 }, 

82 } 

83 }, 

84 }