Skip to content

Commit

Permalink
-Fixed generating schema paths
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesNK committed Feb 7, 2015
1 parent 6c43400 commit e2515a4
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 2 deletions.
19 changes: 19 additions & 0 deletions Src/Newtonsoft.Json.Schema.Tests/ExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,25 @@ namespace Newtonsoft.Json.Schema.Tests
[TestFixture]
public class ExtensionsTests : TestFixtureBase
{
[Test]
public void ValidationErrorPath()
{
string schemaJson = TestHelpers.OpenFileText(@"resources\schemas\schema-draft-v4.json");
JSchema s = JSchema.Parse(schemaJson);

JObject o = JObject.Parse(@"{ ""additionalItems"": 5 }");

IList<ValidationError> validationErrors;
o.IsValid(s, out validationErrors);

Assert.AreEqual(1, validationErrors.Count);
Assert.AreEqual("#/properties/additionalItems", validationErrors[0].SchemaId.ToString());
Assert.AreEqual(2, validationErrors[0].ChildErrors.Count);

Assert.AreEqual("#", validationErrors[0].ChildErrors[0].SchemaId.ToString());
Assert.AreEqual("#/properties/additionalItems/anyOf/0", validationErrors[0].ChildErrors[1].SchemaId.ToString());
}

[Test]
public void IsValid()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private void DiscoverInternal(JSchema schema, string latestPath)
if (schema.Id == null)
{
Uri currentScopeId = _pathStack.First().Id;
currentPath = string.Join("/", _pathStack.Where(p => p.Id == currentScopeId && !string.IsNullOrEmpty(p.Path)).Select(p => p.Path));
currentPath = string.Join("/", _pathStack.Where(p => p.Id == currentScopeId && !string.IsNullOrEmpty(p.Path)).Reverse().Select(p => p.Path));

if (!string.IsNullOrEmpty(currentPath))
currentPath += "/";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
#endregion

using System;
using System.Diagnostics;

namespace Newtonsoft.Json.Schema.Infrastructure.Discovery
{
[DebuggerDisplay("{Id}")]
internal class KnownSchema
{
public Uri Id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
#endregion

using System;
using System.Diagnostics;

namespace Newtonsoft.Json.Schema.Infrastructure.Discovery
{
[DebuggerDisplay("Id = {Id}, Path = {Path}")]
internal class SchemaPath
{
public readonly Uri Id;
Expand Down
2 changes: 1 addition & 1 deletion Src/NuGet.Config
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<packageSources>
<clear />
<add key="NuGet official package source" value="https://nuget.org/api/v2/" />
<add key="Json.NET" value="https://www.myget.org/F/json-net-unsigned/api/v2" />
<add key="Json.NET Unsigned" value="https://www.myget.org/F/json-net-unsigned/api/v2" />
</packageSources>
<activePackageSource>
<add key="All" value="(Aggregate source)" />
Expand Down

0 comments on commit e2515a4

Please sign in to comment.