in src/Json.Schema.Validation/Validator.cs [424:468]
private void ValidateObjectPropertyValue(
JObject jObject,
string instancePropertyName,
List<string> propertiesPropertySet,
JsonSchema schema)
{
// First ascertain the set of schemas against which this property must validate
// successfully.
var applicableSchemas = new List<JsonSchema>();
// 8.3.3.2 If the property name appears in "properties", add the corresponding schema.
if (propertiesPropertySet.Contains(instancePropertyName))
{
applicableSchemas.Add(Resolve(schema.Properties[instancePropertyName]));
}
// 8.3.3.3 For each regex in "patternProperties", if it matches the property
// name, add the corresponding schema.
if (schema.PatternProperties != null)
{
foreach (string regex in schema.PatternProperties.Keys)
{
if (Regex.IsMatch(instancePropertyName, regex))
{
applicableSchemas.Add(Resolve(schema.PatternProperties[regex]));
}
}
}
// 8.3.3.4 Add the schema defined by "additionalProperties" if and only if
// there are not yet any applicable schemas.
if (!applicableSchemas.Any())
{
if (schema.AdditionalProperties?.Schema != null)
{
applicableSchemas.Add(Resolve(schema.AdditionalProperties.Schema));
}
}
// Now validate the property against all applicable schemas.
foreach (JsonSchema applicableSchema in applicableSchemas)
{
ValidateToken(jObject.Property(instancePropertyName).Value, applicableSchema);
}
}