Describe the bug
I have a schema which includes an enum with JsonStringEnumConverter and a member annotated with EnumMember to supply an alternate value for de/serialization:
[JsonConverter(typeof(JsonStringEnumConverter))]
public enum JsonConverterAnnotatedEnum
{
Value1 = 2,
Value2 = 4,
[EnumMember(Value = "X-foo")]
X = 8
}
Expected behavior
The resulting JSON schema should honor value of EnumMember, i.e.:
{
"type": "string",
"enum": [
"Value1",
"Value2",
"X-foo"
]
}
Actual behavior
EnumMember attribute is ignored and the enum name is used instead in the resulting schema:
{
"type": "string",
"enum": [
"Value1",
"Value2",
"X"
]
}
Steps to reproduce
This can be reproduced using SwaggerGen's tests (in fact, the tests for Newtonsoft.Json based serializer already cover this use case).
Here is an example commit modifying the tests: 493e563
- Add
[EnumMember(Value = "X-foo")] attribute to JsonConverterAnnotatedEnum in Swashbuckle.AspNetCore.SwaggerGen.Test
- Modify the
GenerateSchema_HonorsSerializerAttribute_StringEnumConverter in test/Swashbuckle.AspNetCore.SwaggerGen.Test/SchemaGenerator/JsonSerializerSchemaGeneratorTests.cs to assert X-foo value
- Run the
Swashbuckle.AspNetCore.SwaggerGen.Test project
Exception(s) (if any)
No response
Swashbuckle.AspNetCore version
8.0.0
.NET Version
9.0.202
Anything else?
This issue was previously fixed in #589 for Newtonsoft.Json serializer. So it seems like a missing feature parity in System.Text.Json-based serializer.
Describe the bug
I have a schema which includes an enum with
JsonStringEnumConverterand a member annotated withEnumMemberto supply an alternate value for de/serialization:Expected behavior
The resulting JSON schema should honor value of
EnumMember, i.e.:{ "type": "string", "enum": [ "Value1", "Value2", "X-foo" ] }Actual behavior
EnumMemberattribute is ignored and the enum name is used instead in the resulting schema:{ "type": "string", "enum": [ "Value1", "Value2", "X" ] }Steps to reproduce
This can be reproduced using SwaggerGen's tests (in fact, the tests for Newtonsoft.Json based serializer already cover this use case).
Here is an example commit modifying the tests: 493e563
[EnumMember(Value = "X-foo")]attribute toJsonConverterAnnotatedEnuminSwashbuckle.AspNetCore.SwaggerGen.TestGenerateSchema_HonorsSerializerAttribute_StringEnumConverterintest/Swashbuckle.AspNetCore.SwaggerGen.Test/SchemaGenerator/JsonSerializerSchemaGeneratorTests.csto assertX-foovalueSwashbuckle.AspNetCore.SwaggerGen.TestprojectException(s) (if any)
No response
Swashbuckle.AspNetCore version
8.0.0
.NET Version
9.0.202
Anything else?
This issue was previously fixed in #589 for Newtonsoft.Json serializer. So it seems like a missing feature parity in
System.Text.Json-based serializer.