You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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=[]
The text was updated successfully, but these errors were encountered:
Nantero1
changed the title
No zeros (0) displayed in the swagger-ui documentation examples
No zeros (0) displayed in the swagger-ui documentation examples, if provided as a number
Apr 23, 2020
version: flask-restplus=0.13.0
A code sample to reproduce the issue:
take this example line
flask-restplus/examples/todomvc.py
Line 14 in 1fe65dd
'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.
flask-restplus/flask_restplus/fields.py
Line 123 in 1fe65dd
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=[]
The text was updated successfully, but these errors were encountered: