Skip to content
Discussion options

You must be logged in to vote

So, what you see in /docs or /redoc is going to be based on how those pages choose to render the OpenAPI schema.

As far as I can tell, you get the same OpenAPI spec with or without annotations:

from typing import Annotated

from fastapi import FastAPI, Query

app = FastAPI()


@app.get("/items-1/")
async def read_items_1(q: str | None = Query(None)):
    query_items = {"q": q}
    return query_items


@app.get("/items-2/")
async def read_items_2(q: Annotated[str | None, Query()] = None):
    query_items = {"q": q}
    return query_items


print(app.openapi()['paths']['/items-1/']['get']['parameters'])
#> [{'name': 'q', 'in': 'query', 'required': False, 'schema': {'anyOf': [{'type': 'strin…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@looprewind
Comment options

Answer selected by Kludex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem
2 participants