Skip to content

Commit

Permalink
add test to replicate missing attribute on nullable number
Browse files Browse the repository at this point in the history
  • Loading branch information
gregsdennis committed Mar 25, 2024
1 parent dad59b7 commit e39211b
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions JsonSchema.Generation.Tests/ClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using Json.More;
using Json.Schema.Generation.Intents;
using NUnit.Framework;

Expand Down Expand Up @@ -323,4 +324,34 @@ public void Issue551_MinMaxItemsOnStringProperty()
Assert.AreEqual(1, schema.GetProperties()!["Value"].Keywords!.Count);
Assert.AreEqual("type", schema.GetProperties()!["Value"].Keywords!.First().Keyword());
}

private class Issue696_NullableDecimalWithMultipleOf
{
[Nullable(true)]
[MultipleOf(0.1)]
public decimal? Apr { get; set; }
}

[Test]
public void Issue696_MultipleOfMissingForNullableDecimal()
{
var expected = JsonNode.Parse(
"""
{
"type": "object",
"properties": {
"Apr": {
"type": ["number", "null"],
"multipleOf": 0.1
}
}
}
""");

JsonSchema schema = new JsonSchemaBuilder().FromType<Issue696_NullableDecimalWithMultipleOf>();
var schemaJson = JsonSerializer.SerializeToNode(schema, TestSerializerContext.Default.JsonSchema);
Console.WriteLine(schemaJson);

Assert.IsTrue(schemaJson.IsEquivalentTo(expected));
}
}

0 comments on commit e39211b

Please sign in to comment.