У меня есть API в .NET 8, использующий FastEndpoints, и Я пытаюсь сериализовать ввод и вывод API через генератор источников. Я заставил ввод работать, но вывод по каким-то причинам остается пустым "{}".

Мой код:
WeatherForecastController.cs
Код: Выделить всё
public class WeatherForecastController : Endpoint
{
public override void Configure()
{
Post("/test");
Description(b => b.Produces(200));
AllowAnonymous();
}
public override async Task HandleAsync(DtoIn req, CancellationToken ct)
{
await SendOkAsync(new DtoOut()
{
Surname = req.Name + "Teste"
}, ct);
}
}
public class DtoIn
{
public string Name { get; set; }
}
public class DtoOut
{
public string Surname { get; set; }
}
Код: Выделить всё
using FastEndpoints;
using FastEndpoints.Swagger;
using WebApplication1;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddFastEndpoints();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.UseFastEndpoints( c =>
{
c.Serializer.Options.TypeInfoResolver = SourceGenerator.Default;
});
app.UseSwaggerGen();
app.MapControllers();
app.Run();
Код: Выделить всё
using System.Text.Json.Serialization;
using WebApplication1.Controllers;
namespace WebApplication1
{
[JsonSerializable(typeof(DtoIn))]
[JsonSerializable(typeof(DtoOut))]
[JsonSourceGenerationOptions(
WriteIndented = true,
GenerationMode = JsonSourceGenerationMode.Default,
PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase
)]
internal partial class SourceGenerator : JsonSerializerContext
{
}
}
Код: Выделить всё
net8.0
enable
enable
true
false
true
true
Кто-нибудь знает, что не так? Любая помощь будет оценена
Подробнее здесь: https://stackoverflow.com/questions/790 ... mpty-value
Мобильная версия