Coverage for tests / test_additional_responses_bad.py: 100%

11 statements  

« prev     ^ index     » next       coverage.py v7.13.3, created at 2026-02-12 18:15 +0000

1import pytest 1abcd

2from fastapi import FastAPI 1abcd

3from fastapi.testclient import TestClient 1abcd

4 

5app = FastAPI() 1abcd

6 

7 

8@app.get("/a", responses={"hello": {"description": "Not a valid additional response"}}) 1abcd

9async def a(): 1abcd

10 pass # pragma: no cover 

11 

12 

13openapi_schema = { 1abcd

14 "openapi": "3.1.0", 

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

16 "paths": { 

17 "/a": { 

18 "get": { 

19 "responses": { 

20 # this is how one would imagine the openapi schema to be 

21 # but since the key is not valid, openapi.utils.get_openapi will raise ValueError 

22 "hello": {"description": "Not a valid additional response"}, 

23 "200": { 

24 "description": "Successful Response", 

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

26 }, 

27 }, 

28 "summary": "A", 

29 "operationId": "a_a_get", 

30 } 

31 } 

32 }, 

33} 

34 

35client = TestClient(app) 1abcd

36 

37 

38def test_openapi_schema(): 1abcd

39 with pytest.raises(ValueError): 1efg

40 client.get("/openapi.json") 1efg