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

Change how we handle defaults. #171

Merged
merged 1 commit into from
May 5, 2017
Merged

Change how we handle defaults. #171

merged 1 commit into from
May 5, 2017

Conversation

jnb
Copy link
Contributor

@jnb 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.

@jnb jnb requested a review from sjaensch April 19, 2017 23:01
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.006%) to 97.427% when pulling f65fd80 on defaults into 5d9c7ef on master.


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:
Copy link
Contributor Author

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?

Copy link
Contributor

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.


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:
Copy link
Contributor

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)
Copy link
Contributor

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.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.004%) to 97.442% when pulling 1ca6815 on defaults into 1ada116 on master.

@jnb
Copy link
Contributor Author

jnb commented May 4, 2017

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).

@sjaensch sjaensch merged commit 5dbcf79 into master May 5, 2017
@sjaensch
Copy link
Contributor

sjaensch commented May 5, 2017

I've released version 4.7.3 with this change.

@jnb jnb deleted the defaults branch May 5, 2017 21:08
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

Successfully merging this pull request may close these issues.

3 participants