flask-restx icon indicating copy to clipboard operation
flask-restx copied to clipboard

How to set the ENUM path parameters for swagger.

Open tracebackerror opened this issue 3 years ago • 1 comments

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.

tracebackerror avatar Apr 06 '22 09:04 tracebackerror

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

MMichels avatar Apr 19 '22 22:04 MMichels