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

Commit 3d2e299

Browse files
committed
Small improvements in doc, tests and code cleanup
1 parent dd2e889 commit 3d2e299

File tree

23 files changed

+557
-403
lines changed

23 files changed

+557
-403
lines changed

coverage-report/src/test/java/org/jooby/HelloFeature.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ public void hello() throws Exception {
2020
request()
2121
.get("/bye")
2222
.expect("bye!");
23+
24+
request()
25+
.get("/not-found")
26+
.expect(404);
2327
}
2428

2529
}

coverage-report/src/test/java/org/jooby/swagger/Pets.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import com.google.common.collect.Lists;
1616

17-
@Path("/pets")
17+
@Path("/api/pets")
1818
@Singleton
1919
public class Pets {
2020

coverage-report/src/test/java/org/jooby/swagger/SwaggerFeature.java

Lines changed: 130 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
public class SwaggerFeature extends ServerFeature {
77

88
{
9-
SwaggerUI.install(this);
10-
119
use(Pets.class);
10+
11+
new SwaggerUI().install(this);
1212
}
1313

1414
@Test
@@ -47,39 +47,69 @@ public void json() throws Exception {
4747
" \"consumes\" : [ \"application/json\" ],\n" +
4848
" \"produces\" : [ \"application/json\" ],\n" +
4949
" \"paths\" : {\n" +
50-
" \"/pets\" : {\n" +
50+
" \"/api/pets\" : {\n" +
5151
" \"get\" : {\n" +
5252
" \"tags\" : [ \"pets\" ],\n" +
53+
" \"consumes\" : [ \"*/*\" ],\n" +
54+
" \"produces\" : [ \"*/*\" ],\n" +
5355
" \"parameters\" : [ {\n" +
5456
" \"name\" : \"size\",\n" +
5557
" \"in\" : \"query\",\n" +
5658
" \"required\" : false,\n" +
5759
" \"type\" : \"integer\",\n" +
5860
" \"format\" : \"int32\"\n" +
59-
" } ]\n" +
61+
" } ],\n" +
62+
" \"responses\" : {\n" +
63+
" \"200\" : {\n" +
64+
" \"description\" : \"Success\",\n" +
65+
" \"schema\" : {\n" +
66+
" \"$ref\" : \"#/definitions/IterablePet\"\n" +
67+
" }\n" +
68+
" }\n" +
69+
" }\n" +
6070
" },\n" +
6171
" \"post\" : {\n" +
6272
" \"tags\" : [ \"pets\" ],\n" +
73+
" \"consumes\" : [ \"*/*\" ],\n" +
74+
" \"produces\" : [ \"*/*\" ],\n" +
6375
" \"parameters\" : [ {\n" +
6476
" \"in\" : \"body\",\n" +
6577
" \"name\" : \"pet\",\n" +
6678
" \"required\" : true,\n" +
6779
" \"schema\" : {\n" +
6880
" \"$ref\" : \"#/definitions/Pet\"\n" +
6981
" }\n" +
70-
" } ]\n" +
82+
" } ],\n" +
83+
" \"responses\" : {\n" +
84+
" \"200\" : {\n" +
85+
" \"description\" : \"Success\",\n" +
86+
" \"schema\" : {\n" +
87+
" \"$ref\" : \"#/definitions/Pet\"\n" +
88+
" }\n" +
89+
" }\n" +
90+
" }\n" +
7191
" }\n" +
7292
" },\n" +
73-
" \"/pets/{id}\" : {\n" +
93+
" \"/api/pets/{id}\" : {\n" +
7494
" \"get\" : {\n" +
7595
" \"tags\" : [ \"pets\" ],\n" +
96+
" \"consumes\" : [ \"*/*\" ],\n" +
97+
" \"produces\" : [ \"*/*\" ],\n" +
7698
" \"parameters\" : [ {\n" +
7799
" \"name\" : \"id\",\n" +
78100
" \"in\" : \"path\",\n" +
79101
" \"required\" : true,\n" +
80102
" \"type\" : \"integer\",\n" +
81103
" \"format\" : \"int32\"\n" +
82-
" } ]\n" +
104+
" } ],\n" +
105+
" \"responses\" : {\n" +
106+
" \"200\" : {\n" +
107+
" \"description\" : \"Success\",\n" +
108+
" \"schema\" : {\n" +
109+
" \"$ref\" : \"#/definitions/Pet\"\n" +
110+
" }\n" +
111+
" }\n" +
112+
" }\n" +
83113
" }\n" +
84114
" }\n" +
85115
" },\n" +
@@ -114,39 +144,69 @@ public void json() throws Exception {
114144
" \"consumes\" : [ \"application/json\" ],\n" +
115145
" \"produces\" : [ \"application/json\" ],\n" +
116146
" \"paths\" : {\n" +
117-
" \"/pets\" : {\n" +
147+
" \"/api/pets\" : {\n" +
118148
" \"get\" : {\n" +
119149
" \"tags\" : [ \"pets\" ],\n" +
150+
" \"consumes\" : [ \"*/*\" ],\n" +
151+
" \"produces\" : [ \"*/*\" ],\n" +
120152
" \"parameters\" : [ {\n" +
121153
" \"name\" : \"size\",\n" +
122154
" \"in\" : \"query\",\n" +
123155
" \"required\" : false,\n" +
124156
" \"type\" : \"integer\",\n" +
125157
" \"format\" : \"int32\"\n" +
126-
" } ]\n" +
158+
" } ],\n" +
159+
" \"responses\" : {\n" +
160+
" \"200\" : {\n" +
161+
" \"description\" : \"Success\",\n" +
162+
" \"schema\" : {\n" +
163+
" \"$ref\" : \"#/definitions/IterablePet\"\n" +
164+
" }\n" +
165+
" }\n" +
166+
" }\n" +
127167
" },\n" +
128168
" \"post\" : {\n" +
129169
" \"tags\" : [ \"pets\" ],\n" +
170+
" \"consumes\" : [ \"*/*\" ],\n" +
171+
" \"produces\" : [ \"*/*\" ],\n" +
130172
" \"parameters\" : [ {\n" +
131173
" \"in\" : \"body\",\n" +
132174
" \"name\" : \"pet\",\n" +
133175
" \"required\" : true,\n" +
134176
" \"schema\" : {\n" +
135177
" \"$ref\" : \"#/definitions/Pet\"\n" +
136178
" }\n" +
137-
" } ]\n" +
179+
" } ],\n" +
180+
" \"responses\" : {\n" +
181+
" \"200\" : {\n" +
182+
" \"description\" : \"Success\",\n" +
183+
" \"schema\" : {\n" +
184+
" \"$ref\" : \"#/definitions/Pet\"\n" +
185+
" }\n" +
186+
" }\n" +
187+
" }\n" +
138188
" }\n" +
139189
" },\n" +
140-
" \"/pets/{id}\" : {\n" +
190+
" \"/api/pets/{id}\" : {\n" +
141191
" \"get\" : {\n" +
142192
" \"tags\" : [ \"pets\" ],\n" +
193+
" \"consumes\" : [ \"*/*\" ],\n" +
194+
" \"produces\" : [ \"*/*\" ],\n" +
143195
" \"parameters\" : [ {\n" +
144196
" \"name\" : \"id\",\n" +
145197
" \"in\" : \"path\",\n" +
146198
" \"required\" : true,\n" +
147199
" \"type\" : \"integer\",\n" +
148200
" \"format\" : \"int32\"\n" +
149-
" } ]\n" +
201+
" } ],\n" +
202+
" \"responses\" : {\n" +
203+
" \"200\" : {\n" +
204+
" \"description\" : \"Success\",\n" +
205+
" \"schema\" : {\n" +
206+
" \"$ref\" : \"#/definitions/Pet\"\n" +
207+
" }\n" +
208+
" }\n" +
209+
" }\n" +
150210
" }\n" +
151211
" }\n" +
152212
" },\n" +
@@ -185,35 +245,62 @@ public void yml() throws Exception {
185245
"produces:\n" +
186246
"- \"application/json\"\n" +
187247
"paths:\n" +
188-
" /pets:\n" +
248+
" /api/pets:\n" +
189249
" get:\n" +
190250
" tags:\n" +
191251
" - \"pets\"\n" +
252+
" consumes:\n" +
253+
" - \"*/*\"\n" +
254+
" produces:\n" +
255+
" - \"*/*\"\n" +
192256
" parameters:\n" +
193257
" - name: \"size\"\n" +
194258
" in: \"query\"\n" +
195259
" required: false\n" +
196260
" type: \"integer\"\n" +
197261
" format: \"int32\"\n" +
262+
" responses:\n" +
263+
" 200:\n" +
264+
" description: \"Success\"\n" +
265+
" schema:\n" +
266+
" $ref: \"#/definitions/IterablePet\"\n" +
198267
" post:\n" +
199268
" tags:\n" +
200269
" - \"pets\"\n" +
270+
" consumes:\n" +
271+
" - \"*/*\"\n" +
272+
" produces:\n" +
273+
" - \"*/*\"\n" +
201274
" parameters:\n" +
202275
" - in: \"body\"\n" +
203276
" name: \"pet\"\n" +
204277
" required: true\n" +
205278
" schema:\n" +
206279
" $ref: \"#/definitions/Pet\"\n" +
207-
" /pets/{id}:\n" +
280+
" responses:\n" +
281+
" 200:\n" +
282+
" description: \"Success\"\n" +
283+
" schema:\n" +
284+
" $ref: \"#/definitions/Pet\"\n" +
285+
" /api/pets/{id}:\n" +
208286
" get:\n" +
209287
" tags:\n" +
210288
" - \"pets\"\n" +
289+
" consumes:\n" +
290+
" - \"*/*\"\n" +
291+
" produces:\n" +
292+
" - \"*/*\"\n" +
211293
" parameters:\n" +
212294
" - name: \"id\"\n" +
213295
" in: \"path\"\n" +
214296
" required: true\n" +
215297
" type: \"integer\"\n" +
216298
" format: \"int32\"\n" +
299+
" responses:\n" +
300+
" 200:\n" +
301+
" description: \"Success\"\n" +
302+
" schema:\n" +
303+
" $ref: \"#/definitions/Pet\"\n" +
217304
"definitions:\n" +
218305
" Pet:\n" +
219306
" type: \"object\"\n" +
@@ -241,35 +328,62 @@ public void yml() throws Exception {
241328
"produces:\n" +
242329
"- \"application/json\"\n" +
243330
"paths:\n" +
244-
" /pets:\n" +
331+
" /api/pets:\n" +
245332
" get:\n" +
246333
" tags:\n" +
247334
" - \"pets\"\n" +
335+
" consumes:\n" +
336+
" - \"*/*\"\n" +
337+
" produces:\n" +
338+
" - \"*/*\"\n" +
248339
" parameters:\n" +
249340
" - name: \"size\"\n" +
250341
" in: \"query\"\n" +
251342
" required: false\n" +
252343
" type: \"integer\"\n" +
253344
" format: \"int32\"\n" +
345+
" responses:\n" +
346+
" 200:\n" +
347+
" description: \"Success\"\n" +
348+
" schema:\n" +
349+
" $ref: \"#/definitions/IterablePet\"\n" +
254350
" post:\n" +
255351
" tags:\n" +
256352
" - \"pets\"\n" +
353+
" consumes:\n" +
354+
" - \"*/*\"\n" +
355+
" produces:\n" +
356+
" - \"*/*\"\n" +
257357
" parameters:\n" +
258358
" - in: \"body\"\n" +
259359
" name: \"pet\"\n" +
260360
" required: true\n" +
261361
" schema:\n" +
262362
" $ref: \"#/definitions/Pet\"\n" +
263-
" /pets/{id}:\n" +
363+
" responses:\n" +
364+
" 200:\n" +
365+
" description: \"Success\"\n" +
366+
" schema:\n" +
367+
" $ref: \"#/definitions/Pet\"\n" +
368+
" /api/pets/{id}:\n" +
264369
" get:\n" +
265370
" tags:\n" +
266371
" - \"pets\"\n" +
372+
" consumes:\n" +
373+
" - \"*/*\"\n" +
374+
" produces:\n" +
375+
" - \"*/*\"\n" +
267376
" parameters:\n" +
268377
" - name: \"id\"\n" +
269378
" in: \"path\"\n" +
270379
" required: true\n" +
271380
" type: \"integer\"\n" +
272381
" format: \"int32\"\n" +
382+
" responses:\n" +
383+
" 200:\n" +
384+
" description: \"Success\"\n" +
385+
" schema:\n" +
386+
" $ref: \"#/definitions/Pet\"\n" +
273387
"definitions:\n" +
274388
" Pet:\n" +
275389
" type: \"object\"\n" +

jooby-spec/src/main/java/org/jooby/internal/spec/AppCollector.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,17 @@
3232
import com.github.javaparser.ast.visitor.GenericVisitorAdapter;
3333
import com.google.common.collect.ImmutableSet;
3434

35-
public class AppCollector extends GenericVisitorAdapter<Node, Object> {
35+
public class AppCollector extends GenericVisitorAdapter<Node, Context> {
3636

3737
private static final Set<String> APP = ImmutableSet
3838
.of(Jooby.class.getSimpleName(), Jooby.class.getName());
3939

40-
public Node accept(final CompilationUnit unit) {
41-
return unit.accept(this, null);
40+
public Node accept(final CompilationUnit unit, final Context ctx) {
41+
return unit.accept(this, ctx);
4242
}
4343

4444
@Override
45-
public Node visit(final ObjectCreationExpr expr, final Object arg) {
45+
public Node visit(final ObjectCreationExpr expr, final Context ctx) {
4646
/**
4747
* Inline like:
4848
*
@@ -57,8 +57,9 @@ public Node visit(final ObjectCreationExpr expr, final Object arg) {
5757
return null;
5858
}
5959

60+
@SuppressWarnings("rawtypes")
6061
@Override
61-
public Node visit(final InitializerDeclaration expr, final Object arg) {
62+
public Node visit(final InitializerDeclaration expr, final Context ctx) {
6263
/**
6364
* extends + initializer
6465
*
@@ -72,8 +73,12 @@ public Node visit(final InitializerDeclaration expr, final Object arg) {
7273
if (node instanceof ClassOrInterfaceDeclaration) {
7374
List<ClassOrInterfaceType> extendList = ((ClassOrInterfaceDeclaration) node).getExtends();
7475
if (extendList.size() > 0) {
75-
if (APP.contains(extendList.get(0).getName())) {
76-
return expr;
76+
Class type = (Class) extendList.get(0).accept(new TypeCollector(), ctx);
77+
while (type != Object.class) {
78+
if (type.getTypeName().equals("org.jooby.Jooby")) {
79+
return expr;
80+
}
81+
type = type.getSuperclass();
7782
}
7883
}
7984
}

jooby-spec/src/main/java/org/jooby/spec/RouteProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ private List<RouteSpec> processInternal(final Class<? extends Jooby> appClass,
237237
/**
238238
* Find out app node.
239239
*/
240-
Node appNode = new AppCollector().accept(unit);
240+
Node appNode = new AppCollector().accept(unit, ctx);
241241

242242
/** Collect all routes and process them. */
243243
Set<String> owners = new HashSet<>();

jooby-spec/src/test/java/org/jooby/spec/AppNodeFinderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public void findAppNode() throws ParseException {
1919
" {",
2020
" get(\"/\", () -> \"Hello World!\");",
2121
" }",
22-
"}"));
22+
"}"), ctx());
2323
assertNotNull(app);
2424
assertEquals("{\n" +
2525
" get(\"/\", () -> \"Hello World!\");\n" +

0 commit comments

Comments
 (0)