Skip to content

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

@MathiasPius

Description

@MathiasPius

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)?));
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions