mirror of https://github.com/tiangolo/fastapi.git
asyncapi link bug
This commit is contained in:
parent
6e8edfe626
commit
4115a165aa
|
|
@ -1222,7 +1222,7 @@ class FastAPI(Starlette):
|
|||
if oauth2_redirect_url:
|
||||
oauth2_redirect_url = root_path + oauth2_redirect_url
|
||||
asyncapi_docs_url = None
|
||||
if self.asyncapi_docs_url:
|
||||
if self.asyncapi_url and self.asyncapi_docs_url:
|
||||
asyncapi_docs_url = root_path + self.asyncapi_docs_url
|
||||
return get_swagger_ui_html(
|
||||
openapi_url=openapi_url,
|
||||
|
|
|
|||
|
|
@ -402,3 +402,28 @@ def test_get_asyncapi_direct():
|
|||
assert schema["asyncapi"] == "2.6.0"
|
||||
assert schema["info"]["title"] == "Test API"
|
||||
assert "/ws" in schema["channels"]
|
||||
|
||||
|
||||
def test_asyncapi_url_none_no_link_in_swagger():
|
||||
"""Test that Swagger UI doesn't show AsyncAPI link when asyncapi_url is None."""
|
||||
app = FastAPI(
|
||||
title="Test API",
|
||||
version="1.0.0",
|
||||
asyncapi_url=None, # Explicitly disabled
|
||||
# asyncapi_docs_url defaults to "/asyncapi-docs"
|
||||
)
|
||||
|
||||
@app.websocket("/ws")
|
||||
async def websocket_endpoint(websocket: WebSocket):
|
||||
await websocket.accept()
|
||||
await websocket.close()
|
||||
|
||||
client = TestClient(app)
|
||||
# Swagger UI should not show AsyncAPI link when asyncapi_url is None
|
||||
response = client.get("/docs")
|
||||
assert response.status_code == 200, response.text
|
||||
assert "/asyncapi-docs" not in response.text
|
||||
|
||||
# AsyncAPI endpoint should not exist
|
||||
response = client.get("/asyncapi-docs")
|
||||
assert response.status_code == 404
|
||||
|
|
|
|||
Loading…
Reference in New Issue