@@ -117,6 +117,18 @@ public void processOpts() {
117
117
118
118
if (additionalProperties .containsKey (CodegenConstants .INVOKER_PACKAGE )) {
119
119
this .setInvokerPackage ((String ) additionalProperties .get (CodegenConstants .INVOKER_PACKAGE ));
120
+ } else if (additionalProperties .containsKey (CodegenConstants .API_PACKAGE )) {
121
+ // guess from api package
122
+ String derviedInvokerPackage = deriveInvokerPackageName ((String )additionalProperties .get (CodegenConstants .API_PACKAGE ));
123
+ this .additionalProperties .put (CodegenConstants .INVOKER_PACKAGE , derviedInvokerPackage );
124
+ this .setInvokerPackage ((String ) additionalProperties .get (CodegenConstants .INVOKER_PACKAGE ));
125
+ LOGGER .info ("Invoker Package Name, originally not set, is now dervied from api package name: " + derviedInvokerPackage );
126
+ } else if (additionalProperties .containsKey (CodegenConstants .MODEL_PACKAGE )) {
127
+ // guess from model package
128
+ String derviedInvokerPackage = deriveInvokerPackageName ((String )additionalProperties .get (CodegenConstants .MODEL_PACKAGE ));
129
+ this .additionalProperties .put (CodegenConstants .INVOKER_PACKAGE , derviedInvokerPackage );
130
+ this .setInvokerPackage ((String ) additionalProperties .get (CodegenConstants .INVOKER_PACKAGE ));
131
+ LOGGER .info ("Invoker Package Name, originally not set, is now dervied from model package name: " + derviedInvokerPackage );
120
132
} else {
121
133
//not set, use default to be passed to template
122
134
additionalProperties .put (CodegenConstants .INVOKER_PACKAGE , invokerPackage );
@@ -845,4 +857,23 @@ public String escapeUnsafeCharacters(String input) {
845
857
return input .replace ("*/" , "*_/" ).replace ("/*" , "/_*" );
846
858
}
847
859
860
+ /*
861
+ * Derive invoker package name based on the input
862
+ * e.g. foo.bar.model => foo.bar
863
+ *
864
+ * @param input API package/model name
865
+ * @return Derived invoker package name based on API package/model name
866
+ */
867
+ private String deriveInvokerPackageName (String input ) {
868
+ String [] parts = input .split (Pattern .quote ("." )); // Split on period.
869
+
870
+ StringBuilder sb = new StringBuilder ();
871
+ String delim = "" ;
872
+ for (String p : Arrays .copyOf (parts , parts .length -1 )) {
873
+ sb .append (delim ).append (p );
874
+ delim = "." ;
875
+ }
876
+ return sb .toString ();
877
+ }
878
+
848
879
}
0 commit comments