| | 1 | | using Newtonsoft.Json.Linq; |
| | 2 | | using ValidateLib.ErrorsAndWarnings.Warnings; |
| | 3 | | using ValidateLib.Metadata.Descriptors.Interfaces; |
| | 4 | | using ValidateLib.Metadata.Parsers; |
| | 5 | | using ValidateLib.Metadata.Properties; |
| | 6 | | using ValidateLib.Metadata.PropertyParsers; |
| | 7 | | using ValidateLib.Metadata.PropertyParsers.DescriptorNS; |
| | 8 | | using ValidateLib.Metadata.PropertyParsers.Schema; |
| | 9 | |
|
| | 10 | | namespace ValidateLib.Metadata.Descriptors |
| | 11 | | { |
| | 12 | |
|
| | 13 | | public class SchemaDescriptor : InheritedPropertiesDescriptor, INormalize, Interfaces.IParsable<SchemaDescriptor>, I |
| | 14 | | { |
| 1 | 15 | | public ArrayProperty<ColumnDescriptor>? columns { get; set; } |
| 1 | 16 | | public ArrayProperty<ForeignKeyDescriptor>? foreignKeys { get; set; } |
| 1 | 17 | | public ColumnReferenceProperty? rowTitles { get; set; } |
| 1 | 18 | | public ColumnReferenceProperty? primaryKey { get; set; } |
| 1 | 19 | | new public static string getTypeForTypeProperty() => "Schema"; |
| | 20 | |
|
| | 21 | |
|
| | 22 | |
|
| | 23 | | public static List<Warning> Normalize(JToken token, Context context, JProperty? property = null) |
| | 24 | | { |
| 1 | 25 | | List<Warning> errors = new List<Warning>(); |
| 1 | 26 | | if (token.Type != JTokenType.Object) return errors; |
| 1 | 27 | | foreach (JProperty jProperty in token) |
| | 28 | | { |
| 1 | 29 | | var results = NormalizeProperty(jProperty, context); |
| 1 | 30 | | MergeTwoList(errors, results); |
| | 31 | | } |
| 1 | 32 | | return errors; |
| | 33 | | } |
| | 34 | | new static protected List<Warning> NormalizeProperty(JProperty property, Context context) |
| | 35 | | { |
| 1 | 36 | | List<Warning> errors = new List<Warning>(); |
| 1 | 37 | | if (CommonProperty.IsCommonProperty(property.Name)) CommonProperty.Normalize(property.Value, context, proper |
| 1 | 38 | | switch (property.Name) |
| | 39 | | { |
| | 40 | | case "columns": |
| 1 | 41 | | return ArrayProperty<ColumnDescriptor>.Normalize<ColumnDescriptor>(property.Value, context, property |
| | 42 | | case "foreignKeys": |
| 1 | 43 | | return ArrayProperty<ForeignKeyDescriptor>.Normalize<ForeignKeyDescriptor>(property.Value, context, |
| | 44 | | case "primaryKey": |
| 1 | 45 | | return errors; |
| | 46 | | case "rowTitles": |
| 1 | 47 | | return errors; |
| | 48 | | default: |
| 1 | 49 | | return InheritedPropertiesDescriptor.NormalizeProperty(property, context); |
| | 50 | | } |
| | 51 | | } |
| | 52 | |
|
| | 53 | | new public IPropertyParserBase? GetPropertyParser(JProperty property, List<Warning> warnings) |
| | 54 | | { |
| 1 | 55 | | string propertyName = property.Name; |
| 1 | 56 | | if (CommonProperty.IsCommonProperty(propertyName)) |
| | 57 | | { |
| 0 | 58 | | ((CommonPropertiesDescriptor)this).GetPropertyParser(property, warnings); |
| | 59 | | } |
| | 60 | |
|
| | 61 | | switch (propertyName) |
| | 62 | | { |
| | 63 | | case "columns": |
| 1 | 64 | | return new ColumnsPropertyParser(warnings, this); |
| | 65 | | case "foreignKeys": |
| 1 | 66 | | return new ForeignKeysPropertyParser(warnings, this); |
| | 67 | | case "primaryKey": |
| 1 | 68 | | return new PrimaryKeyPropertyParser(warnings, this); |
| | 69 | | case "rowTitles": |
| 1 | 70 | | return new RowTitlesPropertyParser(warnings, this); |
| | 71 | | case "@type": |
| 1 | 72 | | return new TypePropertyParser<SchemaDescriptor>(warnings, this); |
| | 73 | | default: |
| 1 | 74 | | return ((InheritedPropertiesDescriptor)this).GetPropertyParser(property, warnings); |
| | 75 | | } |
| | 76 | | } |
| | 77 | |
|
| 0 | 78 | | public static IParser<SchemaDescriptor> GetParser(List<Warning> warnings, SchemaDescriptor? descriptor = null) = |
| | 79 | |
|
| | 80 | | public override void PassInheritedProperties() |
| | 81 | | { |
| 1 | 82 | | if (columns is not null) |
| 1 | 83 | | foreach (var column in columns._value!) |
| 1 | 84 | | column.ProcessPassedInheritedProperties(this); |
| 1 | 85 | | } |
| | 86 | |
|
| | 87 | | } |
| | 88 | | } |