Skip to content

Commit

Permalink
fix(generator): fix round issue for sample date generator (#1297)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChangeTheCode authored Dec 18, 2020
1 parent 4d47951 commit 39a14b5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public async Task PropertyWithIntegerMinimumDefiniton()


[Fact]
public async Task PropertyWithFloatMinimumDefiniton()
public async Task PropertyWithFloatMinimumDefinition()
{
//// Arrange
var data = @"{
Expand Down Expand Up @@ -172,8 +172,8 @@ public async Task PropertyWithFloatMinimumDefiniton()
""properties"": {
""value"": {
""type"": ""number"",
""maximum"": 5.0,
""minimum"": 1.0
""maximum"": 5.00001,
""minimum"": 1.000012
}
}
}
Expand All @@ -188,7 +188,7 @@ public async Task PropertyWithFloatMinimumDefiniton()
var validationResult = schema.Validate(testJson);
Assert.NotNull(validationResult);
Assert.Equal(0, validationResult.Count);
Assert.Equal(1.0, testJson.SelectToken("body.numberContent.value").Value<float>());
Assert.Equal(1.000012, testJson.SelectToken("body.numberContent.value").Value<double>());
}

[Fact]
Expand Down
6 changes: 3 additions & 3 deletions src/NJsonSchema/Generation/SampleJsonDataGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,15 @@ private static JToken HandleNumberType(JsonSchema schema)
{
if (schema.ExclusiveMinimumRaw != null)
{
return JToken.FromObject(float.Parse(schema.Minimum.ToString()) + 0.1);
return JToken.FromObject((decimal)(float.Parse(schema.Minimum.ToString()) + 0.1));
}
else if (schema.ExclusiveMinimum != null)
{
return JToken.FromObject(float.Parse(schema.ExclusiveMinimum.ToString()));
return JToken.FromObject(decimal.Parse(schema.ExclusiveMinimum.ToString()));
}
else if (schema.Minimum.HasValue)
{
return float.Parse(schema.Minimum.ToString());
return decimal.Parse(schema.Minimum.ToString());
}
return JToken.FromObject(0.0);
}
Expand Down

0 comments on commit 39a14b5

Please sign in to comment.