Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate Enum-Dictionary-Keys (analogous to Newtonsoft) #2825

Merged
merged 8 commits into from
Apr 24, 2024
Prev Previous commit
Next Next commit
Check actual Dictionary key names
  • Loading branch information
angelaki committed Apr 24, 2024
commit f15394962e3381b155255c9e4ff7997775591609
Original file line number Diff line number Diff line change
Expand Up @@ -770,15 +770,22 @@ public void GenerateSchema_HonorsSerializerOption_StringEnumConverter(
Assert.Equal(expectedDefaultAsJson, propertySchema.Default.ToJson());
}

[Fact]
public void GenerateSchema_HonorsEnumDictionaryKeys_StringEnumConverter()
[Theory]
[InlineData(false, new[] { "Value2", "Value4", "Value8" })]
[InlineData(true, new[] { "value2", "value4", "value8" })]
public void GenerateSchema_HonorsEnumDictionaryKeys_StringEnumConverter(
bool camelCaseText,
string[] expectedEnumAsJson
martincostello marked this conversation as resolved.
Show resolved Hide resolved
)
{
var subject = Subject();
var subject = Subject(
configureSerializer: c => { c.DictionaryKeyPolicy = camelCaseText ? JsonNamingPolicy.CamelCase : null; }
angelaki marked this conversation as resolved.
Show resolved Hide resolved
);
var schemaRepository = new SchemaRepository();

var referenceSchema = subject.GenerateSchema(typeof(Dictionary<IntEnum, string>), schemaRepository);

Assert.Equal(typeof(IntEnum).GetEnumValues().Length, referenceSchema.Properties.Count);
Assert.Equal(expectedEnumAsJson, referenceSchema.Properties.Keys);
}

[Fact]
Expand Down
Loading