Skip to content

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

Open
@Nantero1

Description

@Nantero1

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions