Schema Validation errors on Ver. 3.0.14
whiletrue0222 opened this issue · comments
Lee Youngkwon commented
As per the title, Schema Validation errors seem to be occurring on version 3.0.14. JToken.IsValid seems to be fine on ver. 3.0.13. The error that pops up on 3.0.14 is as follows:
JSON does not match schema from 'then'. Path 'Goo', line 3, position 10.
I have attached some sample code below.
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Schema;
JSchemaPreloadedResolver resolver = new JSchemaPreloadedResolver();
resolver.Add(new Uri("CommonEnum.schema.json", UriKind.RelativeOrAbsolute), @"
{
'$schema': 'http://json-schema.org/draft/2019-09/schema#',
'type': 'object',
'definitions': {
'FooType': {
'type': 'string',
'enum': [ 'A', 'B' ]
}
}
}
");
resolver.Add(new Uri("DataCommon.schema.json", UriKind.RelativeOrAbsolute),
@"
{
'$schema': 'http://json-schema.org/draft/2019-09/schema#',
'type': 'object',
'properties': {
'Goo': {
'type': 'object',
'properties': {
'm1': { 'type': 'integer', 'minimum': 0 },
'm2': { 'type': 'integer', 'minimum': 1 }
}
}
}
}
");
var schemaText = @"
{
'$schema': 'http://json-schema.org/draft/2019-09/schema#',
'type': 'object',
'properties': {
'Type': {
'$ref': 'CommonEnum.schema.json#/definitions/FooType'
},
'Goo': {
'$ref': 'DataCommon.schema.json#/properties/Goo',
'if': {
'properties': {
'Type': { 'enum': ['A'] }
}
},
'then': { 'required': [ 'Goo' ] }
}
}
}";
var settings = new JSchemaReaderSettings
{
Resolver = resolver,
};
JSchema schema = JSchema.Parse(schemaText, settings);
var schemaString = schema.ToString();
var jsonText = @"{
'Type': 'A',
'Goo': {
'm1': 30,
'm2': 100
}
}";
var json = JToken.Parse(jsonText);
var isValid = json.IsValid(schema, out IList<string> errorMessages);
Console.WriteLine(isValid);
foreach (var errorMessage in errorMessages)
{
Console.WriteLine(errorMessage);
}
Assistance is much appreciated.
Thank you.