Skip to content

Inconsistency in openapi.json Generation for Annotated[list[str] | None] in FastAPI #10654

Discussion options

You must be logged in to vote

From here #10836 (reply in thread)

Use:

from typing import Annotated
from fastapi import FastAPI, Query
from pydantic.json_schema import SkipJsonSchema

app = FastAPI()

@app.get('/items')
async def read_items(q: Annotated[list[str] | SkipJsonSchema[None], Query()] = None):
    query_items = {"q": q}
    return query_items

Replies: 5 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@Rich5
Comment options

@pygaiwan
Comment options

@JavierSanchezCastro
Comment options

Answer selected by Kludex
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem
5 participants