Repository: jooby-project/jooby
Pull request #3413 (2024-04-18 20:07:39)

Fix/openapi nonnull issue
Closes https://github.com/jooby-project/jooby/issues/3412   
For some reason `method.invisibleParameterAnnotations` contains `null` entries. It looks like ASM issue? I'm not good at it. But a dumb fix is here.



Patch:
diff --git a/modules/jooby-openapi/src/main/java/io/jooby/internal/openapi/AnnotationParser.java b/modules/jooby-openapi/src/main/java/io/jooby/internal/openapi/AnnotationParser.java
index d9dc17f67..3c7a7b617 100644
--- a/modules/jooby-openapi/src/main/java/io/jooby/internal/openapi/AnnotationParser.java
+++ b/modules/jooby-openapi/src/main/java/io/jooby/internal/openapi/AnnotationParser.java
@@ -451,8 +451,10 @@ public class AnnotationParser {
   private static boolean isNullable(MethodNode method, int paramIndex) {
     if (paramIndex < method.invisibleAnnotableParameterCount) {
       List<AnnotationNode> annotations = method.invisibleParameterAnnotations[paramIndex];
-      return annotations.stream()
-          .anyMatch(a -> a.desc.equals("Lorg/jetbrains/annotations/Nullable;"));
+      if (annotations != null) {
+        return annotations.stream()
+                .anyMatch(a -> a.desc.equals("Lorg/jetbrains/annotations/Nullable;"));
+      }
     }
     return true;
   }


Test patch:
diff --git a/modules/jooby-openapi/src/test/java/issues/i3412/App3412.java b/modules/jooby-openapi/src/test/java/issues/i3412/App3412.java
new file mode 100644
index 000000000..a2d768300
--- /dev/null
+++ b/modules/jooby-openapi/src/test/java/issues/i3412/App3412.java
@@ -0,0 +1,27 @@
+package issues.i3412;
+
+import edu.umd.cs.findbugs.annotations.NonNull;
+import io.jooby.Jooby;
+import io.jooby.OpenAPIModule;
+import io.jooby.annotation.GET;
+import io.jooby.annotation.Path;
+import io.jooby.annotation.QueryParam;
+
+public class App3412 extends Jooby {
+
+    @Path("/")
+    static class Controller {
+
+        @GET("/welcome")
+        public String sayHi(@QueryParam @NonNull String greeting, @QueryParam String language) {
+            return "hi";
+        }
+    }
+
+    {
+        install(new OpenAPIModule());
+
+        mvc(new Controller());
+
+    }
+}
diff --git a/modules/jooby-openapi/src/test/java/issues/i3412/Issue3412.java b/modules/jooby-openapi/src/test/java/issues/i3412/Issue3412.java
new file mode 100644
index 000000000..4c02b7151
--- /dev/null
+++ b/modules/jooby-openapi/src/test/java/issues/i3412/Issue3412.java
@@ -0,0 +1,42 @@
+package issues.i3412;
+
+import io.jooby.openapi.OpenAPIResult;
+import io.jooby.openapi.OpenAPITest;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class Issue3412 {
+
+  @OpenAPITest(value = App3412.class)
+  public void shouldParseNonnullQueryParameter(OpenAPIResult result) {
+    assertEquals("""
+              openapi: 3.0.1
+              info:
+                title: 3412 API
+                description: 3412 API description
+                version: "1.0"
+              paths:
+                /welcome:
+                  get:
+                    operationId: sayHi
+                    parameters:
+                    - name: greeting
+                      in: query
+                      required: true
+                      schema:
+                        type: string
+                    - name: language
+                      in: query
+                      schema:
+                        type: string
+                    responses:
+                      "200":
+                        description: Success
+                        content:
+                          application/json:
+                            schema:
+                              type: string
+                                  """,
+        result.toYaml());
+  }
+}