mirror of
https://github.com/fastapi/fastapi.git
synced 2026-05-18 05:15:46 -04:00
✅ Add inline snapshot tests for OpenAPI before changes from Pydantic v2 (#14864)
This commit is contained in:
committed by
GitHub
parent
c48539f4c6
commit
9f4ecf562c
@@ -1,4 +1,5 @@
|
||||
from fastapi.testclient import TestClient
|
||||
from inline_snapshot import snapshot
|
||||
|
||||
from docs_src.extending_openapi.tutorial001_py39 import app
|
||||
|
||||
@@ -14,32 +15,34 @@ def test():
|
||||
def test_openapi_schema():
|
||||
response = client.get("/openapi.json")
|
||||
assert response.status_code == 200, response.text
|
||||
assert response.json() == {
|
||||
"openapi": "3.1.0",
|
||||
"info": {
|
||||
"title": "Custom title",
|
||||
"summary": "This is a very custom OpenAPI schema",
|
||||
"description": "Here's a longer description of the custom **OpenAPI** schema",
|
||||
"version": "2.5.0",
|
||||
"x-logo": {
|
||||
"url": "https://fastapi.tiangolo.com/img/logo-margin/logo-teal.png"
|
||||
assert response.json() == snapshot(
|
||||
{
|
||||
"openapi": "3.1.0",
|
||||
"info": {
|
||||
"title": "Custom title",
|
||||
"summary": "This is a very custom OpenAPI schema",
|
||||
"description": "Here's a longer description of the custom **OpenAPI** schema",
|
||||
"version": "2.5.0",
|
||||
"x-logo": {
|
||||
"url": "https://fastapi.tiangolo.com/img/logo-margin/logo-teal.png"
|
||||
},
|
||||
},
|
||||
},
|
||||
"paths": {
|
||||
"/items/": {
|
||||
"get": {
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Successful Response",
|
||||
"content": {"application/json": {"schema": {}}},
|
||||
}
|
||||
},
|
||||
"summary": "Read Items",
|
||||
"operationId": "read_items_items__get",
|
||||
"paths": {
|
||||
"/items/": {
|
||||
"get": {
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Successful Response",
|
||||
"content": {"application/json": {"schema": {}}},
|
||||
}
|
||||
},
|
||||
"summary": "Read Items",
|
||||
"operationId": "read_items_items__get",
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
)
|
||||
openapi_schema = response.json()
|
||||
# Request again to test the custom cache
|
||||
response = client.get("/openapi.json")
|
||||
|
||||
Reference in New Issue
Block a user