azure-functions-openapi-extension icon indicating copy to clipboard operation
azure-functions-openapi-extension copied to clipboard

Fix handling of [JsonIgnore] to recurse and apply to inherited properties

Open jstoker opened this issue 2 years ago • 2 comments

Fix the handling of the Newtonsoft JsonIgnore attribute to take into account of inheritance.

jstoker avatar Nov 21 '22 12:11 jstoker

@jstoker Thanks for the PR. Would you please be able to elaborate this PR?

justinyoo avatar Dec 20 '22 04:12 justinyoo

Hi @justinyoo,

In one of our applications, we have a set of request/response types have a common set of properties, which are extracted into a common interface. One of the properties happens to be [JsonIgnore]-ed, as it isn't used by our client application, but generated within our functions code.

Newtonsoft JSON recognises the [JsonIgnore] attribute within the interface, and the Thing class when serialized will not contain the 'IgnoredProperty' in the JSON.

public interface IThing
{
    [JsonIgnore]
    string? IgnoredProperty { get; set; }
}
public class Thing : IThing 
{
    public string? IgnoredProperty { get; set; }
}

This PR is to make the behaviour of the OpenAPI generator not emit the IgnoredField in the swagger definition to correspond with the Newtonsoft behaviour (https://stackoverflow.com/a/55522993).

jstoker avatar Mar 22 '23 10:03 jstoker