| | | 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.AtomicProperties; |
| | | 6 | | using ValidateLib.Metadata.PropertyParsers; |
| | | 7 | | using ValidateLib.Metadata.PropertyParsers.DataType; |
| | | 8 | | |
| | | 9 | | namespace ValidateLib.Metadata.Descriptors |
| | | 10 | | { |
| | | 11 | | public class DatatypeDescriptor : Descriptor, INormalize, Interfaces.IParsable<DatatypeDescriptor> |
| | | 12 | | { |
| | 1 | 13 | | public AtomicPropertyString? _base { get; set; } = new AtomicPropertyString("string") { IsDefault = true }; |
| | 1 | 14 | | public FormatDescriptor? format { get; set; } |
| | 1 | 15 | | public AtomicPropertyInteger? length { get; set; } |
| | 1 | 16 | | public AtomicPropertyInteger? minLength { get; set; } |
| | 1 | 17 | | public AtomicPropertyInteger? maxLength { get; set; } |
| | 1 | 18 | | public AtomicPropertyString? minimum { get; set; } |
| | 1 | 19 | | public AtomicPropertyString? maximum { get; set; } |
| | 1 | 20 | | public AtomicPropertyString? minInclusive { get; set; } |
| | 1 | 21 | | public AtomicPropertyString? maxInclusive { get; set; } |
| | 1 | 22 | | public AtomicPropertyString? minExclusive { get; set; } |
| | 1 | 23 | | public AtomicPropertyString? maxExclusive { get; set; } |
| | | 24 | | |
| | 1 | 25 | | public bool IsBuiltIn = true; |
| | | 26 | | public static List<Warning> Normalize(JToken token, Context context, JProperty? property = null) |
| | | 27 | | { |
| | 1 | 28 | | List<Warning> errors = new List<Warning>(); |
| | 1 | 29 | | if (token.Type == JTokenType.String) |
| | 1 | 30 | | token.Replace(new JObject(new JProperty("base", token.ToString()))); |
| | 1 | 31 | | else if (token.Type == JTokenType.Object) |
| | 1 | 32 | | foreach (JProperty jproperty in token) errors.AddRange(NormalizeProperty(jproperty, context)); |
| | 1 | 33 | | return errors; |
| | | 34 | | |
| | | 35 | | |
| | | 36 | | } |
| | | 37 | | new public static List<Warning> NormalizeProperty(JProperty property, Context context) |
| | | 38 | | { |
| | 1 | 39 | | List<Warning> errors = new List<Warning>(); |
| | 1 | 40 | | switch (property.Name) |
| | | 41 | | { |
| | | 42 | | case "base": |
| | | 43 | | case "length": |
| | | 44 | | case "minlength": |
| | | 45 | | case "maxLength": |
| | | 46 | | case "minimum": |
| | | 47 | | case "maximum": |
| | | 48 | | case "minInclusive": |
| | | 49 | | case "maxInclusive": |
| | | 50 | | case "minExclusive": |
| | | 51 | | case "maxExclusive": |
| | | 52 | | case "format": |
| | 1 | 53 | | return errors; |
| | | 54 | | default: |
| | 1 | 55 | | return Descriptor.NormalizeProperty(property, context); |
| | | 56 | | |
| | | 57 | | } |
| | | 58 | | } |
| | | 59 | | |
| | | 60 | | new public IPropertyParserBase? GetPropertyParser(JProperty property, List<Warning> warnings) |
| | | 61 | | { |
| | 1 | 62 | | switch (property.Name) |
| | | 63 | | { |
| | | 64 | | case "base": |
| | 1 | 65 | | return new BasePropertyParser(warnings, this); |
| | | 66 | | case "format": |
| | 1 | 67 | | return new FormatPropertyParser(warnings, this); |
| | | 68 | | case "length": |
| | 1 | 69 | | return new LengthPropertyParser(warnings, this); |
| | | 70 | | case "minLength": |
| | 1 | 71 | | return new MinLengthPropertyParser(warnings, this); |
| | | 72 | | case "maxLength": |
| | 1 | 73 | | return new MaxLengthPropertyParser(warnings, this); |
| | | 74 | | case "minimum": |
| | 1 | 75 | | return new MinimumPropertyParser(warnings, this); |
| | | 76 | | case "maximum": |
| | 1 | 77 | | return new MaximumPropertyParser(warnings, this); |
| | | 78 | | case "minInclusive": |
| | 1 | 79 | | return new MinInclusivePropertyParser(warnings, this); |
| | | 80 | | case "maxInclusive": |
| | 1 | 81 | | return new MaxInclusivePropertyParser(warnings, this); |
| | | 82 | | case "minExclusive": |
| | 1 | 83 | | return new MinExclusivePropertyParser(warnings, this); |
| | | 84 | | case "maxExclusive": |
| | 1 | 85 | | return new MaxExclusivePropertyParser(warnings, this); |
| | | 86 | | default: |
| | 1 | 87 | | return ((Descriptor)this).GetPropertyParser(property, warnings); |
| | | 88 | | } |
| | | 89 | | } |
| | | 90 | | |
| | 0 | 91 | | public static IParser<DatatypeDescriptor> GetParser(List<Warning> warnings, DatatypeDescriptor? descriptor = nul |
| | | 92 | | |
| | | 93 | | } |
| | | 94 | | } |