.NET 10 OpenAPI emits an object constraint for floating-point values
Is there an existing issue for this?
- I have searched the existing issues.
Describe the bug
With Microsoft.AspNetCore.OpenApi 10.0.12, enabling JsonNumberHandling.AllowNamedFloatingPointLiterals generates an unsatisfiable schema for a double property. The endpoint returns numeric values, but its OpenAPI 3.1.1 schema requires an object alongside number/string alternatives:
{
"type": "object",
"anyOf": [
{
"pattern": "^-?(?:0|[1-9]\\d*)(?:\\.\\d+)?(?:[eE][+-]?\\d+)?$",
"type": ["number", "string"]
},
{
"enum": ["NaN", "Infinity", "-Infinity"]
}
],
"format": "double"
}A number fails the object constraint; an object fails both alternatives. No JSON value satisfies this schema.
Expected Behavior
Keep the numeric and named-literal alternatives without the outer "type": "object" constraint.
Steps To Reproduce
git clone https://github.com/alexaka1/repro-dotnet--aspnetcore-openapi-floating-point.git
cd repro-dotnet--aspnetcore-openapi-floating-point
docker compose up --build -d
docker compose run --rm compareThe repro changes two things in dotnet new webapi: enables AllowNamedFloatingPointLiterals through ConfigureHttpJsonOptions and changes WeatherForecast.TemperatureF from int to double.
The comparison runs the same source on both versions and prints the response value and temperatureF schema.
Exceptions (if any)
None. Both endpoints return HTTP 200.
.NET Version
SDK 10.0.401, ASP.NET Core and Microsoft.AspNetCore.OpenApi 10.0.12.
Anything else?
| Runtime and OpenAPI package | Native ARM64 | Emulated x64 |
|---|---|---|
| 10.0.12 | Incorrect object constraint | Incorrect object constraint |
| 11.0.0-preview.6.26359.118 | Correct numeric alternatives | Correct numeric alternatives |
The bug is architecture-independent. Each version produced identical documents on native ARM64 and x64 under Docker emulation on an ARM64 host. The .NET 10 containers ran Ubuntu 24.04 and reported linux-arm64 and linux-x64, respectively.
OpenApiJsonSchema.ReadProperty unconditionally sets schema.Type = JsonSchemaType.Object when reading anyOf or oneOf. #67001 removes that assignment as part of union support. The comparison above verifies the corrected behavior in .NET 11 Preview 6.
Could this correction be considered for a .NET 10 servicing release?
Source: dotnet/aspnetcore