RicoSuter / NSwag

The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript.
http://NSwag.org
MIT License
6.61k stars 1.22k forks source link

[Bug] NSwag 14.0.4 ignores JsonIgnoreAttribute #4834

Closed Mrks83 closed 3 months ago

Mrks83 commented 3 months ago

With NSwag 14.0.3 public properties with [JsonIgnore] were ignored. Now, they appear in the OpenApi document. It looks like the serializer has changed from Newtonsoft Json to System.Text Json.


public class MyClass
{
    [Newtonsoft.Json.JsonIgnore]
    public object? Value

   ...
}
Gismork commented 3 months ago

I had the exact same issue when I updated from NSwag 14.0.3 to 14.0.04. I didn't understand why I had a "new" property in my client.

Using JsonIgnore attribute from System.Text.Json.Serialization fix that.

Thanks !

RicoSuter commented 3 months ago

I think this PR here broke this: https://github.com/RicoSuter/NSwag/pull/4733

isteyak commented 2 months ago

I'musing openApiToCSharpClient (nswag 14.0.7 version) prior to that i was using (nswag 13.20.0 version) before my client code was showing jsonignore attributes like :

[System.Text.Json.Serialization.JsonPropertyName("href")] [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)]
[System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)] public System.Uri Href { get; set; }

Now its not showing

[System.Text.Json.Serialization.JsonPropertyName("href")] [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)] public System.Uri Href { get; set; }

what do i need to do in-order to fix it?