Is there an existing issue for this?
Describe the bug
Routes that accept both form and json bodies through multiple controller actions with [ConsumesAttribute], a documented, supported use case of aspnetcore, are not emitted correctly by Microsoft.AspNetCore.OpenApi.
The comment on these lines is incorrect:
|
// If there are no body parameters, check for form parameters. |
|
// Note: Form parameters and body parameters cannot exist simultaneously |
|
// in the same endpoint. |
. It contradicts the documentation for [ConsumesAttribute] -
https://learn.microsoft.com/en-us/aspnet/core/web-api/?view=aspnetcore-9.0#define-supported-request-content-types-with-the-consumes-attribute-1. A single route can indeed support both formdata and json bodies.
Expected Behavior
Both JSON and form content types are listed for the endpoint in requestBody.content in the OpenAPI document.
Steps To Reproduce
Write the exact example from the [Consumes] documentation at https://learn.microsoft.com/en-us/aspnet/core/web-api/?view=aspnetcore-9.0#define-supported-request-content-types-with-the-consumes-attribute-1:
[ApiController]
[Route("api/[controller]")]
public class ConsumesController : ControllerBase
{
[HttpPost]
[Consumes("application/json")]
public IActionResult PostJson(IEnumerable<int> values) =>
Ok(new { Consumes = "application/json", Values = values });
[HttpPost]
[Consumes("application/x-www-form-urlencoded")]
public IActionResult PostForm([FromForm] IEnumerable<int> values) =>
Ok(new { Consumes = "application/x-www-form-urlencoded", Values = values });
}
Observe that the JSON body is excluded from the OpenAPI document produced by Microsoft.AspNetCore.OpenApi. Only the form data body is present:
"/api/Consumes": {
"post": {
"tags": [
"Consumes"
],
"requestBody": {
"content": {
"application/x-www-form-urlencoded": {
"schema": {
"type": "object",
"properties": {
"values": {
"type": "array",
"items": {
"type": "integer",
"format": "int32"
}
}
}
}
}
},
"required": true
},
"responses": {
"200": {
"description": "OK"
}
}
}
},
Exceptions (if any)
No response
.NET Version
9.0.100-rc.2.24474.11
Anything else?
No response
Is there an existing issue for this?
Describe the bug
Routes that accept both form and json bodies through multiple controller actions with [ConsumesAttribute], a documented, supported use case of aspnetcore, are not emitted correctly by Microsoft.AspNetCore.OpenApi.
The comment on these lines is incorrect:
aspnetcore/src/OpenApi/src/Services/OpenApiDocumentService.cs
Lines 478 to 480 in 44a9f8a
Expected Behavior
Both JSON and form content types are listed for the endpoint in
requestBody.contentin the OpenAPI document.Steps To Reproduce
Write the exact example from the [Consumes] documentation at https://learn.microsoft.com/en-us/aspnet/core/web-api/?view=aspnetcore-9.0#define-supported-request-content-types-with-the-consumes-attribute-1:
Observe that the JSON body is excluded from the OpenAPI document produced by
Microsoft.AspNetCore.OpenApi. Only the form data body is present:Exceptions (if any)
No response
.NET Version
9.0.100-rc.2.24474.11
Anything else?
No response