Skip to content

OpenAPI Doc - how to show authorized values for an optional query parameter #2661

@legalla

Description

@legalla

Hi all,

Quick question about how to manage optional query paramters :
I would like the users to get capability to use or not an optional query parameter for a certain API.
So OK, that works as expected following FastAPI guide.
But my point now is :
For this optional parameter, I would like to get a set of authorized values.
If the parameter sent by the end user is not in the list, it raises an error.
So :

  • Is there an easy way to show to end user within the Swagger UI which are the allowed values for this parameter, and a description for each of them ?
  • In the meantime, I would like to show them as a list ("select" in HTML), to be sure that user can't make a mistake, and select an authorized value.

I've seen it with solutions using Swagger, so I assume this should be possible, but I didn't find a way to do in documentation (or maybe I missed it...)

Thanks a lot,

Environment

  • OS: Linux - Ubuntu 18.04
  • FastAPI Version [e.g. 0.3.0]:
0.63.0
  • Python version:
Python 3.6.9

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions