-
Notifications
You must be signed in to change notification settings - Fork 98
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
Change how we handle defaults. #171
Conversation
jnb
commented
Apr 19, 2017
- Only allow a None to be returned for an optional field if that field is x-nullable.
- Instantiate a missing field to its default value if provided.
bravado_core/unmarshal.py
Outdated
|
||
result = {} | ||
for k, v in iteritems(object_value): | ||
prop_spec = get_spec_for_prop( | ||
swagger_spec, object_spec, object_value, k) | ||
if v is None and k not in required_fields and prop_spec: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be OK to revert this hunk if you think it's not worth the amount of pain it might cause?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the change makes sense conceptually, not sure how many people depend on being allowed to send None
for optional fields though.
bravado_core/unmarshal.py
Outdated
|
||
result = {} | ||
for k, v in iteritems(object_value): | ||
prop_spec = get_spec_for_prop( | ||
swagger_spec, object_spec, object_value, k) | ||
if v is None and k not in required_fields and prop_spec: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the change makes sense conceptually, not sure how many people depend on being allowed to send None
for optional fields though.
# This should fail because the field is not nullable | ||
with pytest.raises(SwaggerMappingError) as excinfo: | ||
unmarshal_object(empty_swagger_spec, content_spec, value) | ||
assert 'is a required value' in str(excinfo.value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a misleading error message, as the field is not required. We just don't allow None
as value anymore.
OK, I scoped this down a bit. Now the behavior is just to add a default field value in case of a missing field. If there's isn't a default field specified, then we add a None (as before). |
I've released version 4.7.3 with this change. |