flask-restplus
flask-restplus copied to clipboard
No zeros (0) displayed in the swagger-ui documentation examples, if provided as a number
version: flask-restplus=0.13.0
A code sample to reproduce the issue:
take this example line https://github.com/noirbizarre/flask-restplus/blob/1fe65ddae4c04315bd88535e3c2eaff381436270/examples/todomvc.py#L14 and replace it by
'id': fields.Integer(description='The task unique identifier', example=0),
You will notice, that 0 will be ignored in the swagger documentation. Passing the string "0" as a value works fine. Passing any other number not as a string works fine as well. Empty lists ([]) don't work either.
Why this happens
This line evaluates wrongly, if the passed variable "example" is set to 0. https://github.com/noirbizarre/flask-restplus/blob/1fe65ddae4c04315bd88535e3c2eaff381436270/flask_restplus/fields.py#L123
Swagger documentation is not created correctly, if 0 as an integer or 0.0 as a float example values in the api.model definition are provided.
Screenshot from created swagger documentation:
Debugger screenshot, self.example != example
Update: An empty list as an example "[]" for list fields evaluates wrongly too.
Partly working workaround
Always use a string, double quoted zero ("0" ) as an example value. But this breaks type safety. field example value will have the wrong type (string).
This workaround does not work for empty list examples example=[]