diff --git a/src/NJsonSchema.CodeGeneration.CSharp/CSharpPropertyNameGenerator.cs b/src/NJsonSchema.CodeGeneration.CSharp/CSharpPropertyNameGenerator.cs index 354a94880..b1c50a40d 100644 --- a/src/NJsonSchema.CodeGeneration.CSharp/CSharpPropertyNameGenerator.cs +++ b/src/NJsonSchema.CodeGeneration.CSharp/CSharpPropertyNameGenerator.cs @@ -19,6 +19,7 @@ public virtual string Generate(JsonProperty property) return ConversionUtilities.ConvertToUpperCamelCase(property.Name .Replace("\"", string.Empty) .Replace("@", string.Empty) + .Replace("$", string.Empty) .Replace(".", "-") .Replace("=", "-") .Replace("+", "plus"), true) diff --git a/src/NJsonSchema.CodeGeneration.CSharp/NJsonSchema.CodeGeneration.CSharp.csproj b/src/NJsonSchema.CodeGeneration.CSharp/NJsonSchema.CodeGeneration.CSharp.csproj index 0a9d3cb8c..b8d06b67d 100644 --- a/src/NJsonSchema.CodeGeneration.CSharp/NJsonSchema.CodeGeneration.CSharp.csproj +++ b/src/NJsonSchema.CodeGeneration.CSharp/NJsonSchema.CodeGeneration.CSharp.csproj @@ -2,7 +2,7 @@ netstandard1.3;netstandard2.0;net451 JSON Schema reader, generator and validator for .NET - 9.13.18 + 9.13.19 json schema validation generator .net Copyright © Rico Suter, 2018 https://github.com/rsuter/NJsonSchema/blob/master/LICENSE.md diff --git a/src/NJsonSchema.CodeGeneration.TypeScript/NJsonSchema.CodeGeneration.TypeScript.csproj b/src/NJsonSchema.CodeGeneration.TypeScript/NJsonSchema.CodeGeneration.TypeScript.csproj index f56b0b522..98c0c7a9f 100644 --- a/src/NJsonSchema.CodeGeneration.TypeScript/NJsonSchema.CodeGeneration.TypeScript.csproj +++ b/src/NJsonSchema.CodeGeneration.TypeScript/NJsonSchema.CodeGeneration.TypeScript.csproj @@ -2,7 +2,7 @@ netstandard1.3;netstandard2.0;net451 JSON Schema reader, generator and validator for .NET - 9.13.18 + 9.13.19 json schema validation generator .net Copyright © Rico Suter, 2018 https://github.com/rsuter/NJsonSchema/blob/master/LICENSE.md diff --git a/src/NJsonSchema.CodeGeneration/NJsonSchema.CodeGeneration.csproj b/src/NJsonSchema.CodeGeneration/NJsonSchema.CodeGeneration.csproj index b240db058..5e1cff433 100644 --- a/src/NJsonSchema.CodeGeneration/NJsonSchema.CodeGeneration.csproj +++ b/src/NJsonSchema.CodeGeneration/NJsonSchema.CodeGeneration.csproj @@ -2,7 +2,7 @@ netstandard1.3;netstandard2.0;net451 JSON Schema reader, generator and validator for .NET - 9.13.18 + 9.13.19 json schema validation generator .net Copyright © Rico Suter, 2018 https://github.com/rsuter/NJsonSchema/blob/master/LICENSE.md diff --git a/src/NJsonSchema.Tests/Validation/SchemaTests.cs b/src/NJsonSchema.Tests/Validation/SchemaTests.cs index d16e59279..cc2b3227d 100644 --- a/src/NJsonSchema.Tests/Validation/SchemaTests.cs +++ b/src/NJsonSchema.Tests/Validation/SchemaTests.cs @@ -379,5 +379,37 @@ public async Task When_multiple_types_fail_with_errors_take_the_best_group() Assert.Equal(1, errors.Count); Assert.Contains(errors, e => e.Kind == ValidationErrorKind.NoTypeValidates); } + + [Fact] + public async Task When_datetime_with_regex_validation_then_datetime_is_not_altered() + { + //// Arrange + var schemaJson = @" + { + ""$schema"": ""http://json-schema.org/draft-07/schema#"", + ""type"": ""object"", + ""required"": [ + ""my_datetime"" + ], + ""properties"": { + ""my_datetime"": { + ""type"": ""string"", + ""pattern"": ""^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{3}Z$"" + } + } + }"; + + var json = @" + { + ""my_datetime"": ""2018-12-19T16:58:07.270Z"" + }"; + + //// Act + var schema = await JsonSchema4.FromJsonAsync(schemaJson); + var errors = schema.Validate(json); + + //// Assert + Assert.Equal(0, errors.Count); + } } } diff --git a/src/NJsonSchema.Yaml/NJsonSchema.Yaml.csproj b/src/NJsonSchema.Yaml/NJsonSchema.Yaml.csproj index 8591a05cc..561941bb1 100644 --- a/src/NJsonSchema.Yaml/NJsonSchema.Yaml.csproj +++ b/src/NJsonSchema.Yaml/NJsonSchema.Yaml.csproj @@ -2,7 +2,7 @@ netstandard1.3;netstandard2.0;net45 JSON Schema reader, generator and validator for .NET - 9.13.18 + 9.13.19 json schema validation generator .net Copyright © Rico Suter, 2018 https://github.com/rsuter/NJsonSchema/blob/master/LICENSE.md diff --git a/src/NJsonSchema/NJsonSchema.csproj b/src/NJsonSchema/NJsonSchema.csproj index fefe97e04..ca3e43aa9 100644 --- a/src/NJsonSchema/NJsonSchema.csproj +++ b/src/NJsonSchema/NJsonSchema.csproj @@ -2,7 +2,7 @@ netstandard1.0;netstandard2.0;net40;net45 JSON Schema reader, generator and validator for .NET - 9.13.18 + 9.13.19 json schema validation generator .net Copyright © Rico Suter, 2018 https://github.com/rsuter/NJsonSchema/blob/master/LICENSE.md diff --git a/src/NJsonSchema/Validation/JsonSchemaValidator.cs b/src/NJsonSchema/Validation/JsonSchemaValidator.cs index 3f78cb2cd..fa8b724fc 100644 --- a/src/NJsonSchema/Validation/JsonSchemaValidator.cs +++ b/src/NJsonSchema/Validation/JsonSchemaValidator.cs @@ -8,6 +8,7 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text.RegularExpressions; using Newtonsoft.Json; @@ -52,8 +53,15 @@ public JsonSchemaValidator() /// The list of validation errors. public ICollection Validate(string jsonData, JsonSchema4 schema) { - var jsonObject = JToken.Parse(jsonData); - return Validate(jsonObject, schema); + using (var reader = new StringReader(jsonData)) + using (var jsonReader = new JsonTextReader(reader) + { + DateParseHandling = DateParseHandling.None + }) + { + var jsonObject = JToken.ReadFrom(jsonReader); + return Validate(jsonObject, schema); + } } /// Validates the given JSON token.