-
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
Description
.NET 9 & .NET 10 have the same behavior.
repro:
using Microsoft.AspNetCore.Mvc.ApiExplorer;
using Microsoft.AspNetCore.Mvc.ModelBinding;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddOpenApi(options => options.AddDocumentTransformer((document, context, cancellationToken) =>
{
EmptyModelMetadataProvider provider = new();
foreach (var group in context.DescriptionGroups)
{
foreach (var item in group.Items)
{
foreach (var responseType in item.SupportedResponseTypes)
{
if (responseType.Type == typeof(Wrapped))
{
responseType.Type = typeof(string);
responseType.ApiResponseFormats = [new ApiResponseFormat { MediaType = "text/plain" }];
}
}
}
}
return Task.CompletedTask;
}));
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
}
app.MapGet("/", () => new Wrapped("Hello, World!")).AddEndpointFilter<EndpointFilter>();
app.Run();
record Wrapped(string Value);
class EndpointFilter : IEndpointFilter
{
public async ValueTask<object?> InvokeAsync(EndpointFilterInvocationContext context, EndpointFilterDelegate next)
{
var v = await next.Invoke(context);
return v is Wrapped wrapped ? wrapped.Value : v;
}
}
the first time:
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Wrapped"
}
}
}
}
the rest:
"responses": {
"200": {
"description": "OK",
"content": {
"text/plain": {
"schema": {
"type": "string"
}
}
}
}
}
Is this a bug or is my usage incorrect ?
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