Skip to content

Commit

Permalink
Merge pull request #423 from gregsdennis/schema/registration-should-a…
Browse files Browse the repository at this point in the history
…lways-initialize

registration with inferred uri should still initialize the schema
  • Loading branch information
gregsdennis committed Mar 29, 2023
2 parents 88cfea8 + 012067d commit ea67872
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 13 deletions.
7 changes: 7 additions & 0 deletions JsonSchema.Tests/Files/Issue419_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"global": {
"timeSpan": {
"weekly": true
}
}
}
11 changes: 11 additions & 0 deletions JsonSchema.Tests/Files/Issue419_level1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$id": "level1.json",
"properties": {
"timeSpan": {
"$ref": "level2.json"
}
},
"required": [
"timeSpan"
]
}
11 changes: 11 additions & 0 deletions JsonSchema.Tests/Files/Issue419_level2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$id": "level2.json",
"required": [
"weekly"
],
"properties": {
"weekly": {
"type": "boolean"
}
}
}
12 changes: 12 additions & 0 deletions JsonSchema.Tests/Files/Issue419_root.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"$id": "root.json",
"type": "object",
"required": [
"global"
],
"properties": {
"global": {
"$ref": "level1.json"
}
}
}
38 changes: 29 additions & 9 deletions JsonSchema.Tests/GithubTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.Encodings.Web;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Threading.Tasks;
Expand All @@ -13,6 +12,17 @@ namespace Json.Schema.Tests;

public class GithubTests
{
private static string GetFile(int issue, string name)
{
return Path.Combine(TestContext.CurrentContext.WorkDirectory, "Files", $"Issue{issue}_{name}.json")
.AdjustForPlatform();
}

private static string GetResource(int issue, string name)
{
return File.ReadAllText(GetFile(issue, name));
}

[Test]
public void Issue18_SomethingNotValidatingRight()
{
Expand Down Expand Up @@ -517,14 +527,6 @@ public void Evaluate(EvaluationContext context)
}
}

private static string GetResource(int issue, string name)
{
var path = Path.Combine(TestContext.CurrentContext.WorkDirectory, "Files", $"Issue{issue}_{name}.json")
.AdjustForPlatform();

return File.ReadAllText(path);
}

[Test]
public void Issue191_SelfReferentialCustomMetaschemaShouldError()
{
Expand Down Expand Up @@ -764,4 +766,22 @@ public void Issue417_BundleWithItemsFails()
.Build();
multiItemSchema.Bundle(); // throws
}

[Test]
public void Issue419_SecondLevelReferences()
{
var level2 = JsonSchema.FromFile(GetFile(419, "level2"));
SchemaRegistry.Global.Register(level2);

var level1 = JsonSchema.FromFile(GetFile(419, "level1"));
SchemaRegistry.Global.Register(level1);

var rootSchema = JsonSchema.FromFile(GetFile(419, "root"));

var config = JsonNode.Parse(GetResource(419, "config"));

var result = rootSchema.Evaluate(config);

result.AssertValid();
}
}
4 changes: 2 additions & 2 deletions JsonSchema/JsonSchema.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<PackageProjectUrl>https://github.com/gregsdennis/json-everything</PackageProjectUrl>
<RepositoryUrl>https://github.com/gregsdennis/json-everything</RepositoryUrl>
<PackageTags>json-schema validation schema json</PackageTags>
<Version>4.0.1</Version>
<FileVersion>4.0.1.0</FileVersion>
<Version>4.0.2</Version>
<FileVersion>4.0.2.0</FileVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<AssemblyName>JsonSchema.Net</AssemblyName>
Expand Down
2 changes: 1 addition & 1 deletion JsonSchema/SchemaRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ internal void InitializeMetaSchemas()
/// <param name="document">The schema.</param>
public void Register(IBaseDocument document)
{
RegisterSchema(document.BaseUri, document);
Register(document.BaseUri, document);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion json-everything.net/wwwroot/md/release-notes/json-logic.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# [4.0.3](https://github.com/gregsdennis/json-everything/pull/422) {#release-logic-4.0.3}
# [4.0.4](https://github.com/gregsdennis/json-everything/pull/422) {#release-logic-4.0.4}

[#420](https://github.com/gregsdennis/json-everything/issues/404) - `<=` not working for the "between" case. Thanks to [@alexkharuk](https://github.com/alexkharuk) for finding and fixing this issue.

Expand Down
4 changes: 4 additions & 0 deletions json-everything.net/wwwroot/md/release-notes/json-schema.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# [4.0.2](https://github.com/gregsdennis/json-everything/pull/423) {#release-schema-4.0.2}

[#419](https://github.com/gregsdennis/json-everything/issues/419) - Fixed an issue with schema registration and populating IDs. Thanks to [@lennver](https://github.com/lennver) for providing reproduction for this issue.

# [4.0.1](https://github.com/gregsdennis/json-everything/pull/418) {#release-schema-4.0.1}

- Add `IIdKeyword` to potentially support using an ID keyword other than `$id` (foot gun, generally, please don't use)
Expand Down

0 comments on commit ea67872

Please sign in to comment.