-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Closed
Labels
Needs: DesignThis issue requires design work before implementating.This issue requires design work before implementating.area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcarea-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesbugThis issue describes a behavior which is not expected - a bug.This issue describes a behavior which is not expected - a bug.feature-openapi
Milestone
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
As described in HttpResults type, IResult types are supported in API Controller, however, after #43543 the metadata from IEndpointMetadataProvider are not populated to API Controller Actions anymore.
It is caused because the ActionDescriptor is already created when the EndpointMetadataPopulator is called and not getting updated.
| EndpointMetadataPopulator.PopulateMetadata(controllerActionDescriptor.MethodInfo, builder); |
swagger.json
{
"openapi": "3.0.1",
"info": {
"title": "WebApplication22",
"version": "1.0"
},
"paths": {
"/api/Test": {
"get": {
"tags": [
"Test"
],
"responses": {
"200": {
"description": "Success"
}
}
}
}
},
"components": { }
}Expected Behavior
swagger.json
{
"openapi": "3.0.1",
"info": {
"title": "WebApplication22",
"version": "1.0"
},
"paths": {
"/api/Test": {
"get": {
"tags": [
"Test"
],
"responses": {
"200": {
"description": "Success",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/FooBar"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"FooBar": {
"type": "object",
"properties": {
"requiredParam": {
"type": "string",
"nullable": true
}
},
"additionalProperties": false
}
}
}
}Steps To Reproduce
using Microsoft.AspNetCore.Http.HttpResults;
using Microsoft.AspNetCore.Mvc;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.MapControllers();
app.Run();
[ApiController]
[Route("api/[controller]")]
public class TestController : ControllerBase
{
[HttpGet]
public Ok<FooBar> GEt()
=> TypedResults.Ok(new FooBar() { RequiredParam = ""});
}
public class FooBar
{
public required string RequiredParam { get; set; }
}Exceptions (if any)
No response
.NET Version
8.0.100-alpha.1.22472.9
Anything else?
No response
vernou, travisty-, sanjaydebnath, JoachimC, FigaCZ and 40 moremeixger, gustavlarson, vernou, rpf3, deltasmackerel and 2 more
Metadata
Metadata
Assignees
Labels
Needs: DesignThis issue requires design work before implementating.This issue requires design work before implementating.area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcarea-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesbugThis issue describes a behavior which is not expected - a bug.This issue describes a behavior which is not expected - a bug.feature-openapi