From 16306443afaa1820b38b26dd546515e1c85743d0 Mon Sep 17 00:00:00 2001 From: Michael Edgar Date: Mon, 23 Sep 2024 12:56:11 -0400 Subject: [PATCH] Improve logging when type args do not match params, type parse trim (#1993) Signed-off-by: Michael Edgar --- .../runtime/scanner/dataobject/DataObjectLogging.java | 9 +++------ .../openapi/runtime/scanner/dataobject/TypeResolver.java | 4 +++- .../io/smallrye/openapi/runtime/util/TypeParser.java | 3 +++ 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/io/smallrye/openapi/runtime/scanner/dataobject/DataObjectLogging.java b/core/src/main/java/io/smallrye/openapi/runtime/scanner/dataobject/DataObjectLogging.java index e02172aed..fd8568004 100644 --- a/core/src/main/java/io/smallrye/openapi/runtime/scanner/dataobject/DataObjectLogging.java +++ b/core/src/main/java/io/smallrye/openapi/runtime/scanner/dataobject/DataObjectLogging.java @@ -1,13 +1,10 @@ package io.smallrye.openapi.runtime.scanner.dataobject; -import java.util.List; - import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.ClassInfo; import org.jboss.jandex.DotName; import org.jboss.jandex.ParameterizedType; import org.jboss.jandex.Type; -import org.jboss.jandex.TypeVariable; import org.jboss.logging.BasicLogger; import org.jboss.logging.Logger; import org.jboss.logging.annotations.LogMessage; @@ -83,9 +80,9 @@ interface DataObjectLogging extends BasicLogger { void classNotAvailable(Type type); @LogMessage(level = Logger.Level.ERROR) - @Message(id = 31016, value = "Unanticipated mismatch between type arguments and type variables \n" + - "Args: %s\n Vars:%s") - void classNotAvailable(List typeVariables, List arguments); + @Message(id = 31016, value = "Unanticipated mismatch between type arguments and type variables declared on class\n" + + "Class: %s\nType: %s") + void classNotAvailable(String classDeclaration, String typeSignature); @LogMessage(level = Logger.Level.WARN) @Message(id = 31017, value = "Failed to read enumeration values from enum %s method %s with `@JsonValue`: %s") diff --git a/core/src/main/java/io/smallrye/openapi/runtime/scanner/dataobject/TypeResolver.java b/core/src/main/java/io/smallrye/openapi/runtime/scanner/dataobject/TypeResolver.java index 52b9106b8..b80a47162 100644 --- a/core/src/main/java/io/smallrye/openapi/runtime/scanner/dataobject/TypeResolver.java +++ b/core/src/main/java/io/smallrye/openapi/runtime/scanner/dataobject/TypeResolver.java @@ -1147,7 +1147,9 @@ private static Map buildParamTypeResolutionMap(ClassInfo klazz, Pa List arguments = parameterizedType.arguments(); if (arguments.size() != typeVariables.size()) { - DataObjectLogging.logger.classNotAvailable(typeVariables, arguments); + String vars = typeVariables.stream().map(TypeVariable::toString).collect(Collectors.joining(", ")); + DataObjectLogging.logger.classNotAvailable(klazz.name() + "<" + vars + ">", parameterizedType.toString()); + return Collections.emptyMap(); } Map resolutionMap = new LinkedHashMap<>(); diff --git a/core/src/main/java/io/smallrye/openapi/runtime/util/TypeParser.java b/core/src/main/java/io/smallrye/openapi/runtime/util/TypeParser.java index e825f1ed8..9653e3762 100644 --- a/core/src/main/java/io/smallrye/openapi/runtime/util/TypeParser.java +++ b/core/src/main/java/io/smallrye/openapi/runtime/util/TypeParser.java @@ -172,6 +172,9 @@ private int advanceNot(char c) { } private DotName parseName() { + while (Character.isWhitespace(signature.charAt(pos))) { + pos++; + } int start = pos; int end = advanceNameEnd(); return DotName.createSimple(signature.substring(start, end));