| | 1 | | using Newtonsoft.Json.Linq; |
| | 2 | | using ValidateLib.ErrorsAndWarnings.Warnings; |
| | 3 | | using ValidateLib.IRINormalization; |
| | 4 | | using ValidateLib.Metadata.Descriptors; |
| | 5 | | using ValidateLib.Metadata.Descriptors.Interfaces; |
| | 6 | | using ValidateLib.UtilityClasses; |
| | 7 | |
|
| | 8 | | namespace ValidateLib.Metadata.Properties |
| | 9 | | { |
| | 10 | | public class ObjectProperty<T> : Property<T> where T : class, INormalize |
| | 11 | | { |
| | 12 | | string? _objectURL; |
| 1 | 13 | | public ObjectProperty(T value) : base(value) { } |
| 0 | 14 | | public ObjectProperty(string url) : base(null) |
| | 15 | | { |
| 0 | 16 | | _objectURL = url; |
| 0 | 17 | | } |
| | 18 | |
|
| | 19 | | public static List<Warning> Normalize(JToken token, Context context, JProperty? property = null) |
| | 20 | | { |
| 1 | 21 | | List<Warning> errors = new List<Warning>(); |
| 1 | 22 | | if (token.Type == JTokenType.String) |
| | 23 | | { |
| 1 | 24 | | string stringValueOfObjectProperty = token.ToString(); |
| 1 | 25 | | var resolvedLink = IRINormalizator.TurnUrlIntoAbsoluteWithBase(context._base!._value!, stringValueOfObje |
| 1 | 26 | | JToken? descriptorObjectToken = ObjectPropertyUtilityClass.GetDescriptor(resolvedLink); |
| 1 | 27 | | if (descriptorObjectToken is null) return errors; |
| 1 | 28 | | Context? localContext = Context.GetContextFromJToken(descriptorObjectToken, errors, resolvedLink); |
| 1 | 29 | | if (localContext != null) context = localContext; |
| 1 | 30 | | ObjectPropertyUtilityClass.RemoveLocalContext((JObject)descriptorObjectToken); |
| 1 | 31 | | ObjectPropertyUtilityClass.AddId((JObject)descriptorObjectToken, resolvedLink); |
| | 32 | |
|
| 1 | 33 | | token.Replace(descriptorObjectToken); |
| 1 | 34 | | Normalize(descriptorObjectToken, context, property); |
| | 35 | |
|
| | 36 | | } |
| 1 | 37 | | else if (token.Type == JTokenType.Object) |
| | 38 | | { |
| 1 | 39 | | T.Normalize(token, context, property); |
| | 40 | | } |
| 1 | 41 | | return errors; |
| | 42 | | } |
| | 43 | | } |
| | 44 | | } |