-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
We have an Enum as one of the method's parameters. We also have a specific naming policy for that Enum. All the API responses that contain the Enum are getting formatted correctly as kebab naming within the JSON responses. But, when used as a parameter the binding fails to use the correct converter, it only works if the name is formatted as the default naming policy.
Expected Behavior
The binding for the parameters utilize the same naming policy that the Enum is configured for.
Steps To Reproduce
Configure specific Enum with custom naming policy.
.AddJsonOptions(options =>
{
...
options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter<Providers>(System.Text.Json.JsonNamingPolicy.KebabCaseLower));
options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter(System.Text.Json.JsonNamingPolicy.CamelCase));
options.JsonSerializerOptions.Converters.Add(new Core.Converters.DateOnlyJsonConverter());
});Use Enum as type of a parameter.
[HttpPost("{provider}/unlink", Name = "Unlink")]
public async Task<ActionResult<BooleanResponse>> Unlink(Providers provider)
{
...
}public enum Providers
{
ProviderOne,
ProviderTwo,
ProviderThree,
}Exceptions (if any)
When calling api endpoint as https://example.com/provider-one/unlink the server responds with 400.
When calling api endpoint as https://example.com/providerOne/unlink the method gets executed and the server responds with 200.
.NET Version
8.0.303
Anything else?
No response