Feature: Support requiring anyOf a list of keys#534
Feature: Support requiring anyOf a list of keys#534alecthomas merged 3 commits intoalecthomas:masterfrom
Conversation
|
Is this something that you're interested in? From the readme, i'm not sure how amenable you'd be to this. I'm not sure if this qualifies as a new feature, as it's using roughly the existing building blocks to wrap in None of the pieces is new, but it enables a new kind of validation that wasn't possible before. |
|
Ping! I wanted a last check to know if this is something that can happen. It would be a shame. Thanks. |
|
Hey! Yep, sounds reasonable to me, thanks |
|
|
||
| error_message = humanize_error(data, ctx.value) | ||
| assert "expected a dictionary" in error_message | ||
|
|
There was a problem hiding this comment.
This is a lot of tests, most of which seem redundant. Can you reduce the number of tests to the minial set please?
There was a problem hiding this comment.
Done! I reduced que number of tests and eliminated some asserts that were kind of redundant with other ones.
There's still a fair amount of assertions but because I wanted to be thorough in that we weren't regressing in any subtle way.
This adds a new feature to Voluptuous, which is somewhat akin to what json-schema does with the special key `anyOf`.
`Schema({Required(Any('color', 'temperature', 'brightness')): str})` will validate that AT LEAST ONE of these three values is present. That doesn't preclude any individual validation on each of those fields to still apply.
That means that in the above example, if `color` is present, brightness doesn't need to be present. But if brightness is present, all other validations of brightness (like checking that its value is a number between 0 and 100) still apply.
ff95a36 to
bfb6ae6
Compare
|
Thanks for doing that, LGTM! |
|
BTW I know that Voluptuous is used heavily by Home Assistant, so if any developers would be interested in becoming maintainers of this repo, I'd be happy to chat about it. |
|
I know someone in the HA community who might be interested in adopting it, I'll ask. BTW, I fixed the formatting issue, CI should be green now. |
|
The error in the mypy CI scenario seems to steam from pytest itself, not from this project's code. Looks like an incompatibility between certain versions of some dependencies |
|
Thank you sir 🙇 May we get a new release cut? |
|
@alecthomas ping on pushing this new version to pypi 👍 |
|
FWIW, I brought this up with HomeAssistant / Open Home Foundation and they are going to discuss if they want / can become maintainers. |
|
Just to be clear - I'd add them as maintainers to the GitHub project and PyPi project |
|
Noted. I was just the messenger. |
I will prepare a new 0.16.0 release |
This adds a new feature to Voluptuous, which is somewhat akin to what json-schema does with the special key
anyOf.Schema({Required(Any('color', 'temperature', 'brightness')): object})will validate that AT LEAST ONE of these three values is present. That doesn't preclude any individual validation on each of those fields to still apply.That means that in the above example, if
coloris present, brightness doesn't need to be present. But if brightness is present, all other validations of brightness (like checking that its value is a number between 0 and 100) still apply.This is easier to understand with an example:
That schema above is equivalent in json schema to:
Support to converting voluptuous schemas into json schema is also being added to voluptuous-openapi in home-assistant-libs/voluptuous-openapi#60