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