Skip to content

Commit

Permalink
Added possibility to override default file path resolver (#1362)
Browse files Browse the repository at this point in the history
Co-authored-by: Marek Landuch <mala@scalepoint.com>
  • Loading branch information
mareklanduch and mareklanduch authored May 7, 2021
1 parent c531cad commit 94997ea
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/NJsonSchema/JsonReferenceResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,7 @@ private async Task<IJsonReference> ResolveReferenceAsync(object rootObject, stri
// Split the file path and fragment before concatenating with
// document path. If document path have '#' in it, doing this
// later would not work.

var arr = Regex.Split(jsonPath, @"(?=#)");
var filePath = DynamicApis.PathCombine(DynamicApis.PathGetDirectoryName(documentPath), arr[0]);
var filePath = ResolveFilePath(documentPath, jsonPath);
return await ResolveFileReferenceWithAlreadyResolvedCheckAsync(filePath, targetType, contractResolver, jsonPath, append, cancellationToken).ConfigureAwait(false);
}
}
Expand All @@ -170,6 +168,15 @@ private async Task<IJsonReference> ResolveReferenceAsync(object rootObject, stri
}
}

/// <summary>Resolves file path.</summary>
/// <param name="documentPath">The document path.</param>
/// <param name="jsonPath">The JSON path</param>
public virtual string ResolveFilePath(string documentPath, string jsonPath)
{
var arr = Regex.Split(jsonPath, @"(?=#)");
return DynamicApis.PathCombine(DynamicApis.PathGetDirectoryName(documentPath), arr[0]);
}

private async Task<IJsonReference> ResolveFileReferenceWithAlreadyResolvedCheckAsync(string filePath, Type targetType, IContractResolver contractResolver, string jsonPath, bool append, CancellationToken cancellationToken)
{
try
Expand Down

0 comments on commit 94997ea

Please sign in to comment.