Ejemplo n.º 1
0
        /// <summary>Finds the root parent of this schema.</summary>
        /// <returns>The parent schema or this when this is the root.</returns>
        public static object FindParentDocument(this IJsonReference obj)
        {
            if (obj.DocumentPath != null)
            {
                return(obj);
            }

            var parent = obj.PossibleRoot;

            if (parent == null)
            {
                return(obj);
            }

            while ((parent as IJsonReference)?.PossibleRoot != null)
            {
                parent = ((IJsonReference)parent).PossibleRoot;
                if (parent is IDocumentPathProvider pathProvider && pathProvider.DocumentPath != null)
                {
                    return(parent);
                }
            }

            return(parent);
        }
            protected override async Task <IJsonReference> VisitJsonReferenceAsync(IJsonReference reference, string path, string typeNameHint, CancellationToken cancellationToken)
            {
                cancellationToken.ThrowIfCancellationRequested();
                if (reference.ReferencePath != null && reference.Reference == null)
                {
                    if (_replaceRefsRound)
                    {
                        if (path.EndsWith("/definitions/" + typeNameHint) || path.EndsWith("/schemas/" + typeNameHint))
                        {
                            // inline $refs in "definitions"
                            return(await _referenceResolver
                                   .ResolveReferenceWithoutAppendAsync(_rootObject, reference.ReferencePath, reference.GetType(), _contractResolver)
                                   .ConfigureAwait(false));
                        }
                    }
                    else
                    {
                        // load $refs and add them to "definitions"
                        reference.Reference = await _referenceResolver
                                              .ResolveReferenceAsync(_rootObject, reference.ReferencePath, reference.GetType(), _contractResolver)
                                              .ConfigureAwait(false);
                    }
                }

                return(reference);
            }
Ejemplo n.º 3
0
            protected override async Task <IJsonReference> VisitJsonReferenceAsync(IJsonReference reference, string path, string typeNameHint)
            {
                if (reference.ReferencePath != null && reference.Reference == null)
                {
                    if (_replaceRefsRound)
                    {
                        if (path.EndsWith("/definitions/" + typeNameHint))
                        {
                            // inline $refs in "definitions"
                            return(await _referenceResolver
                                   .ResolveReferenceWithoutAppendAsync(_rootObject, reference.ReferencePath)
                                   .ConfigureAwait(false));
                        }
                    }
                    else
                    {
                        // load $refs and add them to "definitions"
                        reference.Reference = await _referenceResolver
                                              .ResolveReferenceAsync(_rootObject, reference.ReferencePath)
                                              .ConfigureAwait(false);
                    }
                }

                return(reference);
            }
#pragma warning disable 1998
            protected override async Task <IJsonReference> VisitJsonReferenceAsync(IJsonReference reference, string path, string typeNameHint)
#pragma warning restore 1998
            {
                if (reference.Reference != null)
                {
                    if (!_removeExternalReferences || reference.Reference.DocumentPath == null)
                    {
                        _schemaReferences[reference] = reference.Reference.ActualObject;
                    }
                    else
                    {
                        var externalReference     = reference.Reference;
                        var externalReferenceRoot = externalReference.FindParentDocument();
                        reference.ReferencePath = externalReference.DocumentPath + JsonPathUtilities.GetJsonPath(
                            externalReferenceRoot, externalReference, _contractResolver).TrimEnd('#');
                    }
                }
                else if (_removeExternalReferences && _rootObject != reference && reference.DocumentPath != null)
                {
                    throw new NotSupportedException("removeExternalReferences not supported");
                    //return new JsonSchema4 { ReferencePath = reference.DocumentPath };
                }

                return(reference);
            }
        /// <summary>Called when a <see cref="IJsonReference"/> is visited.</summary>
        /// <param name="reference">The visited schema.</param>
        /// <param name="path">The path.</param>
        /// <param name="typeNameHint">The type name hint.</param>
        /// <returns>The task.</returns>
        protected override async Task <IJsonReference> VisitJsonReferenceAsync(IJsonReference reference, string path, string typeNameHint)
        {
            if (reference is JsonSchema4 schema)
            {
                return(await VisitSchemaAsync(schema, path, typeNameHint));
            }

            return(reference);
        }
Ejemplo n.º 6
0
        /// <summary>Called when a <see cref="IJsonReference"/> is visited.</summary>
        /// <param name="reference">The visited schema.</param>
        /// <param name="path">The path.</param>
        /// <param name="typeNameHint">The type name hint.</param>
        /// <returns>The task.</returns>
        protected override IJsonReference VisitJsonReference(IJsonReference reference, string path, string typeNameHint)
        {
            if (reference is JsonSchema schema)
            {
                return(VisitSchema(schema, path, typeNameHint));
            }

            return(reference);
        }
Ejemplo n.º 7
0
        /// <summary>Called when a <see cref="IJsonReference"/> is visited.</summary>
        /// <param name="reference">The visited schema.</param>
        /// <param name="path">The path.</param>
        /// <param name="typeNameHint">The type name hint.</param>
        /// <param name="cancellationToken">The cancellation token</param>
        /// <returns>The task.</returns>
        protected override async Task <IJsonReference> VisitJsonReferenceAsync(IJsonReference reference, string path, string typeNameHint, CancellationToken cancellationToken)
        {
            if (reference is JsonSchema schema)
            {
                return(await VisitSchemaAsync(schema, path, typeNameHint, cancellationToken).ConfigureAwait(false));
            }

            return(reference);
        }
Ejemplo n.º 8
0
 /// <summary>Called when a <see cref="IJsonReference"/> is visited.</summary>
 /// <param name="reference">The visited schema.</param>
 /// <param name="path">The path.</param>
 /// <param name="typeNameHint">The type name hint.</param>
 /// <returns>The task.</returns>
 protected abstract Task <IJsonReference> VisitJsonReferenceAsync(IJsonReference reference, string path, string typeNameHint);
Ejemplo n.º 9
0
 /// <summary>Adds a document reference.</summary>
 /// <param name="documentPath">The document path.</param>
 /// <param name="schema">The referenced schema.</param>
 public void AddDocumentReference(string documentPath, IJsonReference schema)
 {
     _resolvedObjects[documentPath.Contains("://") ? documentPath : DynamicApis.GetFullPath(documentPath)] = schema;
 }
Ejemplo n.º 10
0
 /// <summary>Adds a document reference.</summary>
 /// <param name="documentPath">The document path.</param>
 /// <param name="schema">The referenced schema.</param>
 public void AddDocumentReference(string documentPath, IJsonReference schema)
 {
     _resolvedObjects[documentPath] = schema;
 }
Ejemplo n.º 11
0
 /// <summary>Called when a <see cref="IJsonReference"/> is visited.</summary>
 /// <param name="reference">The visited schema.</param>
 /// <param name="path">The path.</param>
 /// <param name="typeNameHint">The type name hint.</param>
 /// <param name="cancellationToken">The cancellation token</param>
 /// <returns>The task.</returns>
 protected abstract Task <IJsonReference> VisitJsonReferenceAsync(IJsonReference reference, string path, string typeNameHint, CancellationToken cancellationToken);
 /// <summary>Called when a <see cref="IJsonReference"/> is visited.</summary>
 /// <param name="reference">The visited schema.</param>
 /// <param name="path">The path.</param>
 /// <param name="typeNameHint">The type name hint.</param>
 /// <returns>The task.</returns>
 protected abstract IJsonReference VisitJsonReference(IJsonReference reference, string path, string typeNameHint);