-Fixed schema generation with negative enum values

This commit is contained in:
JamesNK
2009-10-02 23:49:11 +00:00
parent 3ae2accce4
commit 33ac3a9c44
2 changed files with 52 additions and 3 deletions
@@ -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);