-
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
The following model with .NET 10, Microsoft.AspNetCore.OpenApi and Swagger
public class TodoRequest
{
[Required]
public string? Description { get; set; } = null!;
public DateTimeOffset? DueDate { get; set; }
[Required]
public Priority? Priority { get; set; }
public List<string>? Tags { get; set; } = [];
}Would result in the following example value:

Note the nulls for Description and DueDate properties in the Example Value section of the screenshot.
Expected Behavior
This was working in .NET 9 and would result in the following example value:
Steps To Reproduce
Clone the following repo and run the project.
You can also change the TargetFramework to net9.0 to see the previous behaviour.
https://github.com/ctyar/Playground/tree/dotnet_10_openapi
Exceptions (if any)
No response
.NET Version
10.0.100-preview.3.25177.4
Anything else?
I believe this is happening because of the move from openapi 3.0.1 to openapi 3.1.1.
It seems the new specification handles nulls differently, so there was a change in the openapi JSON that Microsoft.AspNetCore.OpenApi produces.
For example, the sample above produces the following JSON specification for the Description property:
"description": {
"type": [
"null",
"string"
]
},If we change the order of members in the type array to:
"description": {
"type": [
"string",
"null"
]
},Swagger is able to produce the correct example.
