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:
Kabir Khan
2019-02-14 10:57:49 -08:00
committed by Sebastián Ramírez
parent 890f1f7899
commit 0ea0d0e82a
9 changed files with 191 additions and 4 deletions

View File

View File

@@ -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"}