-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Closed
Labels
area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-openapi
Milestone
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
If I define this endpoint:
#nullable enable
app.MapGet("/api/{group}/people_nullable_enabled", (string group) =>
{
return TypedResults.Ok(new { GroupName = group });
})
.WithOpenApi();
swagger.json file correctly sets the group
route parameter as required:
"parameters": [
{
"name": "group",
"in": "path",
"required": true,
"style": "simple",
"schema": {
"type": "string"
}
}
]
However, If I disable Nullable Reference Types, than this parameter is no longer marked as required:
#nullable disable
app.MapGet("/api/{group}/people_nullable_disabled", (string group) =>
{
return TypedResults.Ok(new { GroupName = group });
})
.WithOpenApi();
"parameters": [
{
"name": "group",
"in": "path",
"style": "simple",
"schema": {
"type": "string"
}
}
]
If I try to invoke the endpoint using Swagger UI, a comma is passed as route argument:
The problem is related to the WithOpenApi
extension method. In fact, if I remove it, than the group
route parameter is again set as required:
#nullable disable
app.MapGet("/api/{group}/people_nullable_disabled", (string group) =>
{
return TypedResults.Ok(new { GroupName = group });
});
"parameters": [
{
"name": "group",
"in": "path",
"required": true,
"style": "simple",
"schema": {
"type": "string"
}
}
]
Expected Behavior
The group
route parameter should be required in any cases, regardless the presence of Nullable Reference Types and the usage of WithOpenApi
.
Steps To Reproduce
Minimal repro here: https://github.com/marcominerva/PathIssue
Exceptions (if any)
No response
.NET Version
7.0.103
Anything else?
No response
cleftheris
Metadata
Metadata
Assignees
Labels
area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-openapi