1
1
package restx .apidocs ;
2
2
3
- import com .fasterxml .jackson .databind .ObjectMapper ;
4
3
import com .fasterxml .jackson .databind .ObjectWriter ;
5
4
import com .google .common .base .CaseFormat ;
6
5
import com .google .common .base .Optional ;
7
- import com .google .common .base .Predicate ;
8
6
import com .google .common .collect .*;
9
7
import restx .*;
10
8
import restx .description .*;
@@ -54,13 +52,7 @@ public ApiDeclarationRoute(@Named(FrontObjectMapperFactory.WRITER_NAME) ObjectWr
54
52
@ Override
55
53
protected Optional <?> doRoute (RestxRequest restxRequest , RestxRequestMatch match , Object body ) throws IOException {
56
54
String routerName = match .getPathParam ("router" );
57
- routerName = CaseFormat .LOWER_HYPHEN .to (CaseFormat .UPPER_CAMEL , routerName );
58
-
59
- Optional <NamedComponent <RestxRouter >> router = Optional .absent ();
60
- ImmutableList <String > suffixes = ImmutableList .of ("ResourceRouter" , "" , "Resource" , "Router" );
61
- for (int i = 0 ; i < suffixes .size () && !router .isPresent (); i ++) {
62
- router = factory .queryByName (Name .of (RestxRouter .class , routerName + suffixes .get (i ))).optional ().findOne ();
63
- }
55
+ Optional <NamedComponent <RestxRouter >> router = getRouterByName (factory , routerName );
64
56
65
57
if (!router .isPresent ()) {
66
58
return Optional .absent ();
@@ -76,6 +68,17 @@ protected Optional<?> doRoute(RestxRequest restxRequest, RestxRequestMatch match
76
68
.build ());
77
69
}
78
70
71
+ static Optional <NamedComponent <RestxRouter >> getRouterByName (Factory f , String routerName ) {
72
+ routerName = CaseFormat .LOWER_HYPHEN .to (CaseFormat .UPPER_CAMEL , routerName );
73
+
74
+ Optional <NamedComponent <RestxRouter >> router = Optional .absent ();
75
+ ImmutableList <String > suffixes = ImmutableList .of ("ResourceRouter" , "" , "Resource" , "Router" );
76
+ for (int i = 0 ; i < suffixes .size () && !router .isPresent (); i ++) {
77
+ router = f .queryByName (Name .of (RestxRouter .class , routerName + suffixes .get (i ))).optional ().findOne ();
78
+ }
79
+ return router ;
80
+ }
81
+
79
82
private List <ResourceDescription > buildApis (NamedComponent <RestxRouter > router ) {
80
83
return fillRelatedOperations (router .getName ().getName (), describeAllRoutes (router .getComponent ()));
81
84
}
0 commit comments