private void _ResolveReference(SchemaValidationContext context) { if (context.RecursiveAnchor != null) { var baseDocument = JsonSchemaRegistry.Get(context.BaseUri.OriginalString); if (baseDocument?.Get <RecursiveAnchorKeyword>() != null) { _resolvedRoot = context.RecursiveAnchor; } } if (Reference.IsLocalSchemaId()) { Resolved = context.LocalRegistry.GetLocal(Reference); if (Resolved != null) { return; } } var documentPath = _resolvedRoot?.DocumentPath ?? context.BaseUri; var referenceParts = Reference.Split(new[] { '#' }, StringSplitOptions.None); var address = string.IsNullOrWhiteSpace(referenceParts[0]) ? documentPath?.OriginalString : referenceParts[0]; _resolvedFragment = referenceParts.Length > 1 ? JsonPointer.Parse(referenceParts[1]) : new JsonPointer(); if (_resolvedRoot == null) { if (!string.IsNullOrWhiteSpace(address)) { if (!Uri.TryCreate(address, UriKind.Absolute, out var absolute)) { address = context.Local.Id + address; } if (documentPath != null && !Uri.TryCreate(address, UriKind.Absolute, out absolute)) { var uriFolder = documentPath.OriginalString.EndsWith("/") ? documentPath : documentPath.GetParentUri(); absolute = new Uri(uriFolder, address); address = absolute.OriginalString; } _resolvedRoot = JsonSchemaRegistry.Get(address); } else { _resolvedRoot = context.Root; } } var wellKnown = JsonSchemaRegistry.GetWellKnown(Reference); if (wellKnown != null) { Resolved = wellKnown; return; } _ResolveLocalReference(_resolvedRoot?.DocumentPath ?? context.BaseUri); }
private void _ResolveReference(SchemaValidationContext context) { Log.Schema($"Resolving `{Reference}`"); if (context.RecursiveAnchor != null) { Log.Schema("Finding anchor of root schema"); if (context.BaseUri == null) { throw new InvalidOperationException("BaseUri not set"); } var baseDocument = JsonSchemaRegistry.Get(context.BaseUri.OriginalString); if (baseDocument?.Get <RecursiveAnchorKeyword>() != null) { _resolvedRoot = context.RecursiveAnchor; } } if (Reference.IsLocalSchemaId()) { Log.Schema("Reference recognized as anchor or local ID"); Resolved = context.LocalRegistry.GetLocal(Reference); if (Resolved != null) { return; } Log.Schema($"`{Reference}` is an unknown anchor"); } var documentPath = _resolvedRoot?.DocumentPath ?? context.BaseUri; var referenceParts = Reference.Split(new[] { '#' }, StringSplitOptions.None); var address = string.IsNullOrWhiteSpace(referenceParts[0]) ? documentPath?.OriginalString : referenceParts[0]; _resolvedFragment = referenceParts.Length > 1 ? JsonPointer.Parse(referenceParts[1]) : new JsonPointer(); if (_resolvedRoot == null) { if (!string.IsNullOrWhiteSpace(address)) { if (!Uri.TryCreate(address, UriKind.Absolute, out _)) { address = context.Local.Id + address; } if (documentPath != null && !Uri.TryCreate(address, UriKind.Absolute, out _)) { var uriFolder = documentPath.OriginalString.EndsWith("/") ? documentPath : documentPath.GetParentUri(); var absolute = new Uri(uriFolder, address); address = absolute.OriginalString; } _resolvedRoot = JsonSchemaRegistry.Get(address); } else { _resolvedRoot = context.Root; } } if (_resolvedRoot == null) { Log.Schema("Could not resolve root of reference"); return; } var wellKnown = JsonSchemaRegistry.GetWellKnown(Reference); if (wellKnown != null) { Log.Schema("Well known reference found"); Resolved = wellKnown; return; } _ResolveLocalReference(_resolvedRoot?.DocumentPath ?? context.BaseUri !); }
private void _ResolveReference(SchemaValidationContext context) { Log.Schema($"Resolving `{Reference}`"); if (Reference.IsLocalSchemaId()) { Log.Schema("Reference recognized as anchor or local ID"); Resolved = context.LocalRegistry.GetLocal(Reference); if (Resolved != null) { return; } Log.Schema($"`{Reference}` is an unknown anchor"); } var documentPath = context.BaseUri; var referenceParts = Reference.Split(new[] { '#' }, StringSplitOptions.None); var address = string.IsNullOrWhiteSpace(referenceParts[0]) ? documentPath?.OriginalString.Split('#')[0] : referenceParts[0]; _resolvedFragment = referenceParts.Length > 1 ? JsonPointer.Parse(referenceParts[1]) : new JsonPointer(); if (!string.IsNullOrWhiteSpace(address)) { if (!Uri.TryCreate(address, UriKind.Absolute, out var absolute) && (JsonSchemaOptions.RefResolution == RefResolutionStrategy.ProcessSiblingId || context.Root.SupportedVersions == JsonSchemaVersion.Draft2019_09)) { address = context.Local.Id + address; } if (documentPath != null && !Uri.TryCreate(address, UriKind.Absolute, out absolute)) { var uriFolder = documentPath.OriginalString.EndsWith("/") ? documentPath : documentPath.GetParentUri(); absolute = new Uri(uriFolder, address); address = absolute.OriginalString; } _resolvedRoot = JsonSchemaRegistry.Get(address); } else { _resolvedRoot = context.Root; } if (_resolvedRoot == null) { Log.Schema("Could not resolve root of reference"); return; } var wellKnown = JsonSchemaRegistry.GetWellKnown(Reference); if (wellKnown != null) { Log.Schema("Well known reference found"); Resolved = wellKnown; return; } _ResolveLocalReference(_resolvedRoot?.DocumentPath ?? context.BaseUri !); }