-
Notifications
You must be signed in to change notification settings - Fork 10.3k
OpenApi doesn't convert query params to snake_case #60936
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
Comments
You need to configure the JSON serialization options used by OpenAPI to use snake_case: |
I did find that issue. But I think that only deals with json object property names. builder.Services.AddControllers(...).AddJsonOptions(options => ConfigureJsonSerializer(options.JsonSerializerOptions));
builder.Services.ConfigureHttpJsonOptions(options => ConfigureJsonSerializer(options.SerializerOptions));
static void ConfigureJsonSerializer(JsonSerializerOptions options)
{
options.PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower;
} However it doesn't change query parameters ( The currently generated open api spec is as follows: "parameters": [
{
"name": "helloWorld", // <---- not snake_case
"in": "query",
"schema": {
"type": "integer",
"format": "int32"
}
}
], it should be "parameters": [
{
"name": "hello_world", // <---- correct
"in": "query",
"schema": {
"type": "integer",
"format": "int32"
}
}
], |
@eskild-th Thanks for filing this issue! The JsonSerializerOptions will only work for properties within in the schemas that are generated. The issue that you are seeing is with the parameter name. I suspect that the issue here is actually in MVC, likely in the DefaultApiDescriptionProvider that is used to map MVC's model binding metadata to a set of metadata that the OpenAPI document can introspect. In this particular case, I suspect that value providers are not correctly resolved by the provider. We'll need to invetigate further why the ApiDescriptionProvider isn't picking this up. |
Is there an existing issue for this?
Describe the bug
OpenApi doesn't pickup on ValueProvider changes.
I've replaced the default
QueryStringValueProviderFactory
with my ownSnakeCaseQueryValueProviderFactory
. The controller works as expected. But the generated OpenApi spec is still using camelCasing for query params.Expected Behavior
I expect the OpenApi to pickup on the ValueProvider change and show the correct spec
Steps To Reproduce
// startup
// controller
Exceptions (if any)
No response
.NET Version
9.0.201
Anything else?
No response
The text was updated successfully, but these errors were encountered: