コード例 #1
0
ファイル: SchemaObject.cs プロジェクト: grarup/SharpE
 private void ValidateElement(Dictionary<int, List<ValidationError>> errors, JsonElement jsonElement, string localPath)
 {
     if (jsonElement.Key == null)
       {
     //AddError(errors, new ValidationError(ValidationErrorState.NotCorrectJson, jsonElement, "Key exspected"));
     return;
       }
       if (jsonElement.Key == "default")
     return;
       if (m_properties != null && m_properties.ContainsKey(jsonElement.Key))
       {
     m_properties[jsonElement.Key].Validate(jsonElement.Value, errors, localPath);
       }
       else
       {
     if (m_patternProperties != null)
     {
       foreach (KeyValuePair<Regex, SchemaObject> patternedProperty in m_patternProperties)
       {
     if (patternedProperty.Key.IsMatch(jsonElement.Key))
     {
       patternedProperty.Value.Validate(jsonElement.Value, errors, localPath);
       return;
     }
       }
     }
     if (m_additionalProperties != null)
     {
       m_additionalProperties.Validate(jsonElement.Value, errors, localPath);
       //else
       //{
       //  bool any = m_additionalProperties.Any(n => n.Validate(jsonElement.Value, null));
       //  if (!any)
       //    AddError(errors, new ValidationError(ValidationErrorState.WrongData, jsonElement, jsonElement.Key + "needs to validate to at least on of these: \r\n" + string.Join(",", m_additionalProperties.Select(n => n.m_jsonObject.ToString()))));
       //}
     }
     else
     {
       AddError(errors, new ValidationError(ValidationErrorState.NotInSchema, jsonElement, jsonElement.Key + " not part of schema"));
       return;
     }
       }
       if (m_allOf != null)
       {
     foreach (SchemaObject schema2Object in m_allOf)
       schema2Object.Validate(jsonElement, errors, localPath);
       }
       if (m_anyOf != null)
       {
     bool anyfound = m_anyOf.Any(schema2Object => schema2Object.Validate(jsonElement, null, localPath));
     if (!anyfound)
       AddError(errors, new ValidationError(ValidationErrorState.WrongData, jsonElement, jsonElement.Key + "needs to validate to at least on of these: \r\n" + m_anyOfArray));
       }
       if (m_oneOf != null)
       {
     int validCount = m_oneOf.Count(schema2Object => schema2Object.Validate(jsonElement, null, localPath));
     if (validCount != 1)
       AddError(errors, new ValidationError(ValidationErrorState.WrongData, jsonElement, jsonElement.Key + "needs to validate exactly on of these: \r\n" + m_oneOfArray));
       }
 }
コード例 #2
0
ファイル: SchemaObject.cs プロジェクト: grarup/SharpE
 public SchemaObject(JsonElement jsonElement, Schema schema)
     : this((JsonObject)jsonElement.Value, schema)
 {
     m_name = jsonElement.Key;
 }