GERONIMO-6690 ensure no subtring index issue when @Path(/) is used at class level
authorRomain Manni-Bucau <rmannibucau@gmail.com>
Wed, 23 Jan 2019 15:20:36 +0000 (16:20 +0100)
committerRomain Manni-Bucau <rmannibucau@gmail.com>
Wed, 23 Jan 2019 15:20:36 +0000 (16:20 +0100)
geronimo-openapi-impl/src/main/java/org/apache/geronimo/microprofile/openapi/impl/processor/AnnotationProcessor.java
geronimo-openapi-impl/src/test/java/org/apache/geronimo/microprofile/openapi/impl/processor/AnnotationProcessorTest.java

index b691b7f..bd9bb9b 100644 (file)
@@ -475,7 +475,7 @@ public class AnnotationProcessor {
 
     private String buildPath(final String base, final Path path, final Path mtdPath) {
         return Stream.concat(Stream.of(base), Stream.of(path, mtdPath).filter(Objects::nonNull).map(Path::value))
-                .map(v -> v.substring(v.startsWith("/") ? 1 : 0, v.endsWith("/") ? v.length() - 1 : v.length()))
+                .map(v -> v.substring(v.startsWith("/") && !"/".equalsIgnoreCase(v) ? 1 : 0, v.endsWith("/") ? v.length() - 1 : v.length()))
                 .filter(it -> !it.isEmpty())
                 .collect(joining("/", "/", ""));
     }
index 592d562..ff09a7d 100644 (file)
@@ -72,6 +72,26 @@ public class AnnotationProcessorTest {
         });
     }
 
+    @Test
+    public void rootPath() {
+        final AnnotationProcessor annotationProcessor = new AnnotationProcessor((value, def) -> null, new NamingStrategy.Default());
+        final OpenAPI openAPI = new OpenAPIImpl();
+        annotationProcessor.processClass("", openAPI, new ClassElement(RootPath.class),
+                Stream.of(RootPath.class.getMethods()).map(MethodElement::new));
+        assertNotNull(openAPI.getPaths().get("/{a}").getGET().getOperationId()); // we didn't get an index exception
+    }
+
+    @Path("/")
+    public class RootPath {
+
+        @GET
+        @Path("/{a}")
+        @Produces(MediaType.TEXT_PLAIN)
+        public String hello() {
+            return null;
+        }
+    }
+
     @Path("/test")
     public class TestResource {