| 1 |
from fastapi import FastAPI |
| 2 |
from fastapi.testclient import TestClient |
| 3 |
from inline_snapshot import snapshot |
| 4 |
|
| 5 |
app = FastAPI() |
| 6 |
|
| 7 |
|
| 8 |
@app.get("/", openapi_extra={"x-custom-extension": "value"}) |
| 9 |
def route_with_extras(): |
| 10 |
return {} |
| 11 |
|
| 12 |
|
| 13 |
client = TestClient(app) |
| 14 |
|
| 15 |
|
| 16 |
def test_get_route(): |
| 17 |
response = client.get("/") |
| 18 |
assert response.status_code == 200, response.text |
| 19 |
assert response.json() == {} |
| 20 |
|
| 21 |
|
| 22 |
def test_openapi_schema(): |
| 23 |
response = client.get("/openapi.json") |
| 24 |
assert response.status_code == 200, response.text |
| 25 |
assert response.json() == snapshot( |
| 26 |
{ |
| 27 |
"openapi": "3.1.0", |
| 28 |
"info": {"title": "FastAPI", "version": "0.1.0"}, |
| 29 |
"paths": { |
| 30 |
"/": { |
| 31 |
"get": { |
| 32 |
"responses": { |
| 33 |
"200": { |
| 34 |
"description": "Successful Response", |
| 35 |
"content": {"application/json": {"schema": {}}}, |
| 36 |
}, |
| 37 |
}, |
| 38 |
"summary": "Route With Extras", |
| 39 |
"operationId": "route_with_extras__get", |
| 40 |
"x-custom-extension": "value", |
| 41 |
} |
| 42 |
}, |
| 43 |
}, |
| 44 |
} |
| 45 |
) |