public void PropertyNamedRefThatIsNotAReference(string desc, string data, bool expected) { // property named $ref that is not a reference Console.Error.WriteLine(desc); string schemaData = "{ 'properties':{ '$ref':{ 'type':'string' } } }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft7 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }
public void AllOfWithTheLastEmptySchema(string desc, string data, bool expected) { // allOf with the last empty schema Console.Error.WriteLine(desc); string schemaData = "{ 'allOf':[ { 'type':'number' }, { } ] }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft6 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }
public void ValidationOfRelativeJSONPointers(string desc, string data, bool expected) { // validation of relative JSON pointers Console.Error.WriteLine(desc); string schemaData = "{ 'format':'relative-json-pointer' }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft7 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }
public void AdditionalPropertiesBeingFalseDoesNotAllowOtherProperties(string desc, string data, bool expected) { // additionalProperties being false does not allow other properties Console.Error.WriteLine(desc); string schemaData = "{ 'additionalProperties':false, 'patternProperties':{ '^v':{ } }, 'properties':{ 'bar':{ }, 'foo':{ } } }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft201909 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }
public void AllOfSimpleTypes(string desc, string data, bool expected) { // allOf simple types Console.Error.WriteLine(desc); string schemaData = "{ 'allOf':[ { 'maximum':30 }, { 'minimum':20 } ] }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft6 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }
public void AdditionalPropertiesAllowsASchemaWhichShouldValidate(string desc, string data, bool expected) { // additionalProperties allows a schema which should validate Console.Error.WriteLine(desc); string schemaData = "{ 'additionalProperties':{ 'type':'boolean' }, 'properties':{ 'bar':{ }, 'foo':{ } } }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft201909 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }
public void AdditionalPropertiesAreAllowedByDefault(string desc, string data, bool expected) { // additionalProperties are allowed by default Console.Error.WriteLine(desc); string schemaData = "{ 'properties':{ 'bar':{ }, 'foo':{ } } }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft201909 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }
public void EscapedPointerRef(string desc, string data, bool expected) { // escaped pointer ref Console.Error.WriteLine(desc); string schemaData = "{ 'percent%field':{ 'type':'integer' }, 'properties':{ 'percent':{ '$ref':'#/percent%25field' }, 'slash':{ '$ref':'#/slash~1field' }, 'tilda':{ '$ref':'#/tilda~0field' } }, 'slash/field':{ 'type':'integer' }, 'tilda~field':{ 'type':'integer' } }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft7 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }
public void ContainsKeywordValidation(string desc, string data, bool expected) { // contains keyword validation Console.Error.WriteLine(desc); string schemaData = "{ 'contains':{ 'minimum':5 } }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft201909 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }
public void LocationIndependentIdentifier(string desc, string data, bool expected) { // Location-independent identifier Console.Error.WriteLine(desc); string schemaData = "{ 'allOf':[ { '$ref':'#foo' } ], 'definitions':{ 'A':{ '$id':'#foo', 'type':'integer' } } }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft7 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }
public void LocationIndependentIdentifierWithBaseURIChangeInSubschema(string desc, string data, bool expected) { // Location-independent identifier with base URI change in subschema Console.Error.WriteLine(desc); string schemaData = "{ '$id':'http://localhost:1234/root', 'allOf':[ { '$ref':'http://localhost:1234/nested.json#foo' } ], 'definitions':{ 'A':{ '$id':'nested.json', 'definitions':{ 'B':{ '$id':'#foo', 'type':'integer' } } } } }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft7 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }
public void RefsWithQuote(string desc, string data, bool expected) { // refs with quote Console.Error.WriteLine(desc); string schemaData = @"{ 'definitions':{ 'foo\""bar':{ 'type':'number' } }, 'properties':{ 'foo\""bar':{ '$ref':'#/definitions/foo%22bar' } } }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft7 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }
public void RecursiveReferencesBetweenSchemas(string desc, string data, bool expected) { // Recursive references between schemas Console.Error.WriteLine(desc); string schemaData = "{ '$id':'http://localhost:1234/tree', 'definitions':{ 'node':{ '$id':'http://localhost:1234/node', 'description':'node', 'properties':{ 'subtree':{ '$ref':'tree' }, 'value':{ 'type':'number' } }, 'required':[ 'value' ], 'type':'object' } }, 'description':'tree of nodes', 'properties':{ 'meta':{ 'type':'string' }, 'nodes':{ 'items':{ '$ref':'node' }, 'type':'array' } }, 'required':[ 'meta', 'nodes' ], 'type':'object' }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft7 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }
public void RefToBooleanSchemaFalse(string desc, string data, bool expected) { // $ref to boolean schema false Console.Error.WriteLine(desc); string schemaData = "{ '$ref':'#/definitions/bool', 'definitions':{ 'bool':false } }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft7 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }
public void ASchemaGivenForItems(string desc, string data, bool expected) { // a schema given for items Console.Error.WriteLine(desc); string schemaData = "{ 'items':{ 'type':'integer' } }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft7 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }
public void PropertiesPatternPropertiesAdditionalPropertiesInteraction(string desc, string data, bool expected) { // properties, patternProperties, additionalProperties interaction Console.Error.WriteLine(desc); string schemaData = "{ 'additionalProperties':{ 'type':'integer' }, 'patternProperties':{ 'f.o':{ 'minItems':2 } }, 'properties':{ 'bar':{ 'type':'array' }, 'foo':{ 'maxItems':3, 'type':'array' } } }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft6 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }
public void PropertyNamesWithBooleanSchemaTrue(string desc, string data, bool expected) { // propertyNames with boolean schema true Console.Error.WriteLine(desc); string schemaData = "{ 'propertyNames':true }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft6 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }
public void PropertiesWithEscapedCharacters(string desc, string data, bool expected) { // properties with escaped characters Console.Error.WriteLine(desc); string schemaData = @"{ 'properties':{ 'foo\tbar':{ 'type':'number' }, 'foo\nbar':{ 'type':'number' }, 'foo\fbar':{ 'type':'number' }, 'foo\rbar':{ 'type':'number' }, 'foo\'bar':{ 'type':'number' }, 'foo\\bar':{ 'type':'number' } } }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft6 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }
public void AdditionalPropertiesCanExistByItself(string desc, string data, bool expected) { // additionalProperties can exist by itself Console.Error.WriteLine(desc); string schemaData = "{ 'additionalProperties':{ 'type':'boolean' } }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft201909 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }
public void ObjectPropertiesValidation(string desc, string data, bool expected) { // object properties validation Console.Error.WriteLine(desc); string schemaData = "{ 'properties':{ 'bar':{ 'type':'string' }, 'foo':{ 'type':'integer' } } }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft6 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }
public void AdditionalPropertiesShouldNotLookInApplicators(string desc, string data, bool expected) { // additionalProperties should not look in applicators Console.Error.WriteLine(desc); string schemaData = "{ 'additionalProperties':{ 'type':'boolean' }, 'allOf':[ { 'properties':{ 'foo':{ } } } ] }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft201909 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }
public void MaxLengthValidation(string desc, string data, bool expected) { // maxLength validation Console.Error.WriteLine(desc); string schemaData = "{ 'maxLength':2 }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft4 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }
public void NonASCIIPatternWithAdditionalProperties(string desc, string data, bool expected) { // non-ASCII pattern with additionalProperties Console.Error.WriteLine(desc); string schemaData = "{ 'additionalProperties':false, 'patternProperties':{ '^á':{ } } }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft201909 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }
public void ItemsWithBooleanSchemas(string desc, string data, bool expected) { // items with boolean schemas Console.Error.WriteLine(desc); string schemaData = "{ 'items':[ true, false ] }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft7 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }
public void AllOfWithBooleanSchemasAllFalse(string desc, string data, bool expected) { // allOf with boolean schemas, all false Console.Error.WriteLine(desc); string schemaData = "{ 'allOf':[ false, false ] }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft6 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }
public void ItemsAndSubitems(string desc, string data, bool expected) { // items and subitems Console.Error.WriteLine(desc); string schemaData = "{ 'additionalItems':false, 'definitions':{ 'item':{ 'additionalItems':false, 'items':[ { '$ref':'#/definitions/sub-item' }, { '$ref':'#/definitions/sub-item' } ], 'type':'array' }, 'sub-item':{ 'required':[ 'foo' ], 'type':'object' } }, 'items':[ { '$ref':'#/definitions/item' }, { '$ref':'#/definitions/item' }, { '$ref':'#/definitions/item' } ], 'type':'array' }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft7 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }
public void AllOfTest(string desc, string data, bool expected) { // allOf Console.Error.WriteLine(desc); string schemaData = "{ 'allOf':[ { 'properties':{ 'bar':{ 'type':'integer' } }, 'required':[ 'bar' ] }, { 'properties':{ 'foo':{ 'type':'string' } }, 'required':[ 'foo' ] } ] }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft6 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }
public void NestedItems(string desc, string data, bool expected) { // nested items Console.Error.WriteLine(desc); string schemaData = "{ 'items':{ 'items':{ 'items':{ 'items':{ 'type':'number' }, 'type':'array' }, 'type':'array' }, 'type':'array' }, 'type':'array' }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft7 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }
public void ValidationOfURITemplates(string desc, string data, bool expected) { // validation of URI templates Console.Error.WriteLine(desc); string schemaData = "{ 'format':'uri-template' }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft7 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }
public void RemoteRefContainingRefsItself(string desc, string data, bool expected) { // remote ref, containing refs itself Console.Error.WriteLine(desc); string schemaData = "{ '$ref':'http://json-schema.org/draft-07/schema#' }"; MPJson schemaJson = MPJson.Parse(schemaData); MPJson json = MPJson.Parse(data); MPSchema schema = schemaJson; var validator = new JsonValidator { Strict = true, Version = SchemaVersion.Draft7 }; bool actual = validator.Validate(schema, json); Assert.Equal(expected, actual); }