#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>Updates the <see cref="IJsonReferenceBase.Reference" /> properties
        /// from the available <see cref="IJsonReferenceBase.Reference" /> properties.</summary>
        /// <param name="rootObject">The root object.</param>
        /// <param name="removeExternalReferences">Specifies whether to remove external references (otherwise they are inlined).</param>
        /// <param name="contractResolver">The contract resolver.</param>
        public static void UpdateSchemaReferencePaths(object rootObject, bool removeExternalReferences, IContractResolver contractResolver)
        {
            var schemaReferences = new Dictionary <IJsonReference, IJsonReference>();

            var updater = new JsonReferencePathUpdater(rootObject, schemaReferences, removeExternalReferences, contractResolver);

            updater.VisitAsync(rootObject).GetAwaiter().GetResult();

            var searchedSchemas = schemaReferences.Select(p => p.Value).Distinct();
            var result          = JsonPathUtilities.GetJsonPaths(rootObject, searchedSchemas, contractResolver);

            foreach (var p in schemaReferences)
            {
                p.Key.ReferencePath = result[p.Value];
            }
        }