Coverage for tests / test_additional_responses_default_validationerror.py: 100%
11 statements
« prev ^ index » next coverage.py v7.13.3, created at 2026-02-12 18:15 +0000
« prev ^ index » next coverage.py v7.13.3, created at 2026-02-12 18:15 +0000
1from fastapi import FastAPI 1abcd
2from fastapi.testclient import TestClient 1abcd
3from inline_snapshot import snapshot 1abcd
5app = FastAPI() 1abcd
8@app.get("/a/{id}") 1abcd
9async def a(id): 1abcd
10 pass # pragma: no cover
13client = TestClient(app) 1abcd
16def test_openapi_schema(): 1abcd
17 response = client.get("/openapi.json") 1efg
18 assert response.status_code == 200, response.text 1efg
19 assert response.json() == snapshot( 1efg
20 {
21 "openapi": "3.1.0",
22 "info": {"title": "FastAPI", "version": "0.1.0"},
23 "paths": {
24 "/a/{id}": {
25 "get": {
26 "responses": {
27 "422": {
28 "description": "Validation Error",
29 "content": {
30 "application/json": {
31 "schema": {
32 "$ref": "#/components/schemas/HTTPValidationError"
33 }
34 }
35 },
36 },
37 "200": {
38 "description": "Successful Response",
39 "content": {"application/json": {"schema": {}}},
40 },
41 },
42 "summary": "A",
43 "operationId": "a_a__id__get",
44 "parameters": [
45 {
46 "required": True,
47 "schema": {"title": "Id"},
48 "name": "id",
49 "in": "path",
50 }
51 ],
52 }
53 }
54 },
55 "components": {
56 "schemas": {
57 "ValidationError": {
58 "title": "ValidationError",
59 "required": ["loc", "msg", "type"],
60 "type": "object",
61 "properties": {
62 "loc": {
63 "title": "Location",
64 "type": "array",
65 "items": {
66 "anyOf": [{"type": "string"}, {"type": "integer"}]
67 },
68 },
69 "msg": {"title": "Message", "type": "string"},
70 "type": {"title": "Error Type", "type": "string"},
71 "input": {"title": "Input"},
72 "ctx": {"title": "Context", "type": "object"},
73 },
74 },
75 "HTTPValidationError": {
76 "title": "HTTPValidationError",
77 "type": "object",
78 "properties": {
79 "detail": {
80 "title": "Detail",
81 "type": "array",
82 "items": {
83 "$ref": "#/components/schemas/ValidationError"
84 },
85 }
86 },
87 },
88 }
89 },
90 }
91 )