While developing new api we discovered that dry-validation
suits best for our needs as a validation library.
We’re describing our API with OpenAPI 3 and one of the things we want to develop in future is automatic dry-validation schema generation based on OpenAPI schema.
However there are few things, that dry-validation
and/or dry-logic
seem to lack:
- While Open API oneOf with discriminator could be exposed through when rule, without it there is no such capabilities, except constructions like
(a.and(b.not).and(c.not)).or(b.and(a.not).and(c.not)) ... etc
which doesn’t work properly every time and doesn’t generate meaningful errors. - Open API anyOf could be exposed through or but the errors are not meaningful.
- not doesn’t work properly with schemas.
What I want to suggest is to add the corresponding rules to dry-logic
and dry-validation
and below is what I have at this moment:
- I have a code prepared for anyOf rule for
dry-logic
, I called the rule part and I have 2 questions:
a) Should I return all rules ASTs in case of failure?
b) Is name part good for anyOf rule? - I have a code prepared for oneOf rule for
dry-logic
, I called the rule one and I have 3 questions:
a) Should I return all rules ASTs in case of failure?
b) Is name one good for oneOf rule?
c) Does it make sense to extend this rule to have the second parameter - int or range - the number rules it has to satisfy, so that it would become a general rule nOf? - I haven’t prepared code for neither for oneOf nor of anyOf in
dry-validation
and there are some things I want to discuss:
a) I want errors for oneOf and anyOf to be like " not one of (list of rules)" and " not any of (list of rules)", but I think in case of schemas passed the shouldn’t be expanded to AST, so that the error could be " " not one of Cat, Dog, etc.", but currently they come to message compiler already expanded. What’s better to do here? This could also help with exposing rules likeschema(Cat).not
, which could be added viaadd_rule
and currently returns the errors of the Schema errors when there are errors.
b) What should be the names of the rules? I was thinking about one and any.
Probably generating from Open API will require some more extensions, so in general there is also a question, are you interested in Open API support in dry-validation?