Skip to content

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

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public static Dictionary<string, OpenApiSchema> ToOpenApiSchemas(this Type type,
var allProperties = type.IsInterface
? new[] { type }.Concat(type.GetInterfaces()).SelectMany(i => i.GetProperties())
: type.GetProperties();
var properties = allProperties.Where(p => !p.ExistsCustomAttribute<JsonIgnoreAttribute>());
var properties = allProperties.Where(p => !p.ExistsCustomAttribute<JsonIgnoreAttribute>(true));

var retVal = new Dictionary<string, OpenApiSchema>();
foreach (var property in properties)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ public static string GetOpenApiSubTypeNames(this Type type)
public static bool HasRecursiveProperty(this Type type)
{
var properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance)
.Where(p => !p.ExistsCustomAttribute<JsonIgnoreAttribute>());
.Where(p => !p.ExistsCustomAttribute<JsonIgnoreAttribute>(true));

var hasRecursiveType = properties.Select(p => p.PropertyType)
.Any(p => p == type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public override void Visit(IAcceptor acceptor, KeyValuePair<string, Type> type,
// Processes properties.
var properties = type.Value
.GetProperties(BindingFlags.Public | BindingFlags.Instance)
.Where(p => !p.ExistsCustomAttribute<JsonIgnoreAttribute>())
.Where(p => !p.ExistsCustomAttribute<JsonIgnoreAttribute>(true))
.ToDictionary(p => p.GetJsonPropertyName(namingStrategy), p => p);

this.ProcessProperties(instance, name, properties, namingStrategy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public override void Visit(IAcceptor acceptor, KeyValuePair<string, Type> type,
// Processes non-recursive properties
var properties = type.Value
.GetProperties(BindingFlags.Public | BindingFlags.Instance)
.Where(p => !p.ExistsCustomAttribute<JsonIgnoreAttribute>())
.Where(p => !p.ExistsCustomAttribute<JsonIgnoreAttribute>(true))
.Where(p => p.PropertyType != type.Value)
.ToDictionary(p => p.GetJsonPropertyName(namingStrategy), p => p);

Expand All @@ -107,7 +107,7 @@ public override void Visit(IAcceptor acceptor, KeyValuePair<string, Type> type,
// Processes recursive properties
var recursiveProperties = type.Value
.GetProperties(BindingFlags.Public | BindingFlags.Instance)
.Where(p => !p.ExistsCustomAttribute<JsonIgnoreAttribute>())
.Where(p => !p.ExistsCustomAttribute<JsonIgnoreAttribute>(true))
.Where(p => p.PropertyType == type.Value)
.ToDictionary(p => p.GetJsonPropertyName(namingStrategy), p => p);
var recursiveSchemas = recursiveProperties.ToDictionary(p => p.Key,
Expand Down