server: fix openapi generation with duplicate route for audio/mp3

This commit is contained in:
2023-12-18 15:42:42 +01:00
parent b3648529e3
commit 7bb44ac88b
5 changed files with 102 additions and 4 deletions

View File

@@ -100,7 +100,10 @@ def use_route_names_as_operation_ids(app: FastAPI) -> None:
version = None
if route.path.startswith("/v"):
version = route.path.split("/")[1]
opid = f"{version}_{route.name}"
if route.operation_id is not None:
opid = f"{version}_{route.operation_id}"
else:
opid = f"{version}_{route.name}"
else:
opid = route.name
@@ -110,7 +113,7 @@ def use_route_names_as_operation_ids(app: FastAPI) -> None:
"Please rename the route or the view function."
)
route.operation_id = opid
ensure_uniq_operation_ids.add(route.name)
ensure_uniq_operation_ids.add(opid)
use_route_names_as_operation_ids(app)

View File

@@ -18,8 +18,14 @@ from ._range_requests_response import range_requests_response
router = APIRouter()
@router.get("/transcripts/{transcript_id}/audio/mp3")
@router.head("/transcripts/{transcript_id}/audio/mp3")
@router.get(
"/transcripts/{transcript_id}/audio/mp3",
operation_id="transcript_get_audio_mp3",
)
@router.head(
"/transcripts/{transcript_id}/audio/mp3",
operation_id="transcript_head_audio_mp3",
)
async def transcript_get_audio_mp3(
request: Request,
transcript_id: str,