mirror of
https://github.com/fastapi/fastapi.git
synced 2026-05-25 00:37:44 -04:00
Add Open API prefix route - correct docs behind reverse proxy (#26)
Add Open API prefix route - correct docs behind reverse proxy.
This commit is contained in:
committed by
Sebastián Ramírez
parent
890f1f7899
commit
0ea0d0e82a
@@ -0,0 +1,66 @@
|
||||
from starlette.testclient import TestClient
|
||||
|
||||
from sub_applications.tutorial001 import app
|
||||
|
||||
client = TestClient(app)
|
||||
|
||||
openapi_schema_main = {
|
||||
"openapi": "3.0.2",
|
||||
"info": {"title": "Fast API", "version": "0.1.0"},
|
||||
"paths": {
|
||||
"/app": {
|
||||
"get": {
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Successful Response",
|
||||
"content": {"application/json": {"schema": {}}},
|
||||
}
|
||||
},
|
||||
"summary": "Read Main Get",
|
||||
"operationId": "read_main_app_get",
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
openapi_schema_sub = {
|
||||
"openapi": "3.0.2",
|
||||
"info": {"title": "Fast API", "version": "0.1.0"},
|
||||
"paths": {
|
||||
"/subapi/sub": {
|
||||
"get": {
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Successful Response",
|
||||
"content": {"application/json": {"schema": {}}},
|
||||
}
|
||||
},
|
||||
"summary": "Read Sub Get",
|
||||
"operationId": "read_sub_sub_get",
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def test_openapi_schema_main():
|
||||
response = client.get("/openapi.json")
|
||||
assert response.status_code == 200
|
||||
assert response.json() == openapi_schema_main
|
||||
|
||||
|
||||
def test_main():
|
||||
response = client.get("/app")
|
||||
assert response.status_code == 200
|
||||
assert response.json() == {"message": "Hello World from main app"}
|
||||
|
||||
|
||||
def test_openapi_schema_sub():
|
||||
response = client.get("/subapi/openapi.json")
|
||||
assert response.status_code == 200
|
||||
assert response.json() == openapi_schema_sub
|
||||
|
||||
|
||||
def test_sub():
|
||||
response = client.get("/subapi/sub")
|
||||
assert response.status_code == 200
|
||||
assert response.json() == {"message": "Hello World from sub API"}
|
||||
Reference in New Issue
Block a user