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

ValidatePatternProperties applied only to additionalProperties #1736

Open
vdwanderley opened this issue Oct 1, 2024 · 0 comments
Open

ValidatePatternProperties applied only to additionalProperties #1736

vdwanderley opened this issue Oct 1, 2024 · 0 comments

Comments

@vdwanderley
Copy link

When we add a patternProperties validation to a json schema, calling schema.Validate() validates only additional properties.
I don't know if this behavior is intended, but I believe this unit test should have passed:

[Fact]
public void When_property_value_doesnt_match_pattern_then_validation_fails()
{
    //// Arrange
    var schema = new JsonSchema();
    schema.Type = JsonObjectType.Object;
    schema.Properties.Add("capitallettersonly", new JsonSchemaProperty() { Type = JsonObjectType.String });
    schema.AllowAdditionalProperties = false;
    schema.PatternProperties.Add("^[a-z]+$", new JsonSchemaProperty() { Pattern = "^[A-Z]+$" });

    var token = new JObject();
    token.Add("capitallettersonly", new JValue("lowercase"));

    //// Act
    var errors = schema.Validate(token);

    //// Assert
    Assert.Single(errors);
    Assert.Equal(ValidationErrorKind.PatternMismatch, errors.First().Kind);
}

If we look at JsonSchemaValidator.cs, we will notice that only additionalProperties are passed as argument.

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