Skip to content

Optional Enumerables do not create empty instances when omitted #17

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

bmurphy23
Copy link

This PR address #15. If an Enumerable attribute (map or list-of-maps) is flagged as optional, and that attribute is not in the input, I'd expect the output from Speck.validate/2 to be as minimal as possible. For a top-level attribute, that means a nil value. For anything below the top level, that would mean being entirely omitted from the output. To make this happen, I've made the handling of optional values a higher priority in apply_filters.

One behavioural change not directly related to the above is that a non-optional Enumerable that is omitted will not recursively report :not_found errors. Instead, the map/list-of-maps will itself be marked as :not_found, and the interior elements skipped entirely. The old behaviour is easy enough to re-implement by moving a condition in apply_filters.

@bmurphy23
Copy link
Author

After more exhaustive testing, there's still some behaviour that seems not quite right afoot. I'm tinkering with the code more.

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.

1 participant