private Push ( |
||
notification | ||
리턴 | void |
public JSchema Apply(JSchema schema, JSchema baseSchema, SchemaComparisionReport report, string propertyName = null) { if (schema == null) { return(baseSchema); } if (baseSchema == null) { return(schema); } if (!string.IsNullOrEmpty(baseSchema.Title)) { schema.Title = baseSchema.Title; } if (!string.IsNullOrEmpty(baseSchema.Format)) { schema.Format = baseSchema.Format; } if (baseSchema.Type != null) { if (!CanConvert(schema.Type, baseSchema.Type)) { report.Push(new TypeChangeFailure(propertyName, schema, baseSchema)); } else { schema.Type = baseSchema.Type; } } if (schema.Properties != null) { foreach (var property in schema.Properties) { if (baseSchema.Properties == null || !baseSchema.Properties.ContainsKey(property.Key)) { report.Push(new MissingPropertyInfo(property.Key, schema, baseSchema)); continue; } var baseProperty = baseSchema.Properties[property.Key]; Apply(property.Value, baseProperty, report, property.Key); } } if (schema.Items != null && baseSchema.Items != null) { for (int i = 0; i < schema.Items.Count && i < baseSchema.Items.Count; i++) { Apply(schema.Items[i], baseSchema.Items[i], report); } } return(schema); }
private static T Use <T>(JSchema schema1, JSchema schema2, string propertyName, Func <JSchema, T> propertyAccess, SchemaComparisionReport report, Func <T, bool> hasValueCheck) { var val1 = propertyAccess(schema1); var val2 = propertyAccess(schema2); var hasValue1 = hasValueCheck(val1); var hasValue2 = hasValueCheck(val2); if (hasValue1 && hasValue2 && !val1.Equals(val2)) { report.Push(new ValueConflict(propertyName, schema1, schema2, SchemaComparisionNotificationLevel.Failure) { Value1 = val1, Value2 = val2 }); return(default(T)); } if (hasValue1) { return(val1); } if (hasValue2) { return(val2); } return(default(T)); }
public JSchema Apply(JSchema schema, JSchema baseSchema, SchemaComparisionReport report, string propertyName = null) { if (schema == null) return baseSchema; if (baseSchema == null) return schema; if (!string.IsNullOrEmpty(baseSchema.Title)) schema.Title = baseSchema.Title; if (!string.IsNullOrEmpty(baseSchema.Format)) schema.Format = baseSchema.Format; if (baseSchema.Type != null) { if (!CanConvert(schema.Type, baseSchema.Type)) report.Push(new TypeChangeFailure(propertyName, schema, baseSchema)); else schema.Type = baseSchema.Type; } if (schema.Properties != null) { foreach (var property in schema.Properties) { if (baseSchema.Properties == null || !baseSchema.Properties.ContainsKey(property.Key)) { report.Push(new MissingPropertyInfo(property.Key, schema, baseSchema)); continue; } var baseProperty = baseSchema.Properties[property.Key]; Apply(property.Value, baseProperty, report, property.Key); } } if (schema.Items != null && baseSchema.Items != null) { for (int i = 0; i < schema.Items.Count && i < baseSchema.Items.Count; i++) { Apply(schema.Items[i], baseSchema.Items[i], report); } } return schema; }