-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Closed
Labels
✔️ Resolution: AnsweredResolved because the question asked by the original author has been answered.Resolved because the question asked by the original author has been answered.Status: Resolvedarea-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesfeature-openapi
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
In order to configure a controller API app to both accept only numbers for integer properties and represent them as only integers (and not integer/strings) in the OpenAPI document, JSON options have to be configured in two places:
builder.Services
.AddControllers()
.AddJsonOptions(options =>
{
// Tell controllers to not accept strings for number fields
options.JsonSerializerOptions.NumberHandling = JsonNumberHandling.Strict;
});
builder.Services.ConfigureHttpJsonOptions(options =>
{
// Tell OpenApi generator to report number fields as integers/floats only, not strings
options.SerializerOptions.NumberHandling = JsonNumberHandling.Strict;
});Typically only one or the other are configured (former for controller-based APIs and the latter for minimal APIs). Is that intentional or a bug that OpenAPI ignores Microsoft.AspNetCore.Mvc.JsonOptions?
Related to #61038
Expected Behavior
NumberHandling only needs to be set to strict on Microsoft.AspNetCore.Mvc.JsonOptions to cause OpenAPI to report number fields as not strings.
Steps To Reproduce
No response
Exceptions (if any)
No response
.NET Version
10.0.100-rc.2.25502.107
Anything else?
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
✔️ Resolution: AnsweredResolved because the question asked by the original author has been answered.Resolved because the question asked by the original author has been answered.Status: Resolvedarea-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesfeature-openapi