Swashbuckle.AspNetCore icon indicating copy to clipboard operation
Swashbuckle.AspNetCore copied to clipboard

JsonSerializerOptions.IncludeFields seems to be ignored for schema generation

Open rchoffardet opened this issue 2 years ago • 9 comments

Hello,

Knowing that the migration to System.Text.Json disabled the serialization of fields by default, I tried to re-enable it. The "Web API" way :

builder.Services.Configure<Microsoft.AspNetCore.Mvc.JsonOptions>(options => { 
    options.JsonSerializerOptions.IncludeFields = true; 
});

The "Minimal" way :

builder.Services.Configure<Microsoft.AspNetCore.Http.Json.JsonOptions>(options => { 
    options.SerializerOptions.IncludeFields = true; 
});

This option is correctly applied by ASP, but not during the schema generation. Altough, I dont understand why. At least not for the "Web API" way...

The code retrieves the configured option, as shown here : https://github.com/domaindrivendev/Swashbuckle.AspNetCore/blob/master/src/Swashbuckle.AspNetCore.SwaggerGen/DependencyInjection/SwaggerGenServiceCollectionExtensions.cs#L35

One workaround is to declare properties instead of fields.

rchoffardet avatar May 25 '22 14:05 rchoffardet