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

Excessive code duplication in oneOf, anyOf, allOf. #25

Open
MathiasPius opened this issue Nov 29, 2020 · 0 comments
Open

Excessive code duplication in oneOf, anyOf, allOf. #25

MathiasPius opened this issue Nov 29, 2020 · 0 comments

Comments

@MathiasPius
Copy link
Owner

The 3 modifiers share a lot of code, there might be a way to simplify this a bit, since they're all more or less specializations over a validator with multiple possible validations, and only really differ in the number of validations that can fail/pass. The TryFrom<Yaml> implementations for instance are almost identical, only differing in naming.

There's also some duplication in the PropertyType structure which will most likely also just increase over time as more modifiers are added:

if yaml
.lookup("not", "hash", Option::from)
.map(Option::from)
.or_else(optional(None))?
.is_some()
{
return Ok(PropertyType::Not(SchemaNot::try_from(yaml)?));
}
if yaml
.lookup("oneOf", "hash", Option::from)
.map(Option::from)
.or_else(optional(None))?
.is_some()
{
return Ok(PropertyType::OneOf(SchemaOneOf::try_from(yaml)?));
}
if yaml
.lookup("allOf", "hash", Option::from)
.map(Option::from)
.or_else(optional(None))?
.is_some()
{
return Ok(PropertyType::AllOf(SchemaAllOf::try_from(yaml)?));
}
if yaml
.lookup("anyOf", "hash", Option::from)
.map(Option::from)
.or_else(optional(None))?
.is_some()
{
return Ok(PropertyType::AnyOf(SchemaAnyOf::try_from(yaml)?));
}

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

No branches or pull requests

1 participant