python-restx / flask-restx

Fork of Flask-RESTPlus: Fully featured framework for fast, easy and documented API development with Flask
https://flask-restx.readthedocs.io/en/latest/
Other
2.16k stars 335 forks source link

How to set the ENUM path parameters for swagger. #429

Open tracebackerror opened 2 years ago

tracebackerror commented 2 years ago

Ask a question Currently im trying to set and path parameters and want to enum in swagger api docs. But i'm not able to find any clear documentation for that.

MMichels commented 2 years ago

Hello!

To define a "list of possible values" for a parameter in swagger you must inform the list of values ​​through the "choices" attribute in the model, for example:

post_model = reqparse.RequestParser()
post_model.add_argument(
    'format',
    required=True,
    location="args",
    type=str,
    choices=["csv", "xlsx", "txt"],
    help="Formato do arquivo."
)

In the swagger it will be displayed:

image