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
Test for Dictionary Enum Key-Value with StringEnumConverter
  • Loading branch information
angelaki committed Apr 23, 2024
commit dec024370def69e06cba67d9b79f889979b48f6c
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,22 @@ public void GenerateSchema_HonorsSerializerOption_StringEnumConverter(
Assert.Equal(expectedDefaultAsJson, propertySchema.Default.ToJson());
}

[Fact]
public void GenerateSchema_HonorsEnumDictionaryKeys_StringEnumConverter()
{
var subjectWithJsonStringEnumConverter = Subject(
configureSerializer: c => { c.Converters.Add(new JsonStringEnumConverter()); }
);
var subject = Subject();
var schemaRepository = new SchemaRepository();

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

Assert.Equal(typeof(IntEnum).GetEnumValues().Length, referenceSchemaWithJsonStringEnumConverter.Properties.Count);
Assert.Empty(referenceSchema.Properties);
}

[Fact]
public void GenerateSchema_HonorsSerializerAttribute_StringEnumConverter()
{
Expand Down
Loading