Skip to content

Commit af302eb

Browse files
committed
Support Hidden methods and controllers
1 parent 5aac357 commit af302eb

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

src/main/java/io/dinject/javalin/generator/ControllerReader.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.dinject.javalin.generator;
22

33
import io.dinject.controller.Path;
4+
import io.swagger.v3.oas.annotations.Hidden;
45

56
import javax.lang.model.element.Element;
67
import javax.lang.model.element.ElementKind;
@@ -30,29 +31,35 @@ class ControllerReader {
3031

3132
private final Set<String> importTypes = new TreeSet<>();
3233

33-
// private final String docComment;
34+
private boolean docHidden;
3435

3536
ControllerReader(TypeElement beanType, ProcessingContext ctx) {
3637
this.beanType = beanType;
3738
this.ctx = ctx;
38-
// this.docComment = ctx.getDocComment(beanType);
3939
this.roles = Util.findRoles(beanType);
4040
if (ctx.isGeneratedAvailable()) {
4141
importTypes.add(Constants.GENERATED);
4242
}
43+
if (ctx.isOpenApiAvailable()) {
44+
docHidden = isDocHidden(beanType);
45+
}
4346
importTypes.add(Constants.SINGLETON);
4447
importTypes.add(Constants.API_BUILDER);
4548
importTypes.add(Constants.IMPORT_CONTROLLER);
4649
importTypes.add(beanType.getQualifiedName().toString());
4750
}
4851

52+
private boolean isDocHidden(TypeElement beanType) {
53+
return beanType.getAnnotation(Hidden.class) != null;
54+
}
55+
4956
TypeElement getBeanType() {
5057
return beanType;
5158
}
5259

53-
// String getDocComment() {
54-
// return docComment;
55-
// }
60+
boolean isDocHidden() {
61+
return docHidden;
62+
}
5663

5764
void read() {
5865
if (!roles.isEmpty()) {

src/main/java/io/dinject/javalin/generator/ControllerRouteWriter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ private void writeAddRoutes() {
4646

4747
for (MethodReader method : reader.getMethods()) {
4848
method.addRoute(writer);
49-
method.addMeta(ctx);
49+
if (!reader.isDocHidden()) {
50+
method.addMeta(ctx);
51+
}
5052
}
5153

5254
writer.append(" }").eol().eol();

src/main/java/io/dinject/javalin/generator/MethodReader.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import io.dinject.controller.Post;
88
import io.dinject.controller.Put;
99
import io.dinject.javalin.generator.javadoc.Javadoc;
10+
import io.swagger.v3.oas.annotations.Hidden;
1011
import io.swagger.v3.oas.models.Operation;
1112
import io.swagger.v3.oas.models.PathItem;
1213
import io.swagger.v3.oas.models.Paths;
@@ -77,7 +78,7 @@ void read() {
7778

7879
public void addMeta(ProcessingContext ctx) {
7980

80-
if (webMethod != null) {
81+
if (webMethod != null && notHidden()) {
8182

8283
Paths paths = ctx.getOpenAPI().getPaths();
8384

@@ -91,7 +92,7 @@ public void addMeta(ProcessingContext ctx) {
9192
//operation.setOperationId();
9293
operation.setSummary(javadoc.getSummary());
9394
operation.setDescription(javadoc.getDescription());
94-
95+
9596
if (javadoc.isDeprecated()) {
9697
operation.setDeprecated(true);
9798
} else if (element.getAnnotation(Deprecated.class) != null) {
@@ -112,6 +113,12 @@ public void addMeta(ProcessingContext ctx) {
112113
}
113114
}
114115

116+
/**
117+
* Return true if the method is included in documentation.
118+
*/
119+
private boolean notHidden() {
120+
return !ctx.isOpenApiAvailable() || element.getAnnotation(Hidden.class) == null;
121+
}
115122

116123
void addRoute(Append writer) {
117124

0 commit comments

Comments
 (0)