|
17 | 17 | import io.jooby.annotations.Path; |
18 | 18 | import io.jooby.annotations.PathParam; |
19 | 19 | import io.jooby.annotations.QueryParam; |
| 20 | +import io.swagger.v3.oas.annotations.Hidden; |
| 21 | +import io.swagger.v3.oas.annotations.Operation; |
20 | 22 | import io.swagger.v3.oas.models.media.Content; |
21 | 23 | import io.swagger.v3.oas.models.media.ObjectSchema; |
22 | 24 | import io.swagger.v3.oas.models.media.Schema; |
|
49 | 51 | import java.util.stream.Collectors; |
50 | 52 | import java.util.stream.Stream; |
51 | 53 |
|
52 | | -import static io.jooby.internal.openapi.AsmUtils.findAnnotationByType; |
| 54 | +import static io.jooby.internal.openapi.AsmUtils.*; |
53 | 55 | import static io.jooby.internal.openapi.TypeFactory.KT_FUN_0; |
54 | 56 | import static io.jooby.internal.openapi.TypeFactory.KT_KLASS; |
55 | 57 | import static java.util.Collections.singletonList; |
@@ -236,6 +238,11 @@ private static List<OperationExt> routerMethod(ParserContext ctx, String prefix, |
236 | 238 | List<ParameterExt> arguments = routerArguments(ctx, method, requestBody::set); |
237 | 239 | ResponseExt response = returnTypes(method); |
238 | 240 |
|
| 241 | + // If the method is hidden, don't generate an operation for it |
| 242 | + if (isHidden(method.visibleAnnotations)) { |
| 243 | + return result; |
| 244 | + } |
| 245 | + |
239 | 246 | for (String httpMethod : httpMethod(method.visibleAnnotations)) { |
240 | 247 | for (String pattern : httpPattern(ctx, classNode, method, httpMethod)) { |
241 | 248 | OperationExt operation = new OperationExt( |
@@ -266,6 +273,24 @@ private static boolean isDeprecated(List<AnnotationNode> annotations) { |
266 | 273 | return false; |
267 | 274 | } |
268 | 275 |
|
| 276 | + private static boolean isHidden(List<AnnotationNode> annotations) { |
| 277 | + if (annotations != null) { |
| 278 | + // If the method is annotated with @Hidden, it's always hidden |
| 279 | + boolean hiddenAnnotationExists = annotations.stream() |
| 280 | + .anyMatch(a -> a.desc.equals(Type.getDescriptor(Hidden.class))); |
| 281 | + |
| 282 | + if (hiddenAnnotationExists) { |
| 283 | + return true; |
| 284 | + } |
| 285 | + |
| 286 | + // If the method is annotated with @Operation, and the value of "hidden" is true, it's hidden |
| 287 | + return findAnnotationByType(annotations, Operation.class) |
| 288 | + .stream() |
| 289 | + .anyMatch(it -> boolValue(toMap(it), "hidden")); |
| 290 | + } |
| 291 | + return false; |
| 292 | + } |
| 293 | + |
269 | 294 | private static ResponseExt returnTypes(MethodNode method) { |
270 | 295 | Signature signature = Signature.create(method); |
271 | 296 | String desc = Optional.ofNullable(method.signature).orElse(method.desc); |
|
0 commit comments