Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

-Lots and lots of JSON Schema work

-JSON Schema spec tests added
-Added Path to JToken
-Fixed JTokenWriter returning null reference
-Build script logging
-Documentation
-Updated to NUnit 2.6
commit e3a720504e070e22909360048a1acdb86e74dd7a 1 parent 86a9b7b
@JamesNK authored
Showing with 18,051 additions and 4,458 deletions.
  1. +14 −14 Build/build.ps1
  2. +1 −1  Build/runbuild.cmd
  3. +7 −10 Doc/Introduction.aml
  4. +7 −0 Doc/PreserveObjectReferences.aml
  5. BIN  Src/Lib/NUnit/DotNet/nunit.framework.dll
  6. +8,715 −3,337 Src/Lib/NUnit/DotNet/nunit.framework.xml
  7. +2 −2 Src/Newtonsoft.Json.Tests/JsonValidatingReaderTests.cs
  8. +17 −0 Src/Newtonsoft.Json.Tests/Linq/DynamicTests.cs
  9. +33 −0 Src/Newtonsoft.Json.Tests/Linq/JTokenTests.cs
  10. +34 −0 Src/Newtonsoft.Json.Tests/Linq/JValueTests.cs
  11. +19 −0 Src/Newtonsoft.Json.Tests/Linq/LinqToJsonTest.cs
  12. +67 −0 Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.csproj
  13. +1 −1  Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs
  14. +149 −7 Src/Newtonsoft.Json.Tests/Schema/ExtensionsTests.cs
  15. +182 −89 Src/Newtonsoft.Json.Tests/Schema/JsonSchemaBuilderTests.cs
  16. +0 −14 Src/Newtonsoft.Json.Tests/Schema/JsonSchemaGeneratorTests.cs
  17. +84 −40 Src/Newtonsoft.Json.Tests/Schema/JsonSchemaTests.cs
  18. +82 −0 Src/Newtonsoft.Json.Tests/Schema/Specs/additionalItems.json
  19. +63 −0 Src/Newtonsoft.Json.Tests/Schema/Specs/additionalProperties.json
  20. +108 −0 Src/Newtonsoft.Json.Tests/Schema/Specs/dependencies.json
  21. +80 −0 Src/Newtonsoft.Json.Tests/Schema/Specs/disallow.json
  22. +60 −0 Src/Newtonsoft.Json.Tests/Schema/Specs/divisibleBy.json
  23. +39 −0 Src/Newtonsoft.Json.Tests/Schema/Specs/enum.json
  24. +94 −0 Src/Newtonsoft.Json.Tests/Schema/Specs/extends.json
  25. +46 −0 Src/Newtonsoft.Json.Tests/Schema/Specs/items.json
  26. +28 −0 Src/Newtonsoft.Json.Tests/Schema/Specs/maxItems.json
  27. +28 −0 Src/Newtonsoft.Json.Tests/Schema/Specs/maxLength.json
  28. +42 −0 Src/Newtonsoft.Json.Tests/Schema/Specs/maximum.json
  29. +28 −0 Src/Newtonsoft.Json.Tests/Schema/Specs/minItems.json
  30. +28 −0 Src/Newtonsoft.Json.Tests/Schema/Specs/minLength.json
  31. +42 −0 Src/Newtonsoft.Json.Tests/Schema/Specs/minimum.json
  32. +23 −0 Src/Newtonsoft.Json.Tests/Schema/Specs/pattern.json
  33. +79 −0 Src/Newtonsoft.Json.Tests/Schema/Specs/patternProperties.json
  34. +92 −0 Src/Newtonsoft.Json.Tests/Schema/Specs/properties.json
  35. +84 −0 Src/Newtonsoft.Json.Tests/Schema/Specs/ref.json
  36. +53 −0 Src/Newtonsoft.Json.Tests/Schema/Specs/required.json
  37. +479 −0 Src/Newtonsoft.Json.Tests/Schema/Specs/type.json
  38. +79 −0 Src/Newtonsoft.Json.Tests/Schema/Specs/uniqueItems.json
  39. +1 −1  Src/Newtonsoft.Json.Tests/TestFixtureBase.cs
  40. +7 −0 Src/Newtonsoft.Json/JsonException.cs
  41. +1 −1  Src/Newtonsoft.Json/JsonSerializationException.cs
  42. +128 −39 Src/Newtonsoft.Json/JsonValidatingReader.cs
  43. +16 −5 Src/Newtonsoft.Json/JsonWriter.cs
  44. +40 −0 Src/Newtonsoft.Json/Linq/JToken.cs
  45. +1 −1  Src/Newtonsoft.Json/Linq/JTokenWriter.cs
  46. +1 −0  Src/Newtonsoft.Json/PreserveReferencesHandling.cs
  47. +1 −1  Src/Newtonsoft.Json/Properties/AssemblyInfo.cs
  48. +35 −14 Src/Newtonsoft.Json/Schema/JsonSchema.cs
  49. +278 −264 Src/Newtonsoft.Json/Schema/JsonSchemaBuilder.cs
  50. +2 −2 Src/Newtonsoft.Json/Schema/JsonSchemaConstants.cs
  51. +0 −2  Src/Newtonsoft.Json/Schema/JsonSchemaGenerator.cs
  52. +9 −1 Src/Newtonsoft.Json/Schema/JsonSchemaModel.cs
  53. +16 −1 Src/Newtonsoft.Json/Schema/JsonSchemaModelBuilder.cs
  54. +2 −0  Src/Newtonsoft.Json/Schema/JsonSchemaNode.cs
  55. +10 −5 Src/Newtonsoft.Json/Schema/JsonSchemaResolver.cs
  56. +42 −24 Src/Newtonsoft.Json/Schema/JsonSchemaWriter.cs
  57. +1 −1  Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs
  58. BIN  Tools/NUnit/framework/nunit.framework.dll
  59. +665 −173 Tools/NUnit/framework/nunit.framework.xml
  60. BIN  Tools/NUnit/framework/nunit.mocks.dll
  61. BIN  Tools/NUnit/framework/pnunit.framework.dll
  62. BIN  Tools/NUnit/lib/Images/Ellipsis.gif
  63. BIN  Tools/NUnit/lib/Images/Tree/Circles/Failure.jpg
  64. BIN  Tools/NUnit/lib/Images/Tree/Circles/Ignored.jpg
  65. BIN  Tools/NUnit/lib/Images/Tree/Circles/Inconclusive.jpg
  66. BIN  Tools/NUnit/lib/Images/Tree/Circles/Skipped.jpg
  67. BIN  Tools/NUnit/lib/Images/Tree/Circles/Success.jpg
  68. BIN  Tools/NUnit/lib/Images/Tree/Classic/Failure.jpg
  69. BIN  Tools/NUnit/lib/Images/Tree/Classic/Ignored.jpg
  70. BIN  Tools/NUnit/lib/Images/Tree/Classic/Inconclusive.jpg
  71. BIN  Tools/NUnit/lib/Images/Tree/Classic/Skipped.jpg
  72. BIN  Tools/NUnit/lib/Images/Tree/Classic/Success.jpg
  73. 0  Tools/NUnit/lib/{failure.png → Images/Tree/Default/Failure.png}
  74. BIN  Tools/NUnit/lib/Images/Tree/Default/Ignored.png
  75. 0  Tools/NUnit/lib/{inconclusive.png → Images/Tree/Default/Inconclusive.png}
  76. 0  Tools/NUnit/lib/{skipped.png → Images/Tree/Default/Skipped.png}
  77. 0  Tools/NUnit/lib/{success.png → Images/Tree/Default/Success.png}
  78. BIN  Tools/NUnit/lib/Images/Tree/Visual Studio/Failure.png
  79. BIN  Tools/NUnit/lib/Images/Tree/Visual Studio/Ignored.png
  80. BIN  Tools/NUnit/lib/Images/Tree/Visual Studio/Inconclusive.png
  81. BIN  Tools/NUnit/lib/Images/Tree/Visual Studio/SeriousWarning.png
  82. BIN  Tools/NUnit/lib/Images/Tree/Visual Studio/Skipped.png
  83. BIN  Tools/NUnit/lib/Images/Tree/Visual Studio/Success.png
  84. BIN  Tools/NUnit/lib/Images/pinned.gif
  85. BIN  Tools/NUnit/lib/Images/unpinned.gif
  86. BIN  Tools/NUnit/lib/NSubstitute.dll
  87. +259 −0 Tools/NUnit/lib/NSubstitute.xml
  88. BIN  Tools/NUnit/lib/Rhino.Mocks.dll
  89. +5,413 −0 Tools/NUnit/lib/Rhino.Mocks.xml
  90. BIN  Tools/NUnit/lib/ignored.png
  91. BIN  Tools/NUnit/lib/log4net.dll
  92. BIN  Tools/NUnit/lib/nunit-console-runner.dll
  93. BIN  Tools/NUnit/lib/nunit-gui-runner.dll
  94. BIN  Tools/NUnit/lib/nunit.core.dll
  95. BIN  Tools/NUnit/lib/nunit.core.interfaces.dll
  96. BIN  Tools/NUnit/lib/nunit.uiexception.dll
  97. BIN  Tools/NUnit/lib/nunit.uikit.dll
  98. BIN  Tools/NUnit/lib/nunit.util.dll
  99. BIN  Tools/NUnit/nunit-agent-x86.exe
  100. +24 −56 Tools/NUnit/nunit-agent-x86.exe.config
  101. BIN  Tools/NUnit/nunit-agent.exe
  102. +24 −56 Tools/NUnit/nunit-agent.exe.config
  103. BIN  Tools/NUnit/nunit-console-x86.exe
  104. +22 −67 Tools/NUnit/nunit-console-x86.exe.config
  105. BIN  Tools/NUnit/nunit-console.exe
  106. +22 −67 Tools/NUnit/nunit-console.exe.config
  107. BIN  Tools/NUnit/nunit-x86.exe
  108. +21 −81 Tools/NUnit/nunit-x86.exe.config
  109. BIN  Tools/NUnit/nunit.exe
  110. +21 −81 Tools/NUnit/nunit.exe.config
