Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No zeros (0) displayed in the swagger-ui documentation examples, if provided as a number #794

Open
Nantero1 opened this issue Apr 23, 2020 · 0 comments

Comments

@Nantero1
Copy link

Nantero1 commented Apr 23, 2020

version: flask-restplus=0.13.0
A code sample to reproduce the issue:
take this example line

'id': fields.Integer(readonly=True, description='The task unique identifier'),
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.

self.example = example or self.__schema_example__

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:
image

Debugger screenshot, self.example != example
image

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=[]

@Nantero1 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant