Closed
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
I want to generate a OpenApi json for my Controller based Api.
I have the following controller Code:
[Route("api/[controller]")]
[ApiController]
public class TestController : ControllerBase
{
[HttpPost("test")]
public async Task<IActionResult> PostTest([FromBody] XmlPlaceholder? xmlPlaceholder = null)
{
return Ok();
}
}
The XmlPlaceholder class looks like this:
public class XmlPlaceholder : IEndpointParameterMetadataProvider
{
public static void PopulateMetadata(ParameterInfo parameter, EndpointBuilder builder)
{
builder.Metadata.Add(new AcceptsMetadata(["application/xml", "text/xml"], typeof(XmlPlaceholder)));
}
}
The generated OpenAPI json looks like this:
"/api/Test/test": {
"post": {
"tags": [
"Test"
],
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/XmlPlaceholder"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/XmlPlaceholder"
}
},
"application/*+json": {
"schema": {
"$ref": "#/components/schemas/XmlPlaceholder"
}
}
}
},
"responses": {
"200": {
"description": "OK"
}
}
}
}
Expected Behavior
I would expect the same behavior as for minimal apis.
There the metadata is used and produces the following output:
"/minimalTest": {
"post": {
"tags": [
"WebApplication2"
],
"operationId": "Minimal Test",
"requestBody": {
"content": {
"application/xml": {
"schema": {
"$ref": "#/components/schemas/XmlPlaceholder"
}
},
"text/xml": {
"schema": {
"$ref": "#/components/schemas/XmlPlaceholder"
}
}
}
},
"responses": {
"200": {
"description": "OK"
}
}
}
},
Steps To Reproduce
Exceptions (if any)
No response
.NET Version
9.0.100-rc.1.24452.12
Anything else?
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.0-rc.1.24452.1" />
</ItemGroup>
</Project>