Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jstoker
Copy link
Contributor

@jstoker jstoker commented Nov 21, 2022

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

@justinyoo
Copy link
Contributor

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

@jstoker
Copy link
Contributor Author

jstoker commented Mar 22, 2023

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants