-Fixed schema generation with negative enum values
This commit is contained in:
@@ -447,6 +447,55 @@ namespace Newtonsoft.Json.Tests.Schema
|
|||||||
""type"": ""integer""
|
""type"": ""integer""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}", json);
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum SortTypeFlag
|
||||||
|
{
|
||||||
|
No = 0,
|
||||||
|
Asc = 1,
|
||||||
|
Desc = -1
|
||||||
|
}
|
||||||
|
|
||||||
|
public class X
|
||||||
|
{
|
||||||
|
public SortTypeFlag x;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void GenerateSchemaWithNegativeEnum()
|
||||||
|
{
|
||||||
|
JsonSchemaGenerator jsonSchemaGenerator = new JsonSchemaGenerator();
|
||||||
|
JsonSchema schema = jsonSchemaGenerator.Generate(typeof(X));
|
||||||
|
|
||||||
|
string json = schema.ToString();
|
||||||
|
|
||||||
|
Assert.AreEqual(@"{
|
||||||
|
""type"": ""object"",
|
||||||
|
""properties"": {
|
||||||
|
""x"": {
|
||||||
|
""type"": ""integer"",
|
||||||
|
""enum"": [
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
-1
|
||||||
|
],
|
||||||
|
""options"": [
|
||||||
|
{
|
||||||
|
""value"": 0,
|
||||||
|
""value"": ""No""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
""value"": 1,
|
||||||
|
""value"": ""Asc""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
""value"": -1,
|
||||||
|
""value"": ""Desc""
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
}", json);
|
}", json);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -311,8 +311,8 @@ namespace Newtonsoft.Json.Schema
|
|||||||
CurrentSchema.Enum = new List<JToken>();
|
CurrentSchema.Enum = new List<JToken>();
|
||||||
CurrentSchema.Options = new Dictionary<JToken, string>();
|
CurrentSchema.Options = new Dictionary<JToken, string>();
|
||||||
|
|
||||||
EnumValues<ulong> enumValues = EnumUtils.GetNamesAndValues<ulong>(type);
|
EnumValues<long> enumValues = EnumUtils.GetNamesAndValues<long>(type);
|
||||||
foreach (EnumValue<ulong> enumValue in enumValues)
|
foreach (EnumValue<long> enumValue in enumValues)
|
||||||
{
|
{
|
||||||
JToken value = JToken.FromObject(enumValue.Value);
|
JToken value = JToken.FromObject(enumValue.Value);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user