RicoSuter / NJsonSchema

JSON Schema reader, generator and validator for .NET
http://NJsonSchema.org
MIT License
1.4k stars 535 forks source link

$ref to external json file #566

Open zivkan opened 6 years ago

zivkan commented 6 years ago

I'd like to load a schema that has $refs to other json files with http urls. Currently NJsonSchema throws exceptions saying it can't resolve those references. Do you have plans to support this scenario?

An example schema is http://datafactories.schema.management.azure.com/schemas/2015-09-01/Microsoft.DataFactory.Pipeline.json. You'll need to download it with a client that doesn't automatically redirect to https or ignore https cert hostname mismatch errors.

RicoSuter commented 6 years ago

HTTP and file $refs should be supported...

RicoSuter commented 6 years ago

Please add a sample how you load the schema.

zivkan commented 6 years ago
static async Task MainAsync()
{
    var schema = await 
        JsonSchema4.FromUrlAsync(
            "http://datafactories.schema.management.azure.com/schemas/2015-09-01/Microsoft.DataFactory.Pipeline.json");
}

This gives me the error: Unhandled Exception: System.AggregateException: One or more errors occurred. (Could not resolve the JSON path 'http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/UTC' with the full JSON path 'http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/UTC'.) ---> System.InvalidOperationException: Could not resolve the JSON path 'http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/UTC' with the full JSON path 'http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/UTC'. ---> System.InvalidOperationException: Could not resolve the JSON path 'https://schema.management.azure.com/schemas/2015-08-19/Microsoft.Search.json#/resourceDefinitions/searchServices' with the full JSON path 'https://schema.management.azure.com/schemas/2015-08-19/Microsoft.Search.json#/resourceDefinitions/searchServices'. ---> System.InvalidOperationException: Could not resolve the JSON path 'https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression' with the full JSON path 'https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression'. ---> System.InvalidOperationException: Could not resolve the path '#/definitions/SearchServiceProperties'. at NJsonSchema.JsonReferenceResolver.ResolveDocumentReference(Object rootObject, String jsonPath) at NJsonSchema.JsonReferenceResolver.d__9.MoveNext()

dipti927 commented 6 years ago

I am also facing this issue while calling the external url from json.

Is there any fix available for this ?

rjmacarthy commented 6 years ago

+1

danneberg commented 6 years ago

Have the Same Problem:

var schema = JsonSchema4.FromUrlAsync(@"https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#").GetAwaiter().GetResult();

Gets:

System.InvalidOperationException: 'Could not resolve the JSON path 'https://schema.management.azure.com/schemas/2017-10-01/Microsoft.Cache.json#/resourceDefinitions/Redis' with the full JSON path 'https://schema.management.azure.com/schemas/2017-10-01/Microsoft.Cache.json#/resourceDefinitions/Redis'.'
RicoSuter commented 6 years ago

@danneberg I've created a PR with some fixes, but the problem is that the URL

https://schema.management.azure.com/schemas/2017-10-01/Microsoft.Cache.json

contains an invalid JSON Schema - there is a "resourceDefinitions" property but only "definitions" is supported...

Maybe the PR fixes the other issues? https://github.com/RSuter/NJsonSchema/pull/761

sjscymru commented 5 years ago

Was this issue ever resolved? I am having the same problem when trying to create a C# client library using NSwag Studio 13.0.6.0 . I'm trying to load the Strava API.

The Swagger document I'm trying to load is https://developers.strava.com/swagger/swagger.json.

NJsonSchema Error

irega commented 4 years ago

Same error here:

image

Waiting for PR #1098 to be merged

sebastianstudniczek commented 1 year ago

Hey. Is there maybe some workaround for this issue?