mirror of
https://github.com/fastapi/fastapi.git
synced 2026-01-06 04:57:58 -05:00
* ✨ Re-export main features used from Starlette to simplify developer's code * ♻️ Refactor Starlette exports * ♻️ Refactor tutorial examples to use re-exported utils from Starlette * 📝 Add examples for all middlewares * 📝 Add new docs for middlewares * 📝 Add examples for custom responses * 📝 Extend docs for custom responses * 📝 Update docs and add notes explaining re-exports from Starlette everywhere * 🍱 Update screenshot for HTTP status * 🔧 Update MkDocs config with new content * ♻️ Refactor tests to use re-exported utils from Starlette * ✨ Re-export WebSocketDisconnect from Starlette for tests * ✅ Add extra tests for extra re-exported middleware * ✅ Add tests for re-exported responses from Starlette * ✨ Add docs about mounting WSGI apps * ➕ Add Flask as a dependency to test WSGIMiddleware * ✅ Test WSGIMiddleware example
41 lines
1.1 KiB
Python
41 lines
1.1 KiB
Python
import pytest
|
|
from fastapi import FastAPI
|
|
from fastapi.testclient import TestClient
|
|
|
|
app = FastAPI()
|
|
|
|
|
|
@app.get("/a", responses={"hello": {"description": "Not a valid additional response"}})
|
|
async def a():
|
|
pass # pragma: no cover
|
|
|
|
|
|
openapi_schema = {
|
|
"openapi": "3.0.2",
|
|
"info": {"title": "FastAPI", "version": "0.1.0"},
|
|
"paths": {
|
|
"/a": {
|
|
"get": {
|
|
"responses": {
|
|
# this is how one would imagine the openapi schema to be
|
|
# but since the key is not valid, openapi.utils.get_openapi will raise ValueError
|
|
"hello": {"description": "Not a valid additional response"},
|
|
"200": {
|
|
"description": "Successful Response",
|
|
"content": {"application/json": {"schema": {}}},
|
|
},
|
|
},
|
|
"summary": "A",
|
|
"operationId": "a_a_get",
|
|
}
|
|
}
|
|
},
|
|
}
|
|
|
|
client = TestClient(app)
|
|
|
|
|
|
def test_openapi_schema():
|
|
with pytest.raises(ValueError):
|
|
client.get("/openapi.json")
|