-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Open
Labels
documentationhelp-wantedA change up for grabs for contributions from the communityA change up for grabs for contributions from the community
Description
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 toJsonConverterAnnotatedEnuminSwashbuckle.AspNetCore.SwaggerGen.Test - Modify the
GenerateSchema_HonorsSerializerAttribute_StringEnumConverterintest/Swashbuckle.AspNetCore.SwaggerGen.Test/SchemaGenerator/JsonSerializerSchemaGeneratorTests.csto assertX-foovalue - Run the
Swashbuckle.AspNetCore.SwaggerGen.Testproject
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.
Metadata
Metadata
Assignees
Labels
documentationhelp-wantedA change up for grabs for contributions from the communityA change up for grabs for contributions from the community