From 27e0cb1439d0a646577e114e0c3f140858dc2800 Mon Sep 17 00:00:00 2001 From: Michael Edgar Date: Tue, 12 Nov 2024 19:54:16 -0500 Subject: [PATCH] fix: do not auto-expose properties absent from `@JsonIgnoreProperties` Only when annotation is used on the referencing type. Properties still exposed when annotation is on declaring class or descendant. Signed-off-by: Michael Edgar --- .../runtime/scanner/dataobject/IgnoreResolver.java | 11 ++++++----- .../openapi/runtime/scanner/JsonViewTests.java | 4 ++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/io/smallrye/openapi/runtime/scanner/dataobject/IgnoreResolver.java b/core/src/main/java/io/smallrye/openapi/runtime/scanner/dataobject/IgnoreResolver.java index 0b37f0c86..678012abf 100644 --- a/core/src/main/java/io/smallrye/openapi/runtime/scanner/dataobject/IgnoreResolver.java +++ b/core/src/main/java/io/smallrye/openapi/runtime/scanner/dataobject/IgnoreResolver.java @@ -215,7 +215,7 @@ public boolean configuresVisibility(AnnotationTarget reference) { private Visibility declaringClassIgnore(String propertyName, AnnotationTarget target) { AnnotationInstance declaringClassJIP = context.annotations().getAnnotation(TypeUtil.getDeclaringClass(target), getNames()); - return shouldIgnoreTarget(declaringClassJIP, propertyName); + return shouldIgnoreTarget(declaringClassJIP, propertyName, Visibility.EXPOSED); } /** @@ -244,10 +244,11 @@ private Visibility nestingPropertyIgnore(AnnotationTarget nesting, String proper return Visibility.UNSET; } AnnotationInstance nestedTypeJIP = context.annotations().getAnnotation(nesting, getNames()); - return shouldIgnoreTarget(nestedTypeJIP, propertyName); + return shouldIgnoreTarget(nestedTypeJIP, propertyName, Visibility.UNSET); } - private Visibility shouldIgnoreTarget(AnnotationInstance jipAnnotation, String targetName) { + private Visibility shouldIgnoreTarget(AnnotationInstance jipAnnotation, String targetName, + Visibility unlistedVisibility) { if (jipAnnotation == null || jipAnnotation.value() == null) { return Visibility.UNSET; } @@ -255,7 +256,7 @@ private Visibility shouldIgnoreTarget(AnnotationInstance jipAnnotation, String t if (Arrays.asList(jipAnnotation.value().asStringArray()).contains(targetName)) { return Visibility.IGNORED; } else { - return Visibility.EXPOSED; + return unlistedVisibility; } } @@ -268,7 +269,7 @@ public List getNames() { public Visibility getDescendantVisibility(String propertyName, List descendants) { for (ClassInfo descendant : descendants) { AnnotationInstance declaringClassJIP = context.annotations().getAnnotation(descendant, getNames()); - Visibility visibility = shouldIgnoreTarget(declaringClassJIP, propertyName); + Visibility visibility = shouldIgnoreTarget(declaringClassJIP, propertyName, Visibility.EXPOSED); if (visibility != Visibility.UNSET) { return visibility; diff --git a/extension-jaxrs/src/test/java/io/smallrye/openapi/runtime/scanner/JsonViewTests.java b/extension-jaxrs/src/test/java/io/smallrye/openapi/runtime/scanner/JsonViewTests.java index 0b4a7131e..0b69795f2 100644 --- a/extension-jaxrs/src/test/java/io/smallrye/openapi/runtime/scanner/JsonViewTests.java +++ b/extension-jaxrs/src/test/java/io/smallrye/openapi/runtime/scanner/JsonViewTests.java @@ -20,6 +20,7 @@ import org.jboss.jandex.Index; import org.junit.jupiter.api.Test; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonView; @@ -132,6 +133,9 @@ class Abridged { @Schema(name = "Role") class Role { + @JsonIgnore + protected java.util.logging.Logger logger; + @JsonView(Views.Full.class) private UUID id; @JsonView(Views.Ingest.class)