From 5a2bbae0537bc0b595fc2cecb262f68e1d7a622f Mon Sep 17 00:00:00 2001 From: Phillip Kruger Date: Wed, 18 Oct 2023 13:07:24 +1100 Subject: [PATCH] More changes to default content type Signed-off-by: Phillip Kruger --- .../openapi/api/constants/JDKConstants.java | 2 ++ .../scanner/spi/AbstractAnnotationScanner.java | 17 ++++++++++++++--- .../smallrye/openapi/runtime/util/TypeUtil.java | 2 ++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/io/smallrye/openapi/api/constants/JDKConstants.java b/core/src/main/java/io/smallrye/openapi/api/constants/JDKConstants.java index 9c4d0ac02..3afb50f61 100644 --- a/core/src/main/java/io/smallrye/openapi/api/constants/JDKConstants.java +++ b/core/src/main/java/io/smallrye/openapi/api/constants/JDKConstants.java @@ -8,6 +8,7 @@ import java.util.OptionalInt; import java.util.OptionalLong; import java.util.Set; +import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionStage; import org.jboss.jandex.DotName; @@ -27,6 +28,7 @@ public class JDKConstants { public static final DotName DOTNAME_OPTIONAL_INT = DotName.createSimple(OptionalInt.class.getName()); public static final DotName DOTNAME_OPTIONAL_LONG = DotName.createSimple(OptionalLong.class.getName()); public static final DotName COMPLETION_STAGE_NAME = DotName.createSimple(CompletionStage.class.getName()); + public static final DotName COMPLETABLE_STAGE_NAME = DotName.createSimple(CompletableFuture.class.getName()); public static final Set DOTNAME_OPTIONALS = Collections .unmodifiableSet(new HashSet<>(Arrays.asList(DOTNAME_OPTIONAL, diff --git a/core/src/main/java/io/smallrye/openapi/runtime/scanner/spi/AbstractAnnotationScanner.java b/core/src/main/java/io/smallrye/openapi/runtime/scanner/spi/AbstractAnnotationScanner.java index e38b5400c..ade0f91c3 100644 --- a/core/src/main/java/io/smallrye/openapi/runtime/scanner/spi/AbstractAnnotationScanner.java +++ b/core/src/main/java/io/smallrye/openapi/runtime/scanner/spi/AbstractAnnotationScanner.java @@ -116,8 +116,19 @@ public String[] getDefaultProduces(AnnotationScannerContext context, MethodInfo } private boolean isPrimimive(Type type) { - return type.kind().equals(Type.Kind.PRIMITIVE) - || type.name().equals(DotName.createSimple(String.class)) - || (TypeUtil.isWrappedType(type) && isPrimimive(TypeUtil.unwrapType(type))); + if (type != null) { + return type.kind().equals(Type.Kind.PRIMITIVE) + || type.name().equals(DotName.createSimple(String.class)) + || type.name().equals(DotName.createSimple(Integer.class)) + || type.name().equals(DotName.createSimple(Short.class)) + || type.name().equals(DotName.createSimple(Long.class)) + || type.name().equals(DotName.createSimple(Float.class)) + || type.name().equals(DotName.createSimple(Double.class)) + || type.name().equals(DotName.createSimple(Boolean.class)) + || type.name().equals(DotName.createSimple(Character.class)) + || (isWrapperType(type) && isPrimimive(unwrapType(type))) + || (TypeUtil.isWrappedType(type) && isPrimimive(TypeUtil.unwrapType(type))); + } + return false; } } diff --git a/core/src/main/java/io/smallrye/openapi/runtime/util/TypeUtil.java b/core/src/main/java/io/smallrye/openapi/runtime/util/TypeUtil.java index 93e3a7716..a2514bb45 100644 --- a/core/src/main/java/io/smallrye/openapi/runtime/util/TypeUtil.java +++ b/core/src/main/java/io/smallrye/openapi/runtime/util/TypeUtil.java @@ -309,6 +309,8 @@ public class TypeUtil { wrapperTypes.addAll(JaxbConstants.JAXB_ELEMENT); wrapperTypes.add(MutinyConstants.UNI_TYPE.name()); + wrapperTypes.add(JDKConstants.COMPLETION_STAGE_NAME); + wrapperTypes.add(JDKConstants.COMPLETABLE_STAGE_NAME); } private static void indexOptional(Indexer indexer, String className, ClassLoader contextLoader) {