Skip to content

Commit 42af609

Browse files
committed
openapi: work in progress
1 parent 5f82cbc commit 42af609

File tree

4 files changed

+30
-9
lines changed

4 files changed

+30
-9
lines changed

modules/jooby-openapi/src/main/java/io/jooby/internal/openapi/AnnotationParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ public static List<OperationExt> parse(ParserContext ctx, String prefix, Type ty
281281
try {
282282
var className = operationExt.getControllerName();
283283
javadocParser
284-
.parseMvc(toJavaPath(className))
284+
.parse(toJavaPath(className))
285285
.ifPresent(
286286
doc -> {
287287
operationExt.setPathDescription(doc.getDescription());

modules/jooby-openapi/src/main/java/io/jooby/internal/openapi/javadoc/JavaDocParser.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,23 @@ public class JavaDocParser {
1919
private static final Predicate<DetailAST> HAS_CLASS =
2020
it -> backward(it).anyMatch(tokens(TokenTypes.CLASS_DEF));
2121

22-
private static final Predicate<DetailAST> STATEMENT_LIST =
23-
it -> backward(it).anyMatch(tokens(TokenTypes.SLIST));
22+
private static final Predicate<DetailAST> SINGLE_LINE_COMMENT =
23+
it -> backward(it).anyMatch(tokens(TokenTypes.SINGLE_LINE_COMMENT));
2424

2525
private final JavaDocContext context;
2626

2727
public JavaDocParser(JavaDocContext context) {
2828
this.context = context;
2929
}
3030

31-
public Optional<ClassDoc> parseMvc(Path filePath) throws Exception {
31+
public Optional<ClassDoc> parse(Path filePath) throws Exception {
3232
ClassDoc result = null;
3333
var tree = context.resolve(filePath);
3434
for (var comment :
3535
forward(tree)
3636
.filter(tokens(TokenTypes.COMMENT_CONTENT))
3737
.filter(HAS_CLASS)
38-
.filter(STATEMENT_LIST.negate())
38+
.filter(SINGLE_LINE_COMMENT.negate())
3939
.toList()) {
4040
var classOrMethod = classOrMethod(comment);
4141
if (classOrMethod.getType() == TokenTypes.METHOD_DEF) {

modules/jooby-openapi/src/test/java/javadoc/JavaDocParserTest.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,13 @@ public void apiDoc() throws Exception {
9595

9696
@Test
9797
public void ignoreStatementComment() throws Exception {
98-
var result = newParser().parseMvc(Paths.get("issues", "i1580", "Controller1580.java"));
98+
var result = newParser().parse(Paths.get("issues", "i1580", "Controller1580.java"));
9999
assertTrue(result.isEmpty());
100100
}
101101

102102
@Test
103103
public void noDoc() throws Exception {
104-
var result = newParser().parseMvc(Paths.get("javadoc", "input", "NoDoc.java"));
104+
var result = newParser().parse(Paths.get("javadoc", "input", "NoDoc.java"));
105105
assertTrue(result.isEmpty());
106106
}
107107

@@ -124,6 +124,25 @@ public void noClassDoc() throws Exception {
124124
});
125125
}
126126

127+
@Test
128+
public void shouldParseBean() throws Exception {
129+
withDoc(
130+
Paths.get("javadoc", "input", "QueryBeanDoc.java"),
131+
doc -> {
132+
assertNull(doc.getSummary());
133+
assertNull(doc.getDescription());
134+
135+
withMethod(
136+
doc,
137+
"hello",
138+
List.of("String"),
139+
methodDoc -> {
140+
assertEquals("Method Doc.", methodDoc.getSummary());
141+
assertNull(methodDoc.getDescription());
142+
});
143+
});
144+
}
145+
127146
private JavaDocParser newParser() {
128147
return new JavaDocParser(new JavaDocContext(baseDir()));
129148
}
@@ -134,7 +153,7 @@ private Path baseDir() {
134153

135154
private void withDoc(Path path, Consumer<ClassDoc> consumer) throws Exception {
136155
try {
137-
var result = newParser().parseMvc(path);
156+
var result = newParser().parse(path);
138157
assertFalse(result.isEmpty());
139158
consumer.accept(result.get());
140159
} catch (Throwable cause) {

modules/jooby-openapi/src/test/java/javadoc/input/ApiDoc.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
public class ApiDoc {
2323

2424
/**
25-
* This is the Hello <code>/endpoint</code> Operation description
25+
* This is the Hello <code>/endpoint</code>
26+
*
27+
* <p>Operation description
2628
*
2729
* @param name Person name.
2830
* @param age Person age.

0 commit comments

Comments
 (0)