You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have discovered an interesting problem in NJsonSchema validation.
For some context, I am using NJsonSchema to validate data coming in from a json-forms implementation.
I won't include my exact schema and data here, but I wrote a unit test and managed to replicate this behavior with some test data, please see below:
Using NJsonSchema fails to validate this data, specifically on the oneOf properties. Each time I get an error back from the validator saying that the provided data is not oneOf the available options. Json validation failed: NotOneOf: #/SINGLE_CHOICE
I have run the above example through NewtonSoft's own validator, and it passes validation. However, the nuget package (10.9.0), fails.
I stepped through the validation code in order to try diagnosing this and I noticed that the oneOf options in the Schema object are stored in the ExtensionData property, which is never checked during validation, so every provided option matches, this, then causes a failure in the oneOf validator, since it's not getting any fails (the oneOf validation code returns valid only if there are n-1 errors, where n is the number of oneOf options)
privatevoidValidateOneOf(JTokentoken,JsonSchemaschema,stringpropertyName,stringpropertyPath,List<ValidationError>errors){if(schema._oneOf.Count>0){varpropertyErrors=schema._oneOf.ToDictionary(s =>s, s =>Validate(token,s));<---In my example, validate always has 0 errors
if(propertyErrors.Count(s =>s.Value.Count==0)!=1){errors.Add(newChildSchemaValidationError(ValidationErrorKind.NotOneOf,propertyName,propertyPath,propertyErrors,token,schema));}}}
I believe this is a bug in the nuget package, since I have validated this data online using newtonsoft. JsonSchema.Net also correctly validates this data.
The text was updated successfully, but these errors were encountered:
According to react-json-schema-forms documentation it is also a viable option and produces same result. At least it worked for me and the validation worked. Well, at least it seems so, for now.
I have discovered an interesting problem in NJsonSchema validation.
For some context, I am using NJsonSchema to validate data coming in from a json-forms implementation.
I won't include my exact schema and data here, but I wrote a unit test and managed to replicate this behavior with some test data, please see below:
Schema:
Data:
Using NJsonSchema fails to validate this data, specifically on the oneOf properties. Each time I get an error back from the validator saying that the provided data is not oneOf the available options.
Json validation failed: NotOneOf: #/SINGLE_CHOICE
I have run the above example through NewtonSoft's own validator, and it passes validation. However, the nuget package (10.9.0), fails.
I stepped through the validation code in order to try diagnosing this and I noticed that the oneOf options in the Schema object are stored in the ExtensionData property, which is never checked during validation, so every provided option matches, this, then causes a failure in the oneOf validator, since it's not getting any fails (the oneOf validation code returns valid only if there are n-1 errors, where n is the number of oneOf options)
I believe this is a bug in the nuget package, since I have validated this data online using newtonsoft.
JsonSchema.Net also correctly validates this data.
The text was updated successfully, but these errors were encountered: