NJsonSchema icon indicating copy to clipboard operation
NJsonSchema copied to clipboard

Ability to ignore case related errors.

Open holm0563 opened this issue 8 years ago • 2 comments

I would like the ability to ignore errors regarding casing.

The problem is validating json with improper casing ie {Name:"Derek"} vs {name:"Derek"} generates the error "NoAdditionalPropertiesAllowed". This is the same as the error I would get with the validation against {name1:"Derek"}. What are the thoughts of adding a ValidationErrorKind.PropertyMismatch that makes it easier to distinguish this.

I'm happy to hope in and code this, just want to make sure its inline with the goals of this open source project first.

Thanks!

holm0563 avatar Nov 21 '16 17:11 holm0563

I don't think its a good idea to introduce PropertyMismatch because you cannot know whether its PropertyMismatch or NoAdditionalPropertiesAllowed...

My suggestion is to add a second parameter to

    public JsonSchemaValidator(JsonSchema4 schema)
         this(schema, new JsonSchemaValidatorSettings())
    {
    }

    public JsonSchemaValidator(JsonSchema4 schema, JsonSchemaValidatorSettings settings)
    {
        _schema = schema.ActualSchema;
        _settings = settings;
    }

And

public class JsonSchemaValidatorSettings
{
      public bool IgnorePropertyNameCase { get; set; }
}

And handle this in the validator...

RicoSuter avatar Nov 23 '16 19:11 RicoSuter

@RicoSuter I'm interested in knowing if there is any timelines on when this will be added to the main branch. I currently have a requirement where I maintain a json schema in the API and client requests will be validated against this schema. Now, clients json could have different casing from the schema and NoAdditionalPropertiesAllowed doesn't look appropriate. 👍 for this library

2elsa avatar Sep 14 '21 17:09 2elsa