Skip to content
This repository was archived by the owner on Mar 3, 2026. It is now read-only.

Commit 8be6dfd

Browse files
committed
MVC routes fail to show description in Swagger & RAML docs if class contains @Inject-annotated constructor declared before the route methods. fix jooby-project#1059
1 parent bcbd615 commit 8be6dfd

File tree

5 files changed

+97
-9
lines changed

5 files changed

+97
-9
lines changed

modules/jooby-apitool/src/main/antlr4/org/jooby/internal/apitool/javadoc/FuzzyDoc.g4

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ route: doc=DOC 'route' '(' pattern=STRING ')' scripts;
1717

1818
scripts: '{' (scripts | script | .)*? '}';
1919

20-
clazz: doc=DOC annotations+=annotation+ (isClass='class'|.)*? '{' classBody '}';
20+
clazz: doc=DOC? annotations+=annotation+ (isClass='class'|.)*? classBody;
2121

22-
classBody: (mvcRoute | .)*?;
22+
classBody: '{' (classBody | mvcRoute | .)*? '}';
2323

2424
script:
2525
doc=DOC dot='.'? method=METHOD kotlinScriptBody

modules/jooby-apitool/src/main/java/org/jooby/internal/apitool/DocParser.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -394,17 +394,21 @@ private String summary() {
394394
boolean isClass = ctx.isClass != null;
395395
if (isClass) {
396396
this.prefix.addLast(normalize(pattern));
397-
this.summary.addLast(cleanJavadoc(file, ctx.doc.getText()));
397+
if (ctx.doc != null) {
398+
this.summary.addLast(cleanJavadoc(file, ctx.doc.getText()));
399+
}
398400
} else {
399401
popPrefix();
400402
popSummary();
401403
List<String> methods = methods(ctx.annotations);
402-
String comment = ctx.doc.getText();
403-
if (methods.size() == 0) {
404-
doc.add(doc("get", normalize(pattern), file, summary(), comment));
405-
} else {
406-
methods.stream()
407-
.forEach(it -> doc.add(doc(it, normalize(pattern), file, summary(), comment)));
404+
if (ctx.doc != null) {
405+
String comment = ctx.doc.getText();
406+
if (methods.size() == 0) {
407+
doc.add(doc("get", normalize(pattern), file, summary(), comment));
408+
} else {
409+
methods.stream()
410+
.forEach(it -> doc.add(doc(it, normalize(pattern), file, summary(), comment)));
411+
}
408412
}
409413
}
410414
} else {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package apps;
2+
3+
import org.jooby.Jooby;
4+
5+
public class App1059 extends Jooby {
6+
7+
{
8+
use(Controller1059.class);
9+
}
10+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package apps;
2+
3+
import org.jooby.mvc.GET;
4+
import org.jooby.mvc.Path;
5+
6+
import javax.inject.Inject;
7+
8+
/**
9+
* Top level comment.
10+
*/
11+
@Path("/test")
12+
public class Controller1059 {
13+
14+
@Inject
15+
public Controller1059() {
16+
}
17+
18+
/**
19+
* Say hi.
20+
* @return Hi.
21+
*/
22+
@GET
23+
public String salute() {
24+
return "Hi";
25+
}
26+
27+
/**
28+
* Say X.
29+
* @return Hi.
30+
*/
31+
@GET
32+
@Path("/x")
33+
public String salutex() {
34+
return "Hi";
35+
}
36+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package org.jooby.apitool;
2+
3+
import apps.App1059;
4+
import org.junit.Test;
5+
6+
import java.nio.file.Path;
7+
import java.nio.file.Paths;
8+
9+
public class Issue1059 {
10+
11+
@Test
12+
public void topLevelDescriptionShouldWorkWhenAnnotatedContructorIsPresent() throws Exception {
13+
new RouteMethodAssert(new ApiParser(dir()).parseFully(new App1059()))
14+
.next(r -> {
15+
r.returnType(String.class);
16+
r.pattern("/test");
17+
r.method("GET");
18+
r.description("Say hi.");
19+
r.summary("Top level comment.");
20+
})
21+
.next(r -> {
22+
r.returnType(String.class);
23+
r.pattern("/test/x");
24+
r.method("GET");
25+
r.description("Say X.");
26+
r.summary("Top level comment.");
27+
})
28+
.done();
29+
}
30+
31+
private Path dir() {
32+
Path userdir = Paths.get(System.getProperty("user.dir"));
33+
if (!userdir.toString().endsWith("jooby-apitool")) {
34+
userdir = userdir.resolve("modules").resolve("jooby-apitool");
35+
}
36+
return userdir;
37+
}
38+
}

0 commit comments

Comments
 (0)