-Fixed schema generation with negative enum values
This commit is contained in:
@@ -449,5 +449,54 @@ namespace Newtonsoft.Json.Tests.Schema
|
||||
}
|
||||
}", 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -311,8 +311,8 @@ namespace Newtonsoft.Json.Schema
|
||||
CurrentSchema.Enum = new List<JToken>();
|
||||
CurrentSchema.Options = new Dictionary<JToken, string>();
|
||||
|
||||
EnumValues<ulong> enumValues = EnumUtils.GetNamesAndValues<ulong>(type);
|
||||
foreach (EnumValue<ulong> enumValue in enumValues)
|
||||
EnumValues<long> enumValues = EnumUtils.GetNamesAndValues<long>(type);
|
||||
foreach (EnumValue<long> enumValue in enumValues)
|
||||
{
|
||||
JToken value = JToken.FromObject(enumValue.Value);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user