Skip to content

Request parameters model not exported to docs (and OpenAPI Specification) #11543

Discussion options

You must be logged in to vote

Oh, now I see.. Sorry for the inattention.

I don't think you can easily do what you want in current version of FastAPI since it only accepts simple types (and arrays of simple type parameters) as a Query parameters.

When you use annotation like
params: Annotated[ParamsModel, Depends()]
it is just a shortcut to
params: Annotated[ParamsModel, Depends(ParamsModel)]

FastAPI just looks at the parameters of ParamsModel's init method and treats them as subdependencies. So, it's equivalent of

def get_query_params_dep(foo: str, bar: str) -> ParamsModel:
    return ParamsModel(foo=foo, bar=bar)

@app.get("/")
def test_route(params: Annotated[ParamsModel, Depends(get_query_params_dep)]):
    return …

Replies: 1 comment 13 replies

Comment options

You must be logged in to vote
13 replies
@Philipp3211
Comment options

@YuriiMotov
Comment options

@Philipp3211
Comment options

@YuriiMotov
Comment options

Answer selected by Philipp3211
@Philipp3211
Comment options

@YuriiMotov
Comment options

@Philipp3211
Comment options

@Philipp3211
Comment options

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