View
28 Build/build.ps1
@@ -17,8 +17,8 @@
$workingDir = "$baseDir\Working"
$builds = @(
@{Name = "Newtonsoft.Json"; TestsName = "Newtonsoft.Json.Tests"; Constants=""; FinalDir="Net40"; NuGetDir = "net40"; Framework="net-4.0"; Sign=$true},
- @{Name = "Newtonsoft.Json.Portable"; TestsName = "Newtonsoft.Json.Tests.Portable"; Constants="PORTABLE"; FinalDir="Portable"; NuGetDir = "portable-net40+sl4+wp7+win8"; Framework="net-4.0"; Sign=$true},
- @{Name = "Newtonsoft.Json.WinRT"; TestsName = $null; Constants="NETFX_CORE"; FinalDir="WinRT"; NuGetDir = "winrt45"; Framework="net-4.5"; Sign=$true},
+ #@{Name = "Newtonsoft.Json.Portable"; TestsName = "Newtonsoft.Json.Tests.Portable"; Constants="PORTABLE"; FinalDir="Portable"; NuGetDir = "portable-net40+sl4+wp7+win8"; Framework="net-4.0"; Sign=$true},
+ #@{Name = "Newtonsoft.Json.WinRT"; TestsName = $null; Constants="NETFX_CORE"; FinalDir="WinRT"; NuGetDir = "winrt45"; Framework="net-4.5"; Sign=$true},
@{Name = "Newtonsoft.Json.WindowsPhone"; TestsName = $null; Constants="SILVERLIGHT;WINDOWS_PHONE"; FinalDir="WindowsPhone"; NuGetDir = "sl3-wp,sl4-windowsphone71"; Framework="net-4.0"; Sign=$true},
@{Name = "Newtonsoft.Json.Silverlight"; TestsName = "Newtonsoft.Json.Tests.Silverlight"; Constants="SILVERLIGHT"; FinalDir="Silverlight"; NuGetDir = "sl4"; Framework="net-4.0"; Sign=$true},
@{Name = "Newtonsoft.Json.Net35"; TestsName = "Newtonsoft.Json.Tests.Net35"; Constants="NET35"; FinalDir="Net35"; NuGetDir = "net35"; Framework="net-2.0"; Sign=$true},
@@ -59,7 +59,7 @@ task Build -depends Clean {
Write-Host -ForegroundColor Green "Building " $name
Write-Host -ForegroundColor Green "Signed " $sign
Write-Host
- exec { msbuild "/t:Clean;Rebuild" /p:Configuration=Release "/p:Platform=Any CPU" /p:OutputPath=bin\Release\$finalDir\ /p:AssemblyOriginatorKeyFile=$signKeyPath "/p:SignAssembly=$sign" (GetConstants $build.Constants $sign) ".\Src\$name.sln" } "Error building $name"
+ exec { msbuild "/t:Clean;Rebuild" /p:Configuration=Release "/p:Platform=Any CPU" /p:OutputPath=bin\Release\$finalDir\ /p:AssemblyOriginatorKeyFile=$signKeyPath "/p:SignAssembly=$sign" (GetConstants $build.Constants $sign) ".\Src\$name.sln" | Out-Default } "Error building $name"
}
}
@@ -70,7 +70,7 @@ task Package -depends Build {
$name = $build.TestsName
$finalDir = $build.FinalDir
- robocopy "$sourceDir\Newtonsoft.Json\bin\Release\$finalDir" $workingDir\Package\Bin\$finalDir /NP /XO /XF *.pri
+ robocopy "$sourceDir\Newtonsoft.Json\bin\Release\$finalDir" $workingDir\Package\Bin\$finalDir /NP /XO /XF *.pri | Out-Default
}
if ($buildNuGet)
@@ -88,7 +88,7 @@ task Package -depends Build {
foreach ($frameworkDir in $frameworkDirs)
{
- robocopy "$sourceDir\Newtonsoft.Json\bin\Release\$finalDir" $workingDir\NuGet\lib\$frameworkDir /NP /XO /XF *.pri
+ robocopy "$sourceDir\Newtonsoft.Json\bin\Release\$finalDir" $workingDir\NuGet\lib\$frameworkDir /NP /XO /XF *.pri | Out-Default
}
}
}
@@ -105,7 +105,7 @@ task Package -depends Build {
Write-Host -ForegroundColor Green "Building documentation from $documentationSourcePath"
# Sandcastle has issues when compiling with .NET 4 MSBuild - http://shfb.codeplex.com/Thread/View.aspx?ThreadId=50652
- exec { msbuild "/t:Clean;Rebuild" /p:Configuration=Release "/p:DocumentationSourcePath=$documentationSourcePath" $docDir\doc.shfbproj } "Error building documentation. Check that you have Sandcastle, Sandcastle Help File Builder and HTML Help Workshop installed."
+ exec { msbuild "/t:Clean;Rebuild" /p:Configuration=Release "/p:DocumentationSourcePath=$documentationSourcePath" $docDir\doc.shfbproj | Out-Default } "Error building documentation. Check that you have Sandcastle, Sandcastle Help File Builder and HTML Help Workshop installed."
move -Path $workingDir\Documentation\LastBuild.log -Destination $workingDir\Documentation.log
}
@@ -113,17 +113,17 @@ task Package -depends Build {
Copy-Item -Path $docDir\readme.txt -Destination $workingDir\Package\
Copy-Item -Path $docDir\versions.txt -Destination $workingDir\Package\Bin\
- robocopy $sourceDir $workingDir\Package\Source\Src /MIR /NP /XD .svn bin obj TestResults AppPackages /XF *.suo *.user
- robocopy $buildDir $workingDir\Package\Source\Build /MIR /NP /XD .svn
- robocopy $docDir $workingDir\Package\Source\Doc /MIR /NP /XD .svn
- robocopy $toolsDir $workingDir\Package\Source\Tools /MIR /NP /XD .svn
+ robocopy $sourceDir $workingDir\Package\Source\Src /MIR /NP /XD .svn bin obj TestResults AppPackages /XF *.suo *.user | Out-Default
+ robocopy $buildDir $workingDir\Package\Source\Build /MIR /NP /XD .svn | Out-Default
+ robocopy $docDir $workingDir\Package\Source\Doc /MIR /NP /XD .svn | Out-Default
+ robocopy $toolsDir $workingDir\Package\Source\Tools /MIR /NP /XD .svn | Out-Default
- exec { .\Tools\7-zip\7za.exe a -tzip $workingDir\$zipFileName $workingDir\Package\* } "Error zipping"
+ exec { .\Tools\7-zip\7za.exe a -tzip $workingDir\$zipFileName $workingDir\Package\* | Out-Default } "Error zipping"
}
# Unzip package to a location
task Deploy -depends Package {
- exec { .\Tools\7-zip\7za.exe x -y "-o$workingDir\Deployed" $workingDir\$zipFileName } "Error unzipping"
+ exec { .\Tools\7-zip\7za.exe x -y "-o$workingDir\Deployed" $workingDir\$zipFileName | Out-Default } "Error unzipping"
}
# Run tests on deployed files
@@ -138,13 +138,13 @@ task Test -depends Deploy {
Write-Host -ForegroundColor Green "Copying test assembly $name to deployed directory"
Write-Host
- robocopy ".\Src\Newtonsoft.Json.Tests\bin\Release\$finalDir" $workingDir\Deployed\Bin\$finalDir /NP /XO /XF LinqBridge.dll
+ robocopy ".\Src\Newtonsoft.Json.Tests\bin\Release\$finalDir" $workingDir\Deployed\Bin\$finalDir /MIR /NP /XO /XF LinqBridge.dll | Out-Default
Copy-Item -Path ".\Src\Newtonsoft.Json.Tests\bin\Release\$finalDir\Newtonsoft.Json.Tests.dll" -Destination $workingDir\Deployed\Bin\$finalDir\
Write-Host -ForegroundColor Green "Running tests " $name
Write-Host
- exec { .\Tools\NUnit\nunit-console.exe "$workingDir\Deployed\Bin\$finalDir\Newtonsoft.Json.Tests.dll" /framework=$framework /xml:$workingDir\$name.xml } "Error running $name tests"
+ exec { .\Tools\NUnit\nunit-console.exe "$workingDir\Deployed\Bin\$finalDir\Newtonsoft.Json.Tests.dll" /framework=$framework /xml:$workingDir\$name.xml | Out-Default } "Error running $name tests"
}
}
}
View
2  Build/runbuild.cmd
@@ -1,2 +1,2 @@
-powershell -Command "& {Import-Module ..\Tools\PSake\psake.psm1; Invoke-psake .\build.ps1 %*}"
+powershell -Command "& { [Console]::WindowWidth = 200; [Console]::WindowHeight = 50; Start-Transcript runbuild.txt; Import-Module ..\Tools\PSake\psake.psm1; Invoke-psake .\build.ps1 %*; Stop-Transcript; }"
pause
View
17 Doc/Introduction.aml
@@ -95,25 +95,22 @@ and write from your objects.</para>
<linkTarget>_blank</linkTarget>
</externalLink>,
Microsoft's HTTP service framework.</para>
- <para><externalLink>
- <linkText>James Newton-King</linkText>
- <linkUri>http://twitter.com/jamesnk</linkUri>
- <linkTarget>_blank</linkTarget>
- </externalLink></para>
+ <para><markup>
+ <a href="https://twitter.com/JamesNK" class="twitter-follow-button" data-show-count="false" data-lang="en" data-size="large">Follow @JamesNK</a>
+ <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
+ </markup></para>
</content>
</section>
<section>
<title>Donate</title>
- <content><para>Json.NET is a free open source project developed in my own time.</para>
- <para>I really appreciate your feedback and donations help support Json.NET and its future development.</para></content>
+ <content><para>Json.NET is a personal open source project. Started in 2006, I have put hundreds of hours adding, refining and tuning Json.NET with the goal to make it not just the best JSON serializer for .NET but the best serializer for any computer language. I need your
+ help to achieve this.</para></content>
</section>
<markup>
<p>
- <a target="_blank" href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&amp;business=james%40newtonking%2ecom&amp;item_name=Supporting%20Json%2eNET&amp;no_shipping=0&amp;no_note=1&amp;tax=0&amp;currency_code=USD&amp;lc=US&amp;bn=PP%2dDonationsBF&amp;charset=UTF%2d8">
- <img style="border-width:0;" alt="Donate" src="../donate.gif" />
- </a>
+ <a href="http://www.pledgie.com/campaigns/18941" target="_blank"><img src="http://www.pledgie.com/campaigns/18941.png?skin_name=chrome" alt="Click here to lend your support to: Json.NET and make a donation at www.pledgie.com !" border="0" /></a>
</p>
</markup>
<relatedTopics>
View
7 Doc/PreserveObjectReferences.aml
@@ -37,6 +37,13 @@
<para>With PreserveReferencesHandling on now only one Person object is created
on deserialization and the list contains two references to it, mirroring
what we started with.</para>
+<alert class="note">
+ <para>References cannot be preserved when a value is set via a non-default constructor.
+ With a non-default constructor child values must be created before the parent value so they can be passed into
+ the constructor, making tracking reference impossible.
+ <codeEntityReference>T:System.Runtime.Serialization.ISerializable</codeEntityReference> types are an example
+ of a class whose values are populated with a non-default constructor and won't work with PreserveReferencesHandling.</para>
+</alert>
</content>
</section>
View
BIN  Src/Lib/NUnit/DotNet/nunit.framework.dll
Binary file not shown
View
12,052 Src/Lib/NUnit/DotNet/nunit.framework.xml
8,715 additions, 3,337 deletions not shown
View
4 Src/Newtonsoft.Json.Tests/JsonValidatingReaderTests.cs
@@ -1068,12 +1068,12 @@ public void ExtendsMissingRequiredProperties()
}
[Test]
- public void NoAdditionalProperties()
+ public void NoAdditionalItems()
{
string schemaJson = @"{
""type"":""array"",
""items"": [{""type"":""string""},{""type"":""integer""}],
- ""additionalProperties"": false
+ ""additionalItems"": false
}";
string json = @"[1, 'a', null]";
View
17 Src/Newtonsoft.Json.Tests/Linq/DynamicTests.cs
@@ -76,6 +76,23 @@ public void JObjectPropertyNames()
}
[Test]
+ public void JObjectCount()
+ {
+ JObject o = new JObject();
+
+ dynamic d = o;
+
+ long? c1 = d.Count;
+
+ o["Count"] = 99;
+
+ long? c2 = d.Count;
+
+ Assert.AreEqual(null, c1);
+ Assert.AreEqual(99, c2);
+ }
+
+ [Test]
public void JObjectEnumerator()
{
JObject o = new JObject(
View
33 Src/Newtonsoft.Json.Tests/Linq/JTokenTests.cs
@@ -949,5 +949,38 @@ public void ParseAdditionalContent()
JToken.Parse(json);
});
}
+
+ [Test]
+ public void Path()
+ {
+ JObject o =
+ new JObject(
+ new JProperty("Test1", new JArray(1, 2, 3)),
+ new JProperty("Test2", "Test2Value"),
+ new JProperty("Test3", new JObject(new JProperty("Test1", new JArray(1, new JObject(new JProperty("Test1", 1)), 3)))),
+ new JProperty("Test4", new JConstructor("Date", new JArray(1, 2, 3)))
+ );
+
+ JToken t = o.SelectToken("Test1[0]");
+ Assert.AreEqual("Test1[0]", t.Path);
+
+ t = o.SelectToken("Test2");
+ Assert.AreEqual("Test2", t.Path);
+
+ t = o.SelectToken("");
+ Assert.AreEqual("", t.Path);
+
+ t = o.SelectToken("Test4[0][0]");
+ Assert.AreEqual("Test4[0][0]", t.Path);
+
+ t = o.SelectToken("Test4[0]");
+ Assert.AreEqual("Test4[0]", t.Path);
+
+ t = t.DeepClone();
+ Assert.AreEqual("", t.Path);
+
+ t = o.SelectToken("Test3.Test1[1].Test1");
+ Assert.AreEqual("Test3.Test1[1].Test1", t.Path);
+ }
}
}
View
34 Src/Newtonsoft.Json.Tests/Linq/JValueTests.cs
@@ -25,6 +25,7 @@
using System;
using System.Collections.Generic;
+using System.IO;
using System.Text;
#if !NETFX_CORE
using NUnit.Framework;
@@ -362,6 +363,39 @@ public void SetDateTimeOffsetProperty()
var o = JObject.Parse(json);
o.Property("DateTimeOffset").Value = dateTimeOffset;
}
+
+ public void ParseAndConvertDateTimeOffset()
+ {
+ var json = @"{ d: ""\/Date(0+0100)\/"" }";
+
+ using (var stringReader = new StringReader(json))
+ using (var jsonReader = new JsonTextReader(stringReader))
+ {
+ jsonReader.DateParseHandling = DateParseHandling.DateTimeOffset;
+
+ var obj = JObject.Load(jsonReader);
+ var d = (JValue)obj["d"];
+
+ Assert.IsInstanceOfType(typeof(DateTimeOffset), d.Value);
+ TimeSpan offset = ((DateTimeOffset)d.Value).Offset;
+ Assert.AreEqual(TimeSpan.FromHours(1), offset);
+
+ DateTimeOffset dateTimeOffset = (DateTimeOffset) d;
+ Assert.AreEqual(TimeSpan.FromHours(1), dateTimeOffset.Offset);
+ }
+ }
+
+ public void ReadDatesAsDateTimeOffsetViaJsonConvert()
+ {
+ var content = @"{""startDateTime"":""2012-07-19T14:30:00+09:30""}";
+
+ var jsonSerializerSettings = new JsonSerializerSettings() { DateFormatHandling = DateFormatHandling.IsoDateFormat, DateParseHandling = DateParseHandling.DateTimeOffset, DateTimeZoneHandling = DateTimeZoneHandling.RoundtripKind };
+ JObject obj = (JObject)JsonConvert.DeserializeObject(content, jsonSerializerSettings);
+
+ object startDateTime = obj["startDateTime"];
+
+ Assert.IsInstanceOfType(typeof(DateTimeOffset), startDateTime);
+ }
#endif
}
}
View
19 Src/Newtonsoft.Json.Tests/Linq/LinqToJsonTest.cs
@@ -864,5 +864,24 @@ public void ParseWithPrecendingComments()
JArray a = JArray.Parse(json);
Assert.AreEqual("hi!", (string)a[0]);
}
+
+#if !(NET35 || NET20 || WINDOWS_PHONE || PORTABLE)
+ [Test]
+ public void ExceptionFromOverloadWithJValue()
+ {
+ dynamic name = new JValue("Matthew Doig");
+
+ IDictionary<string, string> users = new Dictionary<string, string>();
+
+ // unfortunatly there doesn't appear to be a way around this
+ ExceptionAssert.Throws<Microsoft.CSharp.RuntimeBinder.RuntimeBinderException>("The best overloaded method match for 'System.Collections.Generic.IDictionary<string,string>.Add(string, string)' has some invalid arguments",
+ () =>
+ {
+ users.Add("name2", name);
+
+ Assert.AreEqual(users["name2"], "Matthew Doig");
+ });
+ }
+#endif
}
}
View
67 Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.csproj
@@ -149,6 +149,7 @@
<Compile Include="Linq\DynamicTests.cs" />
<Compile Include="Linq\JPathTests.cs" />
<Compile Include="Linq\JRawTests.cs" />
+ <Compile Include="Schema\JsonSchemaSpecTests.cs" />
<Compile Include="Serialization\ConstructorHandlingTests.cs" />
<Compile Include="Serialization\ContractResolverTests.cs" />
<Compile Include="Serialization\DefaultValueHandlingTests.cs" />
@@ -309,6 +310,69 @@
<LastGenOutput>LinqToSqlClasses.designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</None>
+ <None Include="Schema\Specs\additionalItems.json">
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ </None>
+ <None Include="Schema\Specs\additionalProperties.json">
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ </None>
+ <None Include="Schema\Specs\dependencies.json">
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ </None>
+ <None Include="Schema\Specs\disallow.json">
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ </None>
+ <None Include="Schema\Specs\divisibleBy.json">
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ </None>
+ <None Include="Schema\Specs\enum.json">
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ </None>
+ <None Include="Schema\Specs\extends.json">
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ </None>
+ <None Include="Schema\Specs\items.json">
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ </None>
+ <None Include="Schema\Specs\maximum.json">
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ </None>
+ <None Include="Schema\Specs\maxItems.json">
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ </None>
+ <None Include="Schema\Specs\maxLength.json">
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ </None>
+ <None Include="Schema\Specs\minimum.json">
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ </None>
+ <None Include="Schema\Specs\minItems.json">
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ </None>
+ <None Include="Schema\Specs\minLength.json">
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ </None>
+ <None Include="Schema\Specs\pattern.json">
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ </None>
+ <None Include="Schema\Specs\patternProperties.json">
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ </None>
+ <None Include="Schema\Specs\properties.json">
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ </None>
+ <None Include="Schema\Specs\ref.json">
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ </None>
+ <None Include="Schema\Specs\required.json">
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ </None>
+ <None Include="Schema\Specs\type.json">
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ </None>
+ <None Include="Schema\Specs\uniqueItems.json">
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ </None>
</ItemGroup>
<ItemGroup>
<Service Include="{3259AA49-8AA1-44D3-9025-A0B520596A8C}" />
@@ -347,6 +411,9 @@
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
+ <ItemGroup>
+ <Folder Include="Schema\Specs\optional\" />
+ </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
View
2  Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs
@@ -76,5 +76,5 @@
// by using the '*' as shown below:
[assembly: AssemblyVersion("4.5.0.0")]
#if !PocketPC
-[assembly: AssemblyFileVersion("4.5.11.15520")]
+[assembly: AssemblyFileVersion("4.5.11.15631")]
#endif
View
156 Src/Newtonsoft.Json.Tests/Schema/ExtensionsTests.cs
@@ -300,14 +300,156 @@ public void ExclusiveMinimum_Float()
public void DivisibleBy_Int()
{
ExceptionAssert.Throws<JsonSchemaException>("Integer 10 is not evenly divisible by 3.",
- () =>
- {
- JsonSchema schema = new JsonSchema();
- schema.DivisibleBy = 3;
+ () =>
+ {
+ JsonSchema schema = new JsonSchema();
+ schema.DivisibleBy = 3;
+
+ JValue v = new JValue(10);
+ v.Validate(schema);
+ });
+ }
- JValue v = new JValue(10);
- v.Validate(schema);
- });
+ [Test]
+ public void UniqueItems_SimpleUnique()
+ {
+ JsonSchema schema = new JsonSchema();
+ schema.UniqueItems = true;
+
+ JArray a = new JArray(1, 2, 3);
+ Assert.IsTrue(a.IsValid(schema));
+ }
+
+ [Test]
+ public void UniqueItems_SimpleDuplicate()
+ {
+ JsonSchema schema = new JsonSchema();
+ schema.UniqueItems = true;
+
+ JArray a = new JArray(1, 2, 3, 2, 2);
+ IList<string> errorMessages;
+ Assert.IsFalse(a.IsValid(schema, out errorMessages));
+ Assert.AreEqual(2, errorMessages.Count);
+ Assert.AreEqual("Non-unique array item at index 3.", errorMessages[0]);
+ Assert.AreEqual("Non-unique array item at index 4.", errorMessages[1]);
+ }
+
+ [Test]
+ public void UniqueItems_ComplexDuplicate()
+ {
+ JsonSchema schema = new JsonSchema();
+ schema.UniqueItems = true;
+
+ JArray a = new JArray(1, new JObject(new JProperty("value", "value!")), 3, 2, new JObject(new JProperty("value", "value!")), 4, 2, new JObject(new JProperty("value", "value!")));
+ IList<string> errorMessages;
+ Assert.IsFalse(a.IsValid(schema, out errorMessages));
+ Assert.AreEqual(3, errorMessages.Count);
+ Assert.AreEqual("Non-unique array item at index 4.", errorMessages[0]);
+ Assert.AreEqual("Non-unique array item at index 6.", errorMessages[1]);
+ Assert.AreEqual("Non-unique array item at index 7.", errorMessages[2]);
+ }
+
+ [Test]
+ public void UniqueItems_NestedDuplicate()
+ {
+ JsonSchema schema = new JsonSchema();
+ schema.UniqueItems = true;
+ schema.Items = new List<JsonSchema>
+ {
+ new JsonSchema
+ {
+ UniqueItems = true
+ }
+ };
+ schema.PositionalItemsValidation = false;
+
+ JArray a = new JArray(
+ new JArray(1, 2),
+ new JArray(1, 1),
+ new JArray(3, 4),
+ new JArray(1, 2),
+ new JArray(1, 1)
+ );
+ IList<string> errorMessages;
+ Assert.IsFalse(a.IsValid(schema, out errorMessages));
+ Assert.AreEqual(4, errorMessages.Count);
+ Assert.AreEqual("Non-unique array item at index 1.", errorMessages[0]);
+ Assert.AreEqual("Non-unique array item at index 3.", errorMessages[1]);
+ Assert.AreEqual("Non-unique array item at index 1.", errorMessages[2]);
+ Assert.AreEqual("Non-unique array item at index 4.", errorMessages[3]);
+ }
+
+ [Test]
+ public void Enum_Properties()
+ {
+ JsonSchema schema = new JsonSchema();
+ schema.Properties = new Dictionary<string, JsonSchema>
+ {
+ {
+ "bar",
+ new JsonSchema
+ {
+ Enum = new List<JToken>
+ {
+ new JValue(1),
+ new JValue(2)
+ }
+ }
+ }
+ };
+
+ JObject o = new JObject(
+ new JProperty("bar", 1)
+ );
+ IList<string> errorMessages;
+ Assert.IsTrue(o.IsValid(schema, out errorMessages));
+ Assert.AreEqual(0, errorMessages.Count);
+
+ o = new JObject(
+ new JProperty("bar", 3)
+ );
+ Assert.IsFalse(o.IsValid(schema, out errorMessages));
+ Assert.AreEqual(1, errorMessages.Count);
+ }
+
+ [Test]
+ public void UniqueItems_Property()
+ {
+ JsonSchema schema = new JsonSchema();
+ schema.Properties = new Dictionary<string, JsonSchema>
+ {
+ {
+ "bar",
+ new JsonSchema
+ {
+ UniqueItems = true
+ }
+ }
+ };
+
+ JObject o = new JObject(
+ new JProperty("bar", new JArray(1, 2, 3, 3))
+ );
+ IList<string> errorMessages;
+ Assert.IsFalse(o.IsValid(schema, out errorMessages));
+ Assert.AreEqual(1, errorMessages.Count);
+ }
+
+ [Test]
+ public void Items_Positional()
+ {
+ JsonSchema schema = new JsonSchema();
+ schema.Items = new List<JsonSchema>
+ {
+ new JsonSchema { Type = JsonSchemaType.Object },
+ new JsonSchema { Type = JsonSchemaType.Integer }
+ };
+ schema.PositionalItemsValidation = true;
+
+ JArray a = new JArray(new JObject(), 1);
+ IList<string> errorMessages;
+ Assert.IsTrue(a.IsValid(schema, out errorMessages));
+ Assert.AreEqual(0, errorMessages.Count);
}
}
}
View
271 Src/Newtonsoft.Json.Tests/Schema/JsonSchemaBuilderTests.cs
@@ -59,7 +59,7 @@ public void Simple()
";
JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
- JsonSchema schema = builder.Parse(new JsonTextReader(new StringReader(json)));
+ JsonSchema schema = builder.Read(new JsonTextReader(new StringReader(json)));
Assert.AreEqual("A person", schema.Description);
Assert.AreEqual(JsonSchemaType.Object, schema.Type);
@@ -80,7 +80,7 @@ public void MultipleTypes()
}";
JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
- JsonSchema schema = builder.Parse(new JsonTextReader(new StringReader(json)));
+ JsonSchema schema = builder.Read(new JsonTextReader(new StringReader(json)));
Assert.AreEqual("Age", schema.Description);
Assert.AreEqual(JsonSchemaType.String | JsonSchemaType.Integer, schema.Type);
@@ -96,7 +96,7 @@ public void MultipleItems()
}";
JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
- JsonSchema schema = builder.Parse(new JsonTextReader(new StringReader(json)));
+ JsonSchema schema = builder.Read(new JsonTextReader(new StringReader(json)));
Assert.AreEqual("MultipleItems", schema.Description);
Assert.AreEqual(JsonSchemaType.String, schema.Items[0].Type);
@@ -113,7 +113,7 @@ public void AdditionalProperties()
}";
JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
- JsonSchema schema = builder.Parse(new JsonTextReader(new StringReader(json)));
+ JsonSchema schema = builder.Read(new JsonTextReader(new StringReader(json)));
Assert.AreEqual("AdditionalProperties", schema.Description);
Assert.AreEqual(JsonSchemaType.Object | JsonSchemaType.Boolean, schema.AdditionalProperties.Type);
@@ -128,7 +128,7 @@ public void Required()
}";
JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
- JsonSchema schema = builder.Parse(new JsonTextReader(new StringReader(json)));
+ JsonSchema schema = builder.Read(new JsonTextReader(new StringReader(json)));
Assert.AreEqual("Required", schema.Description);
Assert.AreEqual(true, schema.Required);
@@ -143,7 +143,7 @@ public void ExclusiveMinimum_ExclusiveMaximum()
}";
JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
- JsonSchema schema = builder.Parse(new JsonTextReader(new StringReader(json)));
+ JsonSchema schema = builder.Read(new JsonTextReader(new StringReader(json)));
Assert.AreEqual(true, schema.ExclusiveMinimum);
Assert.AreEqual(true, schema.ExclusiveMaximum);
@@ -158,7 +158,7 @@ public void ReadOnly()
}";
JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
- JsonSchema schema = builder.Parse(new JsonTextReader(new StringReader(json)));
+ JsonSchema schema = builder.Read(new JsonTextReader(new StringReader(json)));
Assert.AreEqual("ReadOnly", schema.Description);
Assert.AreEqual(true, schema.ReadOnly);
@@ -173,7 +173,7 @@ public void Hidden()
}";
JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
- JsonSchema schema = builder.Parse(new JsonTextReader(new StringReader(json)));
+ JsonSchema schema = builder.Read(new JsonTextReader(new StringReader(json)));
Assert.AreEqual("Hidden", schema.Description);
Assert.AreEqual(true, schema.Hidden);
@@ -188,7 +188,7 @@ public void Id()
}";
JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
- JsonSchema schema = builder.Parse(new JsonTextReader(new StringReader(json)));
+ JsonSchema schema = builder.Read(new JsonTextReader(new StringReader(json)));
Assert.AreEqual("Id", schema.Description);
Assert.AreEqual("testid", schema.Id);
@@ -203,7 +203,7 @@ public void Title()
}";
JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
- JsonSchema schema = builder.Parse(new JsonTextReader(new StringReader(json)));
+ JsonSchema schema = builder.Read(new JsonTextReader(new StringReader(json)));
Assert.AreEqual("Title", schema.Description);
Assert.AreEqual("testtitle", schema.Title);
@@ -218,7 +218,7 @@ public void Pattern()
}";
JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
- JsonSchema schema = builder.Parse(new JsonTextReader(new StringReader(json)));
+ JsonSchema schema = builder.Read(new JsonTextReader(new StringReader(json)));
Assert.AreEqual("Pattern", schema.Description);
Assert.AreEqual("testpattern", schema.Pattern);
@@ -233,7 +233,7 @@ public void Format()
}";
JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
- JsonSchema schema = builder.Parse(new JsonTextReader(new StringReader(json)));
+ JsonSchema schema = builder.Read(new JsonTextReader(new StringReader(json)));
Assert.AreEqual("Format", schema.Description);
Assert.AreEqual("testformat", schema.Format);
@@ -248,46 +248,13 @@ public void Requires()
}";
JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
- JsonSchema schema = builder.Parse(new JsonTextReader(new StringReader(json)));
+ JsonSchema schema = builder.Read(new JsonTextReader(new StringReader(json)));
Assert.AreEqual("Requires", schema.Description);
Assert.AreEqual("PurpleMonkeyDishwasher", schema.Requires);
}
[Test]
- public void IdentitySingle()
- {
- string json = @"{
- ""description"":""Identity"",
- ""identity"":""PurpleMonkeyDishwasher""
-}";
-
- JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
- JsonSchema schema = builder.Parse(new JsonTextReader(new StringReader(json)));
-
- Assert.AreEqual("Identity", schema.Description);
- Assert.AreEqual(1, schema.Identity.Count);
- Assert.AreEqual("PurpleMonkeyDishwasher", schema.Identity[0]);
- }
-
- [Test]
- public void IdentityMultiple()
- {
- string json = @"{
- ""description"":""Identity"",
- ""identity"":[""PurpleMonkeyDishwasher"",""Antelope""]
-}";
-
- JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
- JsonSchema schema = builder.Parse(new JsonTextReader(new StringReader(json)));
-
- Assert.AreEqual("Identity", schema.Description);
- Assert.AreEqual(2, schema.Identity.Count);
- Assert.AreEqual("PurpleMonkeyDishwasher", schema.Identity[0]);
- Assert.AreEqual("Antelope", schema.Identity[1]);
- }
-
- [Test]
public void MinimumMaximum()
{
string json = @"{
@@ -302,7 +269,7 @@ public void MinimumMaximum()
}";
JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
- JsonSchema schema = builder.Parse(new JsonTextReader(new StringReader(json)));
+ JsonSchema schema = builder.Read(new JsonTextReader(new StringReader(json)));
Assert.AreEqual("MinimumMaximum", schema.Description);
Assert.AreEqual(1.1, schema.Minimum);
@@ -323,7 +290,7 @@ public void DisallowSingleType()
}";
JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
- JsonSchema schema = builder.Parse(new JsonTextReader(new StringReader(json)));
+ JsonSchema schema = builder.Read(new JsonTextReader(new StringReader(json)));
Assert.AreEqual("DisallowSingleType", schema.Description);
Assert.AreEqual(JsonSchemaType.String, schema.Disallow);
@@ -338,7 +305,7 @@ public void DisallowMultipleTypes()
}";
JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
- JsonSchema schema = builder.Parse(new JsonTextReader(new StringReader(json)));
+ JsonSchema schema = builder.Read(new JsonTextReader(new StringReader(json)));
Assert.AreEqual("DisallowMultipleTypes", schema.Description);
Assert.AreEqual(JsonSchemaType.String | JsonSchemaType.Float, schema.Disallow);
@@ -353,10 +320,10 @@ public void DefaultPrimitiveType()
}";
JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
- JsonSchema schema = builder.Parse(new JsonTextReader(new StringReader(json)));
+ JsonSchema schema = builder.Read(new JsonTextReader(new StringReader(json)));
Assert.AreEqual("DefaultPrimitiveType", schema.Description);
- Assert.AreEqual(1.1, (double)schema.Default);
+ Assert.AreEqual(1.1, (double) schema.Default);
}
[Test]
@@ -368,37 +335,13 @@ public void DefaultComplexType()
}";
JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
- JsonSchema schema = builder.Parse(new JsonTextReader(new StringReader(json)));
+ JsonSchema schema = builder.Read(new JsonTextReader(new StringReader(json)));
Assert.AreEqual("DefaultComplexType", schema.Description);
Assert.IsTrue(JToken.DeepEquals(JObject.Parse(@"{""pie"":true}"), schema.Default));
}
[Test]
- public void Options()
- {
- string json = @"{
- ""description"":""NZ Island"",
- ""type"":""string"",
- ""options"":
- [
- {""value"":""NI"",""label"":""North Island""},
- {""value"":""SI"",""label"":""South Island""}
- ]
-}";
-
- JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
- JsonSchema schema = builder.Parse(new JsonTextReader(new StringReader(json)));
-
- Assert.AreEqual("NZ Island", schema.Description);
- Assert.AreEqual(JsonSchemaType.String, schema.Type);
-
- Assert.AreEqual(2, schema.Options.Count);
- Assert.AreEqual("North Island", schema.Options[new JValue("NI")]);
- Assert.AreEqual("South Island", schema.Options[new JValue("SI")]);
- }
-
- [Test]
public void Enum()
{
string json = @"{
@@ -408,14 +351,14 @@ public void Enum()
}";
JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
- JsonSchema schema = builder.Parse(new JsonTextReader(new StringReader(json)));
+ JsonSchema schema = builder.Read(new JsonTextReader(new StringReader(json)));
Assert.AreEqual("Type", schema.Description);
Assert.AreEqual(JsonSchemaType.String | JsonSchemaType.Array, schema.Type);
Assert.AreEqual(8, schema.Enum.Count);
- Assert.AreEqual("string", (string)schema.Enum[0]);
- Assert.AreEqual("any", (string)schema.Enum[schema.Enum.Count - 1]);
+ Assert.AreEqual("string", (string) schema.Enum[0]);
+ Assert.AreEqual("any", (string) schema.Enum[schema.Enum.Count - 1]);
}
[Test]
@@ -429,7 +372,7 @@ public void CircularReference()
}";
JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
- JsonSchema schema = builder.Parse(new JsonTextReader(new StringReader(json)));
+ JsonSchema schema = builder.Read(new JsonTextReader(new StringReader(json)));
Assert.AreEqual("CircularReference", schema.Description);
Assert.AreEqual("CircularReferenceArray", schema.Id);
@@ -441,19 +384,19 @@ public void CircularReference()
[Test]
public void UnresolvedReference()
{
- ExceptionAssert.Throws<Exception>(@"Could not resolve schema reference for Id 'MyUnresolvedReference'.",
- () =>
- {
- string json = @"{
+ ExceptionAssert.Throws<Exception>(@"Could not resolve schema reference 'MyUnresolvedReference'.",
+ () =>
+ {
+ string json = @"{
""id"":""CircularReferenceArray"",
""description"":""CircularReference"",
""type"":[""array""],
""items"":{""$ref"":""MyUnresolvedReference""}
}";
- JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
- JsonSchema schema = builder.Parse(new JsonTextReader(new StringReader(json)));
- });
+ JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
+ JsonSchema schema = builder.Read(new JsonTextReader(new StringReader(json)));
+ });
}
[Test]
@@ -466,11 +409,161 @@ public void PatternProperties()
}";
JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
- JsonSchema schema = builder.Parse(new JsonTextReader(new StringReader(json)));
+ JsonSchema schema = builder.Read(new JsonTextReader(new StringReader(json)));
Assert.IsNotNull(schema.PatternProperties);
Assert.AreEqual(1, schema.PatternProperties.Count);
Assert.AreEqual("Blah", schema.PatternProperties["[abc]"].Id);
}
+
+ [Test]
+ public void AdditionalItems()
+ {
+ string json = @"{
+ ""items"": [],
+ ""additionalItems"": {""type"": ""integer""}
+}";
+
+ JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
+ JsonSchema schema = builder.Read(new JsonTextReader(new StringReader(json)));
+
+ Assert.IsNotNull(schema.AdditionalItems);
+ Assert.AreEqual(JsonSchemaType.Integer, schema.AdditionalItems.Type);
+ Assert.AreEqual(true, schema.AllowAdditionalItems);
+ }
+
+ [Test]
+ public void DisallowAdditionalItems()
+ {
+ string json = @"{
+ ""items"": [],
+ ""additionalItems"": false
+}";
+
+ JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
+ JsonSchema schema = builder.Read(new JsonTextReader(new StringReader(json)));
+
+ Assert.IsNull(schema.AdditionalItems);
+ Assert.AreEqual(false, schema.AllowAdditionalItems);
+ }
+
+ [Test]
+ public void AllowAdditionalItems()
+ {
+ string json = @"{
+ ""items"": {},
+ ""additionalItems"": false
+}";
+
+ JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
+ JsonSchema schema = builder.Read(new JsonTextReader(new StringReader(json)));
+
+ Assert.IsNull(schema.AdditionalItems);
+ Assert.AreEqual(false, schema.AllowAdditionalItems);
+ }
+
+ [Test]
+ public void Location()
+ {
+ string json = @"{
+ ""properties"":{
+ ""foo"":{
+ ""type"":""array"",
+ ""items"":[
+ {
+ ""type"":""integer""
+ },
+ {
+ ""properties"":{
+ ""foo"":{
+ ""type"":""integer""
+ }
+ }
+ }
+ ]
+ }
}
-}
+}";
+
+ JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
+ JsonSchema schema = builder.Read(new JsonTextReader(new StringReader(json)));
+
+ Assert.AreEqual("#", schema.Location);
+ Assert.AreEqual("#/properties/foo", schema.Properties["foo"].Location);
+ Assert.AreEqual("#/properties/foo/items/1/properties/foo", schema.Properties["foo"].Items[1].Properties["foo"].Location);
+ }
+
+ [Test]
+ public void Reference_BackwardsLocation()
+ {
+ string json = @"{
+ ""properties"": {
+ ""foo"": {""type"": ""integer""},
+ ""bar"": {""$ref"": ""#/properties/foo""}
+ }
+}";
+
+ JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
+ JsonSchema schema = builder.Read(new JsonTextReader(new StringReader(json)));
+
+ Assert.AreEqual(schema.Properties["foo"], schema.Properties["bar"]);
+ }
+
+ [Test]
+ public void Reference_ForwardsLocation()
+ {
+ string json = @"{
+ ""properties"": {
+ ""bar"": {""$ref"": ""#/properties/foo""},
+ ""foo"": {""type"": ""integer""}
+ }
+}";
+
+ JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
+ JsonSchema schema = builder.Read(new JsonTextReader(new StringReader(json)));
+
+ Assert.AreEqual(schema.Properties["foo"], schema.Properties["bar"]);
+ }
+
+ [Test]
+ public void Reference_NonStandardLocation()
+ {
+ string json = @"{
+ ""properties"": {
+ ""bar"": {""$ref"": ""#/common/foo""},
+ ""foo"": {""$ref"": ""#/common/foo""}
+ },
+ ""common"": {
+ ""foo"": {""type"": ""integer""}
+ }
+}";
+
+ JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
+ JsonSchema schema = builder.Read(new JsonTextReader(new StringReader(json)));
+
+ Assert.AreEqual(schema.Properties["foo"], schema.Properties["bar"]);
+ }
+
+ [Test]
+ public void EscapedReferences()
+ {
+ string json = @"{
+ ""tilda~field"": {""type"": ""integer""},
+ ""slash/field"": {""type"": ""object""},
+ ""percent%field"": {""type"": ""array""},
+ ""properties"": {
+ ""tilda"": {""$ref"": ""#/tilda~0field""},
+ ""slash"": {""$ref"": ""#/slash~1field""},
+ ""percent"": {""$ref"": ""#/percent%25field""}
+ }
+ }";
+
+ JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
+ JsonSchema schema = builder.Read(new JsonTextReader(new StringReader(json)));
+
+ Assert.AreEqual(JsonSchemaType.Integer, schema.Properties["tilda"].Type);
+ Assert.AreEqual(JsonSchemaType.Object, schema.Properties["slash"].Type);
+ Assert.AreEqual(JsonSchemaType.Array, schema.Properties["percent"].Type);
+ }
+ }
+}
View
14 Src/Newtonsoft.Json.Tests/Schema/JsonSchemaGeneratorTests.cs
@@ -619,20 +619,6 @@ public void GenerateSchemaWithNegativeEnum()
0,
1,
-1
- ],
- ""options"": [
- {
- ""value"": 0,
- ""label"": ""No""
- },
- {
- ""value"": 1,
- ""label"": ""Asc""
- },
- {
- ""value"": -1,
- ""label"": ""Desc""
- }
]
}
}
View
124 Src/Newtonsoft.Json.Tests/Schema/JsonSchemaTests.cs
@@ -25,6 +25,7 @@
using System.Collections.Generic;
using System.IO;
+using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Schema;
#if !NETFX_CORE
using NUnit.Framework;
@@ -62,7 +63,7 @@ public void Extends()
}";
JsonSchema second = JsonSchema.Parse(json, resolver);
- Assert.AreEqual(first, second.Extends);
+ Assert.AreEqual(first, second.Extends[0]);
json =
@"{
@@ -73,8 +74,8 @@ public void Extends()
}";
JsonSchema third = JsonSchema.Parse(json, resolver);
- Assert.AreEqual(second, third.Extends);
- Assert.AreEqual(first, third.Extends.Extends);
+ Assert.AreEqual(second, third.Extends[0]);
+ Assert.AreEqual(first, third.Extends[0].Extends[0]);
StringWriter writer = new StringWriter();
JsonTextWriter jsonWriter = new JsonTextWriter(writer);
@@ -347,43 +348,6 @@ public void WriteTo_MultipleItems()
}
[Test]
- public void ReadOptions()
- {
- JsonSchema schema = JsonSchema.Parse(@"{
- ""type"": ""object"",
- ""properties"": {
- ""x"": {
- ""type"": ""integer"",
- ""enum"": [
- 0,
- 1,
- -1
- ],
- ""options"": [
- {
- ""value"": 0,
- ""label"": ""No""
- },
- {
- ""value"": 1,
- ""label"": ""Asc""
- },
- {
- ""value"": -1,
- ""label"": ""Desc""
- }
- ]
- }
- }
-}");
-
- Assert.AreEqual(schema.Properties["x"].Options.Count, 3);
- Assert.AreEqual(schema.Properties["x"].Options[0], "No");
- Assert.AreEqual(schema.Properties["x"].Options[1], "Asc");
- Assert.AreEqual(schema.Properties["x"].Options[-1], "Desc");
- }
-
- [Test]
public void WriteTo_ExclusiveMinimum_ExclusiveMaximum()
{
JsonSchema schema = new JsonSchema();
@@ -427,5 +391,85 @@ public void WriteTo_PatternProperties()
}
}", json);
}
+
+ [Test]
+ public void ToString_AdditionalItems()
+ {
+ JsonSchema schema = JsonSchema.Parse(@"{
+ ""additionalItems"": {""type"": ""integer""}
+}");
+
+ string json = schema.ToString();
+
+ Assert.AreEqual(@"{
+ ""additionalItems"": {
+ ""type"": ""integer""
+ }
+}", json);
+ }
+
+ [Test]
+ public void WriteTo_PositionalItemsValidation_True()
+ {
+ JsonSchema schema = new JsonSchema();
+ schema.PositionalItemsValidation = true;
+
+ StringWriter writer = new StringWriter();
+ JsonTextWriter jsonWriter = new JsonTextWriter(writer);
+ jsonWriter.Formatting = Formatting.Indented;
+
+ schema.WriteTo(jsonWriter);
+
+ string json = writer.ToString();
+
+ Assert.AreEqual(@"{
+ ""items"": []
+}", json);
+ }
+
+ [Test]
+ public void WriteTo_PositionalItemsValidation_TrueWithItemsSchema()
+ {
+ JsonSchema schema = new JsonSchema();
+ schema.PositionalItemsValidation = true;
+ schema.Items = new List<JsonSchema> { new JsonSchema { Type = JsonSchemaType.String }};
+
+ StringWriter writer = new StringWriter();
+ JsonTextWriter jsonWriter = new JsonTextWriter(writer);
+ jsonWriter.Formatting = Formatting.Indented;
+
+ schema.WriteTo(jsonWriter);
+
+ string json = writer.ToString();
+
+ Assert.AreEqual(@"{
+ ""items"": [
+ {
+ ""type"": ""string""
+ }
+ ]
+}", json);
+ }
+
+ [Test]
+ public void WriteTo_PositionalItemsValidation_FalseWithItemsSchema()
+ {
+ JsonSchema schema = new JsonSchema();
+ schema.Items = new List<JsonSchema> { new JsonSchema { Type = JsonSchemaType.String } };
+
+ StringWriter writer = new StringWriter();
+ JsonTextWriter jsonWriter = new JsonTextWriter(writer);
+ jsonWriter.Formatting = Formatting.Indented;
+
+ schema.WriteTo(jsonWriter);
+
+ string json = writer.ToString();
+
+ Assert.AreEqual(@"{
+ ""items"": {
+ ""type"": ""string""
+ }
+}", json);
+ }
}
}
View
82 Src/Newtonsoft.Json.Tests/Schema/Specs/additionalItems.json
@@ -0,0 +1,82 @@
+[
+ {
+ "description": "additionalItems as schema",
+ "schema": {
+ "items": [],
+ "additionalItems": {"type": "integer"}
+ },
+ "tests": [
+ {
+ "description": "additional items match schema",
+ "data": [ 1, 2, 3, 4 ],
+ "valid": true
+ },
+ {
+ "description": "additional items do not match schema",
+ "data": [ 1, 2, 3, "foo" ],
+ "valid": false
+ }
+ ]
+ },
+ {
+ "description": "items is schema, no additionalItems",
+ "schema": {
+ "items": {},
+ "additionalItems": false
+ },
+ "tests": [
+ {
+ "description": "all items match schema",
+ "data": [ 1, 2, 3, 4, 5 ],
+ "valid": true
+ }
+ ]
+ },
+ {
+ "description": "array of items with no additionalItems",
+ "schema": {
+ "items": [{}, {}, {}],
+ "additionalItems": false
+ },
+ "tests": [
+ {
+ "description": "no additional items present",
+ "data": [ 1, 2, 3 ],
+ "valid": true
+ },
+ {
+ "description": "additional items are not permitted",
+ "data": [ 1, 2, 3, 4 ],
+ "valid": false
+ }
+ ]
+ },
+ {
+ "description": "additionalItems as false without items",
+ "schema": {"additionalItems": false},
+ "tests": [
+ {
+ "description":
+ "items defaults to empty schema so everything is valid",
+ "data": [ 1, 2, 3, 4, 5 ],
+ "valid": true
+ },
+ {
+ "description": "ignores non-arrays",
+ "data": {"foo" : "bar"},
+ "valid": true
+ }
+ ]
+ },
+ {
+ "description": "additionalItems are allowed by default",
+ "schema": {"items": []},
+ "tests": [
+ {
+ "description": "only the first items are validated",
+ "data": [1, "foo", false],
+ "valid": true
+ }
+ ]
+ }
+]
View
63 Src/Newtonsoft.Json.Tests/Schema/Specs/additionalProperties.json
@@ -0,0 +1,63 @@
+[
+ {
+ "description":
+ "additionalProperties being false does not allow other properties",
+ "schema": {
+ "properties": {"foo": {}, "bar": {}},
+ "additionalProperties": false
+ },
+ "tests": [
+ {
+ "description": "no additional properties is valid",
+ "data": {"foo": 1},
+ "valid": true
+ },
+ {
+ "description": "an additional property is invalid",
+ "data": {"foo" : 1, "bar" : 2, "quux" : "boom"},
+ "valid": false
+ },
+ {
+ "description": "ignores non-objects",
+ "data": [1, 2, 3],
+ "valid": true
+ }
+ ]
+ },
+ {
+ "description":
+ "additionalProperties allows a schema which should validate",
+ "schema": {
+ "properties": {"foo": {}, "bar": {}},
+ "additionalProperties": {"type": "boolean"}
+ },
+ "tests": [
+ {
+ "description": "no additional properties is valid",
+ "data": {"foo": 1},
+ "valid": true
+ },
+ {
+ "description": "an additional valid property is valid",
+ "data": {"foo" : 1, "bar" : 2, "quux" : true},
+ "valid": true
+ },
+ {
+ "description": "an additional invalid property is invalid",
+ "data": {"foo" : 1, "bar" : 2, "quux" : 12},
+ "valid": false
+ }
+ ]
+ },
+ {
+ "description": "additionalProperties are allowed by default",
+ "schema": {"properties": {"foo": {}, "bar": {}}},
+ "tests": [
+ {
+ "description": "additional properties are allowed",
+ "data": {"foo": 1, "bar": 2, "quux": true},
+ "valid": true
+ }
+ ]
+ }
+]
View
108 Src/Newtonsoft.Json.Tests/Schema/Specs/dependencies.json
@@ -0,0 +1,108 @@
+[
+ {
+ "description": "dependencies",
+ "schema": {
+ "dependencies": {"bar": "foo"}
+ },
+ "tests": [
+ {
+ "description": "neither",
+ "data": {},
+ "valid": true
+ },
+ {
+ "description": "nondependant",
+ "data": {"foo": 1},
+ "valid": true
+ },
+ {
+ "description": "with dependency",
+ "data": {"foo": 1, "bar": 2},
+ "valid": true
+ },
+ {
+ "description": "missing dependency",
+ "data": {"bar": 2},
+ "valid": false
+ },
+ {
+ "description": "ignores non-objects",
+ "data": "foo",
+ "valid": true
+ }
+ ]
+ },
+ {
+ "description": "multiple dependencies",
+ "schema": {
+ "dependencies": {"quux": ["foo", "bar"]}
+ },
+ "tests": [
+ {
+ "description": "neither",
+ "data": {},
+ "valid": true
+ },
+ {
+ "description": "nondependants",
+ "data": {"foo": 1, "bar": 2},
+ "valid": true
+ },
+ {
+ "description": "with dependencies",
+ "data": {"foo": 1, "bar": 2, "quux": 3},
+ "valid": true
+ },
+ {
+ "description": "missing dependency",
+ "data": {"foo": 1, "quux": 2},
+ "valid": false
+ },
+ {
+ "description": "missing other dependency",
+ "data": {"bar": 1, "quux": 2},
+ "valid": false
+ },
+ {
+ "description": "missing both dependencies",
+ "data": {"quux": 1},
+ "valid": false
+ }
+ ]
+ },
+ {
+ "description": "multiple dependencies subschema",
+ "schema": {
+ "dependencies": {
+ "bar": {
+ "properties": {
+ "foo": {"type": "integer"},
+ "bar": {"type": "integer"}
+ }
+ }
+ }
+ },
+ "tests": [
+ {
+ "description": "valid",
+ "data": {"foo": 1, "bar": 2},
+ "valid": true
+ },
+ {
+ "description": "wrong type",
+ "data": {"foo": "quux", "bar": 2},
+ "valid": false
+ },
+ {
+ "description": "wrong type other",
+ "data": {"foo": 2, "bar": "quux"},
+ "valid": false
+ },
+ {
+ "description": "wrong type both",
+ "data": {"foo": "quux", "bar": "quux"},
+ "valid": false
+ }
+ ]
+ }
+]
View
80 Src/Newtonsoft.Json.Tests/Schema/Specs/disallow.json
@@ -0,0 +1,80 @@
+[
+ {
+ "description": "disallow",
+ "schema": {
+ "disallow": "integer"
+ },
+ "tests": [
+ {
+ "description": "allowed",
+ "data": "foo",
+ "valid": true
+ },
+ {
+ "description": "disallowed",
+ "data": 1,
+ "valid": false
+ }
+ ]
+ },
+ {
+ "description": "multiple disallow",
+ "schema": {
+ "disallow": ["integer", "boolean"]
+ },
+ "tests": [
+ {
+ "description": "valid",
+ "data": "foo",
+ "valid": true
+ },
+ {
+ "description": "mismatch",
+ "data": 1,
+ "valid": false
+ },
+ {
+ "description": "other mismatch",
+ "data": true,
+ "valid": false
+ }
+ ]
+ },
+ {
+ "description": "multiple disallow subschema",
+ "schema": {
+ "disallow":
+ ["string",
+ {
+ "type": "object",
+ "properties": {
+ "foo": {
+ "type": "string"
+ }
+ }
+ }]
+ },
+ "tests": [
+ {
+ "description": "match",
+ "data": 1,
+ "valid": true
+ },
+ {
+ "description": "other match",
+ "data": {"foo": 1},
+ "valid": true
+ },
+ {
+ "description": "mismatch",
+ "data": "foo",
+ "valid": false
+ },
+ {
+ "description": "other mismatch",
+ "data": {"foo": "bar"},
+ "valid": false
+ }
+ ]
+ }
+]
View
60 Src/Newtonsoft.Json.Tests/Schema/Specs/divisibleBy.json
@@ -0,0 +1,60 @@
+[
+ {
+ "description": "by int",
+ "schema": {"divisibleBy": 2},
+ "tests": [
+ {
+ "description": "int by int",
+ "data": 10,
+ "valid": true
+ },
+ {
+ "description": "int by int fail",
+ "data": 7,
+ "valid": false
+ },
+ {
+ "description": "ignores non-numbers",
+ "data": "foo",
+ "valid": true
+ }
+ ]
+ },
+ {
+ "description": "by number",
+ "schema": {"divisibleBy": 1.5},
+ "tests": [
+ {
+ "description": "zero is divisible by anything (except 0)",
+ "data": 0,
+ "valid": true
+ },
+ {
+ "description": "4.5 is divisible by 1.5",
+ "data": 4.5,
+ "valid": true
+ },
+ {
+ "description": "35 is not divisible by 1.5",
+ "data": 35,
+ "valid": false
+ }
+ ]
+ },
+ {
+ "description": "by small number",
+ "schema": {"divisibleBy": 0.0001},
+ "tests": [
+ {
+ "description": "0.0075 is divisible by 0.0001",
+ "data": 0.0075,
+ "valid": true
+ },
+ {
+ "description": "0.00751 is not divisible by 0.0001",
+ "data": 0.00751,
+ "valid": false
+ }
+ ]
+ }
+]
View
39 Src/Newtonsoft.Json.Tests/Schema/Specs/enum.json
@@ -0,0 +1,39 @@
+[
+ {
+ "description": "simple enum validation",
+ "schema": {"enum": [1, 2, 3]},
+ "tests": [
+ {
+ "description": "one of the enum is valid",
+ "data": 1,
+ "valid": true
+ },
+ {
+ "description": "something else is invalid",
+ "data": 4,
+ "valid": false
+ }
+ ]
+ },
+ {
+ "description": "heterogeneous enum validation",
+ "schema": {"enum": [6, "foo", [], true, {"foo": 12}]},
+ "tests": [
+ {
+ "description": "one of the enum is valid",
+ "data": [],
+ "valid": true
+ },
+ {
+ "description": "something else is invalid",
+ "data": null,
+ "valid": false
+ },
+ {
+ "description": "objects are deep compared",
+ "data": {"foo": false},
+ "valid": false
+ }
+ ]
+ }
+]
View
94 Src/Newtonsoft.Json.Tests/Schema/Specs/extends.json
@@ -0,0 +1,94 @@
+[
+ {
+ "description": "extends",
+ "schema": {
+ "properties": {"bar": {"type": "integer", "required": true}},
+ "extends": {
+ "properties": {
+ "foo": {"type": "string", "required": true}
+ }
+ }
+ },
+ "tests": [
+ {
+ "description": "extends",
+ "data": {"foo": "baz", "bar": 2},
+ "valid": true
+ },
+ {
+ "description": "mismatch extends",
+ "data": {"foo": "baz"},
+ "valid": false
+ },
+ {
+ "description": "mismatch extended",
+ "data": {"bar": 2},
+ "valid": false
+ },
+ {
+ "description": "wrong type",
+ "data": {"foo": "baz", "bar": "quux"},
+ "valid": false
+ }
+ ]
+ },
+ {
+ "description": "multiple extends",
+ "schema": {
+ "properties": {"bar": {"type": "integer", "required": true}},
+ "extends" : [
+ {
+ "properties": {
+ "foo": {"type": "string", "required": true}
+ }
+ },
+ {
+ "properties": {
+ "baz": {"type": "null", "required": true}
+ }
+ }
+ ]
+ },
+ "tests": [
+ {
+ "description": "valid",
+ "data": {"foo": "quux", "bar": 2, "baz": null},
+ "valid": true
+ },
+ {
+ "description": "mismatch first extends",
+ "data": {"bar": 2, "baz": null},
+ "valid": false
+ },
+ {
+ "description": "mismatch second extends",
+ "data": {"foo": "quux", "bar": 2},
+ "valid": false
+ },
+ {
+ "description": "mismatch both",
+ "data": {"bar": 2},
+ "valid": false
+ }
+ ]
+ },
+ {
+ "description": "extends simple types",
+ "schema": {
+ "minimum": 20,
+ "extends": {"maximum": 30}
+ },
+ "tests": [
+ {
+ "description": "valid",
+ "data": 25,
+ "valid": true
+ },
+ {
+ "description": "mismatch extends",
+ "data": 35,
+ "valid": false
+ }
+ ]
+ }
+]
View
46 Src/Newtonsoft.Json.Tests/Schema/Specs/items.json
@@ -0,0 +1,46 @@
+[
+ {
+ "description": "a schema given for items",
+ "schema": {
+ "items": {"type": "integer"}
+ },
+ "tests": [
+ {
+ "description": "valid items",
+ "data": [ 1, 2, 3 ],
+ "valid": true
+ },
+ {
+ "description": "wrong type of items",
+ "data": [1, "x"],
+ "valid": false
+ },
+ {
+ "description": "ignores non-arrays",
+ "data": {"foo" : "bar"},
+ "valid": true
+ }
+ ]
+ },
+ {
+ "description": "an array of schemas for items",
+ "schema": {
+ "items": [
+ {"type": "integer"},
+ {"type": "string"}
+ ]
+ },
+ "tests": [
+ {
+ "description": "correct types",
+ "data": [ 1, "foo" ],
+ "valid": true
+ },
+ {
+ "description": "wrong types",
+ "data": [ "foo", 1 ],
+ "valid": false
+ }
+ ]
+ }
+]
View
28 Src/Newtonsoft.Json.Tests/Schema/Specs/maxItems.json
@@ -0,0 +1,28 @@
+[
+ {
+ "description": "maxItems validation",
+ "schema": {"maxItems": 2},
+ "tests": [
+ {
+ "description": "shorter is valid",
+ "data": [1],
+ "valid": true
+ },
+ {
+ "description": "exact length is valid",
+ "data": [1, 2],
+ "valid": true
+ },
+ {
+ "description": "too long is invalid",
+ "data": [1, 2, 3],
+ "valid": false
+ },
+ {
+ "description": "ignores non-arrays",
+ "data": "foobar",
+ "valid": true
+ }
+ ]
+ }
+]
View
28 Src/Newtonsoft.Json.Tests/Schema/Specs/maxLength.json
@@ -0,0 +1,28 @@
+[
+ {
+ "description": "maxLength validation",
+ "schema": {"maxLength": 2},
+ "tests": [
+ {
+ "description": "shorter is valid",
+ "data": "f",
+ "valid": true
+ },
+ {
+ "description": "exact length is valid",
+ "data": "fo",
+ "valid": true
+ },
+ {
+ "description": "too long is invalid",
+ "data": "foo",
+ "valid": false
+ },
+ {
+ "description": "ignores non-strings",
+ "data": 10,
+ "valid": true
+ }
+ ]
+ }
+]
View
42 Src/Newtonsoft.Json.Tests/Schema/Specs/maximum.json
@@ -0,0 +1,42 @@
+[
+ {
+ "description": "maximum validation",
+ "schema": {"maximum": 3.0},
+ "tests": [
+ {
+ "description": "below the maximum is valid",
+ "data": 2.6,
+ "valid": true
+ },
+ {
+ "description": "above the maximum is invalid",
+ "data": 3.5,
+ "valid": false
+ },
+ {
+ "description": "ignores non-numbers",
+ "data": "x",
+ "valid": true
+ }
+ ]
+ },
+ {
+ "description": "exclusiveMaximum validation",
+ "schema": {
+ "maximum": 3.0,
+ "exclusiveMaximum": true
+ },
+ "tests": [
+ {
+ "description": "below the maximum is still valid",
+ "data": 2.2,
+ "valid": true
+ },
+ {
+ "description": "boundary point is invalid",
+ "data": 3.0,
+ "valid": false
+ }
+ ]
+ }
+]
View
28 Src/Newtonsoft.Json.Tests/Schema/Specs/minItems.json
@@ -0,0 +1,28 @@
+[
+ {
+ "description": "minItems validation",
+ "schema": {"minItems": 1},
+ "tests": [
+ {
+ "description": "longer is valid",
+ "data": [1, 2],
+ "valid": true
+ },
+ {
+ "description": "exact length is valid",
+ "data": [1],
+ "valid": true
+ },
+ {
+ "description": "too short is invalid",
+ "data": [],
+ "valid": false
+ },
+ {
+ "description": "ignores non-arrays",
+ "data": "",
+ "valid": true
+ }
+ ]
+ }
+]
View
28 Src/Newtonsoft.Json.Tests/Schema/Specs/minLength.json
@@ -0,0 +1,28 @@
+[
+ {
+ "description": "minLength validation",
+ "schema": {"minLength": 2},
+ "tests": [
+ {
+ "description": "longer is valid",
+ "data": "foo",
+ "valid": true
+ },
+ {
+ "description": "exact length is valid",
+ "data": "fo",
+ "valid": true
+ },
+ {
+ "description": "too short is invalid",
+ "data": "f",
+ "valid": false
+ },
+ {
+ "description": "ignores non-strings",
+ "data": 1,
+ "valid": true
+ }
+ ]
+ }
+]
View
42 Src/Newtonsoft.Json.Tests/Schema/Specs/minimum.json
@@ -0,0 +1,42 @@
+[
+ {
+ "description": "minimum validation",
+ "schema": {"minimum": 1.1},
+ "tests": [