Skip to content

Commit

Permalink
fix: repair how multiple examples are declared in web_api
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
joanise committed Oct 2, 2024
1 parent 3cab240 commit 3fe116b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
40 changes: 19 additions & 21 deletions readalongs/web_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": "<?xml version='1.0' encoding='utf-8'?><read-along version=\"1.0\"><text><p><s>hej verden</s></p></text></read-along>",
"type": "application/readalong+xml",
"text_languages": ["dan", "und"],
"debug": False,
},
},
"xml": {
"summary": "A basic example with xml input",
"value": {
"input": "<?xml version='1.0' encoding='utf-8'?><read-along version=\"1.0\"><text><p><s>hej verden</s></p></text></read-along>",
"type": "application/readalong+xml",
"text_languages": ["dan", "und"],
"debug": False,
},
}
]
},
}
),
):
"""Create an input RAS from the given text (as plain text or XML).
Expand Down Expand Up @@ -331,7 +329,7 @@ class ConvertRequest(BaseModel):
"""\
<?xml version='1.0' encoding='utf-8'?>
<read-along version="%s">
<meta name="generator" content="@readalongs/studio (cli) %s"/>
<meta name="generator" content="@readalongs/studio (cli) %s"/>
<text xml:lang="dan" fallback-langs="und" id="t0">
<body id="t0b0">
<div type="page" id="t0b0d0">
Expand Down
2 changes: 1 addition & 1 deletion requirements.min.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3fe116b

Please sign in to comment.