|
52 | 52 | import io.micronaut.inject.ast.GenericPlaceholderElement;
|
53 | 53 | import io.micronaut.inject.ast.MemberElement;
|
54 | 54 | import io.micronaut.inject.ast.PropertyElement;
|
| 55 | +import io.micronaut.inject.ast.PropertyElementQuery; |
55 | 56 | import io.micronaut.inject.ast.TypedElement;
|
56 | 57 | import io.micronaut.inject.ast.WildcardElement;
|
57 | 58 | import io.micronaut.inject.visitor.VisitorContext;
|
@@ -1485,9 +1486,19 @@ private static void populateSchemaProperties(OpenAPI openAPI, VisitorContext con
|
1485 | 1486 | if (classElement != null && !ClassUtils.isJavaLangType(classElement.getName())) {
|
1486 | 1487 | List<PropertyElement> beanProperties;
|
1487 | 1488 | try {
|
1488 |
| - beanProperties = classElement.getBeanProperties().stream() |
1489 |
| - .filter(p -> !"groovy.lang.MetaClass".equals(p.getType().getName())) |
1490 |
| - .toList(); |
| 1489 | + beanProperties = classElement.getBeanProperties( |
| 1490 | + PropertyElementQuery.of(classElement) |
| 1491 | + .excludedAnnotations(Set.of( |
| 1492 | + Hidden.class.getName(), |
| 1493 | + JsonIgnore.class.getName() |
| 1494 | + )) |
| 1495 | + ).stream() |
| 1496 | + .filter(p -> |
| 1497 | + !"groovy.lang.MetaClass".equals(p.getType().getName()) |
| 1498 | + && !"java.lang.Class".equals(p.getType().getName()) |
| 1499 | + && !getAnnotationMetadata(p).booleanValue(io.swagger.v3.oas.annotations.media.Schema.class, PROP_HIDDEN).orElse(false) |
| 1500 | + ) |
| 1501 | + .toList(); |
1491 | 1502 | } catch (Exception e) {
|
1492 | 1503 | warn("Error with getting properties for class " + classElement.getName() + ": " + e + "\n" + Utils.printStackTrace(e), context, classElement);
|
1493 | 1504 | // Workaround for https://github.com/micronaut-projects/micronaut-openapi/issues/313
|
@@ -2298,12 +2309,7 @@ private static void processPropertyElements(OpenAPI openAPI, VisitorContext cont
|
2298 | 2309 | }
|
2299 | 2310 |
|
2300 | 2311 | for (TypedElement publicField : publicFields) {
|
2301 |
| - boolean isHidden = getAnnotationMetadata(publicField).booleanValue(io.swagger.v3.oas.annotations.media.Schema.class, PROP_HIDDEN).orElse(false); |
2302 |
| - var jsonAnySetterAnn = getAnnotation(publicField, JsonAnySetter.class); |
2303 |
| - if (isAnnotationPresent(publicField, JsonIgnore.class) |
2304 |
| - || isAnnotationPresent(publicField, Hidden.class) |
2305 |
| - || (jsonAnySetterAnn != null && jsonAnySetterAnn.booleanValue("enabled").orElse(true)) |
2306 |
| - || isHidden) { |
| 2312 | + if (isHiddenElement(publicField)) { |
2307 | 2313 | continue;
|
2308 | 2314 | }
|
2309 | 2315 |
|
@@ -2353,6 +2359,17 @@ private static void processPropertyElements(OpenAPI openAPI, VisitorContext cont
|
2353 | 2359 | }
|
2354 | 2360 | }
|
2355 | 2361 |
|
| 2362 | + private static boolean isHiddenElement(TypedElement elementType) { |
| 2363 | + boolean isHidden = getAnnotationMetadata(elementType) |
| 2364 | + .booleanValue(io.swagger.v3.oas.annotations.media.Schema.class, PROP_HIDDEN).orElse(false); |
| 2365 | + var jsonAnySetterAnn = getAnnotation(elementType, JsonAnySetter.class); |
| 2366 | + return elementType.getType().isAssignable(Class.class) |
| 2367 | + || isAnnotationPresent(elementType, JsonIgnore.class) |
| 2368 | + || isAnnotationPresent(elementType, Hidden.class) |
| 2369 | + || (jsonAnySetterAnn != null && jsonAnySetterAnn.booleanValue("enabled").orElse(true)) |
| 2370 | + || isHidden; |
| 2371 | + } |
| 2372 | + |
2356 | 2373 | private static boolean allowedByJsonView(TypedElement publicField, String[] classLvlJsonViewClasses, ClassElement jsonViewClassEl, VisitorContext context) {
|
2357 | 2374 | String[] fieldJsonViewClasses = getAnnotationMetadata(publicField).stringValues(JsonView.class);
|
2358 | 2375 | if (ArrayUtils.isEmpty(fieldJsonViewClasses)) {
|
|
0 commit comments