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

Commit e2bbcde

Browse files
committed
ApiTool: add support for @apioperation swagger annotation fix jooby-project#1100
1 parent ee6cede commit e2bbcde

File tree

9 files changed

+514
-59
lines changed

9 files changed

+514
-59
lines changed

doc/doc/apitool/apitool.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,9 @@ It is possible to customize Swagger/RAML objects:
284284
285285
This option is required when you want to customize/complement Swagger/RAML objects.
286286
287+
288+
For <a href="https://swagger.io/">Swagger</a> you can annotated your controller methods with `ApiOperation` and/or `ApiResponse` annotations. These annotations modifies the <a href="https://swagger.io/">Swagger</a> output.
289+
287290
# starter project
288291
289292
We do provide an [apitool-starter](https://github.com/jooby-project/apitool-starter) project.

jooby/src/main/java/org/jooby/Route.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -736,8 +736,7 @@ default T excludes(final String... excludes) {
736736
* @author edgar
737737
* @deprecated Replaced by {@link Router#path(String, Runnable)}.
738738
*/
739-
@Deprecated
740-
class Group implements Props<Group> {
739+
@Deprecated class Group implements Props<Group> {
741740

742741
/** List of definitions. */
743742
private List<Route.Definition> routes = new ArrayList<>();
@@ -1577,6 +1576,10 @@ private boolean valid(final Object value) {
15771576
if (value.getClass().isArray()) {
15781577
return valid(Array.get(value, 0));
15791578
}
1579+
if (value instanceof Map && ((Map) value).size() > 0) {
1580+
Map.Entry e = (Map.Entry) ((Map) value).entrySet().iterator().next();
1581+
return valid(e.getKey()) && valid(e.getValue());
1582+
}
15801583
return false;
15811584
}
15821585

jooby/src/main/java/org/jooby/internal/mvc/MvcRoutes.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@
209209
import org.jooby.MediaType;
210210
import org.jooby.Route;
211211
import org.jooby.Route.Definition;
212+
import org.jooby.funzy.Try;
212213
import org.jooby.internal.RouteMetadata;
213214
import org.jooby.mvc.CONNECT;
214215
import org.jooby.mvc.Consumes;
@@ -222,10 +223,10 @@
222223
import org.jooby.mvc.Path;
223224
import org.jooby.mvc.Produces;
224225
import org.jooby.mvc.TRACE;
225-
import org.jooby.funzy.Try;
226226

227227
import java.lang.annotation.Annotation;
228228
import java.lang.reflect.AnnotatedElement;
229+
import java.lang.reflect.Array;
229230
import java.lang.reflect.Method;
230231
import java.lang.reflect.Modifier;
231232
import java.util.ArrayList;
@@ -311,7 +312,8 @@ public static List<Route.Definition> routes(final Env env, final RouteMetadata c
311312
String[] excludes = excludes(method, rootExcludes);
312313

313314
Definition definition = new Route.Definition(
314-
verb.getSimpleName(), rpath + "/" + path, new MvcHandler(method, routeClass, paramProvider), caseSensitiveRouting)
315+
verb.getSimpleName(), rpath + "/" + path,
316+
new MvcHandler(method, routeClass, paramProvider), caseSensitiveRouting)
315317
.produces(produces)
316318
.consumes(consumes)
317319
.excludes(excludes)
@@ -369,7 +371,18 @@ private static Map<String, Object> attrs(final Annotation annotation) {
369371
Method[] attrs = annotation.annotationType().getDeclaredMethods();
370372
for (Method attr : attrs) {
371373
Try.apply(() -> attr.invoke(annotation))
372-
.onSuccess(value -> result.put(attrName(annotation, attr), value));
374+
.onSuccess(value -> {
375+
if (value.getClass().isArray() && Annotation.class
376+
.isAssignableFrom(value.getClass().getComponentType())) {
377+
List<Map<String, Object>> array = new ArrayList<>();
378+
for(int i = 0; i < Array.getLength(value); i ++) {
379+
array.add(attrs((Annotation) Array.get(value, i)));
380+
}
381+
result.put(attrName(annotation, attr), array.toArray());
382+
} else {
383+
result.put(attrName(annotation, attr), value);
384+
}
385+
});
373386
}
374387
}
375388
return result;

modules/coverage-report/src/test/java/org/jooby/issues/Issue131.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public class Issue131 extends ServerFeature {
77

88
{
99

10-
assets("/swagger/ui/**", "/META-INF/resources/webjars/swagger-ui/3.9.3/{0}");
10+
assets("/swagger/ui/**", "/META-INF/resources/webjars/swagger-ui/3.14.2/{0}");
1111

1212
}
1313

@@ -16,6 +16,6 @@ public void largeFileFromInputStream() throws Exception {
1616
request()
1717
.get("/swagger/ui/swagger-ui.js")
1818
.expect(200)
19-
.header("Content-Length", 349262);
19+
.header("Content-Length", 366799);
2020
}
2121
}

0 commit comments

Comments
 (0)