net core 5, I stopped using System.text.Json for some reason and I use NewtonSoft and I changed all the namespaces, for example, to JsonIgnore, but my problem is that the properties that I ignored are still displayed in the swagger output.
using System;
using Newtonsoft.Json;
public class AddEmployeeDto
{
public Guid Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
[JsonIgnore]
public int EmployeeType { get; set; }
}
this is swagger output :
CodePudding user response:
Since Sytem.text.Json
has become the default Serialize
tool of Asp.Net Core
, the standard version of Swagger
is also compatible with it,
and to change it, like this change that you have probably applied,
services.AddControllers().AddNewtonsoftJson();
You must install the package From Nuget
:
Swashbuckle.AspNetCore.Newtonsoft
And register it in your Service Container as follows to solve your problem
services.AddSwaggerGenNewtonsoftSupport();