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

correctly fill default parameter if default is boolean False #130

Merged
merged 1 commit into from Jun 26, 2017

Conversation

@nebularazer
Copy link
Contributor

commented Jun 23, 2017

When using False as a default or missing parameter the swagger spec does not include a default.
This PR fixes this.

from apispec.ext.marshmallow import swagger
from marshmallow import fields

field = fields.Boolean(default=False, missing=False)
swagger.field2property(field)
# {'type': 'boolean'}  # actual response
# {'default': False, 'type': 'boolean'}  # expected
@@ -231,7 +231,7 @@ def field2property(field, spec=None, use_refs=True, dump=True, name=None):
ret['format'] = fmt

default = field.default if dump else field.missing
if default:
if not isinstance(default, _Missing):

This comment has been minimized.

Copy link
@sloria

sloria Jun 26, 2017

Member

Since _Missing is private API, you can compare against the missing singleton instead:

from marshmallow import missing

# ...

if default is not missing:

This comment has been minimized.

Copy link
@sloria

sloria Jun 26, 2017

Member

I made this change when I merged.

@sloria sloria merged commit 5806528 into marshmallow-code:dev Jun 26, 2017

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.