From 3fe116b3caa9fcfb217f666c97620b88953d041b Mon Sep 17 00:00:00 2001 From: Eric Joanis Date: Wed, 2 Oct 2024 07:16:16 -0400 Subject: [PATCH] fix: repair how multiple examples are declared in web_api Before fastapi 0.99, we could declare multiple examples with examples=[{"key1": ..., "key2": ...}] Now, examples no longer accept keys or metadata, just a list of plain examples. Since fastapi 0.103, using openapi_examples instead restores the old key and metadata functionality. See https://fastapi.tiangolo.com/tutorial/schema-extra-example/#using-the-openapi_examples-parameter for details. --- readalongs/web_api.py | 40 +++++++++++++++++++--------------------- requirements.min.txt | 2 +- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/readalongs/web_api.py b/readalongs/web_api.py index 6aef947e..30ff8126 100644 --- a/readalongs/web_api.py +++ b/readalongs/web_api.py @@ -145,28 +145,26 @@ async def langs() -> List[SupportedLanguage]: @v1.post("/assemble", response_model=AssembleResponse) async def assemble( request: AssembleRequest = Body( - examples=[ - { - "text": { - "summary": "A basic example with plain text input", - "value": { - "input": "hej verden", - "type": "text/plain", - "text_languages": ["dan", "und"], - "debug": False, - }, + openapi_examples={ + "text": { + "summary": "A basic example with plain text input", + "value": { + "input": "hej verden", + "type": "text/plain", + "text_languages": ["dan", "und"], + "debug": False, }, - "xml": { - "summary": "A basic example with xml input", - "value": { - "input": "

hej verden

", - "type": "application/readalong+xml", - "text_languages": ["dan", "und"], - "debug": False, - }, + }, + "xml": { + "summary": "A basic example with xml input", + "value": { + "input": "

hej verden

", + "type": "application/readalong+xml", + "text_languages": ["dan", "und"], + "debug": False, }, - } - ] + }, + } ), ): """Create an input RAS from the given text (as plain text or XML). @@ -331,7 +329,7 @@ class ConvertRequest(BaseModel): """\ - +
diff --git a/requirements.min.txt b/requirements.min.txt index f720ba43..e4970217 100644 --- a/requirements.min.txt +++ b/requirements.min.txt @@ -2,7 +2,7 @@ chevron==0.14.0 click>=8.0.4 coloredlogs>=10.0 -fastapi>=0.100.0 +fastapi>=0.103.0 g2p>=1.1.20230822, <3 lxml==4.9.4 numpy>=1.20.2