[TestMethod]
[DeploymentItem(@"Files\IssueRefCore.json", "Files")]
[DeploymentItem(@"Files\IssueRefChild.json", "Files")]
public void UriReferenceSchemaTest()
{
const string coreSchemaUri = "http://example.org/IssueRefCore.json";
const string childSchemaUri = "http://example.org/IssueRefChild.json";
string coreSchemaPath = System.IO.Path.Combine(TestContext.TestDeploymentDir, @"Files\IssueRefCore.json");
string childSchemaPath = System.IO.Path.Combine(TestContext.TestDeploymentDir, @"Files\IssueRefChild.json");
var coreSchemaText = string.Empty;
var childSchemaText = string.Empty;
using (TextReader reader = File.OpenText(coreSchemaPath))
{
coreSchemaText = reader.ReadToEnd();
}
using (TextReader reader = File.OpenText(childSchemaPath))
{
childSchemaText = reader.ReadToEnd();
}
var requestedUris = new List<string>();
JsonSchemaOptions.Download = (uri) =>
{
requestedUris.Add(uri);
switch(uri)
{
case coreSchemaUri:
return coreSchemaText;
case childSchemaUri:
return childSchemaText;
}
return coreSchemaText;
};
var schema = JsonSchemaRegistry.Get(childSchemaUri);
var testJson = new JsonObject();
testJson["myProperty"] = "http://example.org/";
var result = schema.Validate(testJson);
Assert.IsTrue(result.Valid);
Assert.AreEqual(requestedUris[0], childSchemaUri);
Assert.AreEqual(requestedUris[1], coreSchemaUri);
}
{
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "http://example.org/IssueRefCore#",
"title": "Core Schema",
"description": "",
"definitions": {
"myProperty": {
"type": "string",
"format": "uri"
}
}
}
{
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "http://example.org/IssueRefChild#",
"title": "Child Schema",
"description": "",
"properties": {
"myProperty": { "$ref": "IssueRefCore.json#/definitions/myProperty" }
},
"required" : [ "myProperty" ]
}
this test fails.
"myProperty": { "$ref": "IssueRefCore.json#/definitions/myProperty" }