Skip to content

'allowEmptyValue' for query #11488

Answered by YuriiMotov
rockyoung asked this question in Questions
Discussion options

You must be logged in to vote

I managed to make it work only with openapi customization.

from fastapi import FastAPI, Query
from fastapi.openapi.utils import get_openapi

app = FastAPI()

@app.get("/foo")
async def foo(qk: str = Query(default='any')) -> str:
    return qk


def custom_openapi():
    if app.openapi_schema:
        return app.openapi_schema
    openapi_schema = get_openapi(
        title=app.title,
        version=app.version,
        summary=app.summary,
        description=app.description,
        routes=app.routes,
    )
    for param in openapi_schema["paths"]["/foo"]["get"]["parameters"]:
        if param["name"] == "qk":
            param["schema"].pop("default")
            param.pop("required")
…

Replies: 1 comment 1 reply

Comment options

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

Answer selected by rockyoung
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