Skip to content

Commit

Permalink
Merge pull request #572 from gregsdennis/schema/date-time-format-corr…
Browse files Browse the repository at this point in the history
…ection

Schema/date time format correction
  • Loading branch information
gregsdennis committed Dec 2, 2023
2 parents 2b7ed0a + 8a3720f commit f6d7bc2
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
13 changes: 13 additions & 0 deletions JsonSchema.Tests/FormatTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ public void DateTime_Pass(string dateString)
Assert.True(result.IsValid);
}

[Test]
public void DateTime_MissingTimeOffset_Fail()
{
JsonSchema schema = new JsonSchemaBuilder()
.Format(Formats.DateTime);

var value = JsonNode.Parse("\"2023-04-28T21:51:26\"");

var result = schema.Evaluate(value, new EvaluationOptions { RequireFormatValidation = true });

result.AssertInvalid();
}

private static readonly Uri _formatAssertionMetaSchemaId = new("https://json-everything/test/format-assertion");
private static readonly JsonSchema _formatAssertionMetaSchema =
new JsonSchemaBuilder()
Expand Down
2 changes: 1 addition & 1 deletion JsonSchema/Formats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ private static bool CheckDateFormat(JsonNode? node, params string[] formats)
//We use a fallback to catch these cases

//from built from https://regex101.com/r/qH0sU7/1, edited to support all date+time examples in https://ijmacd.github.io/rfc3339-iso8601/
var regex = new Regex(@"^((?:(\d{4}-\d{2}-\d{2})([Tt_]| )(\d{2}:\d{2}:\d{2}(?:\.\d+)?))([Zz]|[\+-]\d{2}:\d{2})?)$");
var regex = new Regex(@"^((?:(\d{4}-\d{2}-\d{2})([Tt_]| )(\d{2}:\d{2}:\d{2}(?:\.\d+)?))([Zz]|[\+-]\d{2}:\d{2}))$");
var match = regex.Match(dateString);
return match.Success;

Expand Down
4 changes: 2 additions & 2 deletions JsonSchema/JsonSchema.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,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>5.4.0</Version>
<FileVersion>5.4.0.0</FileVersion>
<Version>5.4.1</Version>
<FileVersion>5.4.1.0</FileVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<AssemblyName>JsonSchema.Net</AssemblyName>
Expand Down
4 changes: 4 additions & 0 deletions tools/ApiDocsGenerator/release-notes/rn-json-schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ title: JsonSchema.Net
icon: fas fa-tag
order: "08.01"
---
# [5.4.1](https://github.com/gregsdennis/json-everything/pull/572) {#release-pointer-5.4.1}

[#570](https://github.com/gregsdennis/json-everything/issues/570) - RFC 3339 date/times require the time zone offset. Thanks to [@danielstarck](https://github.com/danielstarck) for identifying and fixing this issue.

# [5.4.0](https://github.com/gregsdennis/json-everything/pull/565) {#release-pointer-5.4.0}

[#549](https://github.com/gregsdennis/json-everything/issues/549) - Expose JSON converters for all types to support JSON source generation.
Expand Down

0 comments on commit f6d7bc2

Please sign in to comment.