forked from loafle/openapi-generator-original
derive invoker package name from api/modoel package name
This commit is contained in:
parent
748f4b21f4
commit
67a674bf3d
@ -117,6 +117,18 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
|||||||
|
|
||||||
if (additionalProperties.containsKey(CodegenConstants.INVOKER_PACKAGE)) {
|
if (additionalProperties.containsKey(CodegenConstants.INVOKER_PACKAGE)) {
|
||||||
this.setInvokerPackage((String) additionalProperties.get(CodegenConstants.INVOKER_PACKAGE));
|
this.setInvokerPackage((String) additionalProperties.get(CodegenConstants.INVOKER_PACKAGE));
|
||||||
|
} else if (additionalProperties.containsKey(CodegenConstants.API_PACKAGE)) {
|
||||||
|
// guess from api package
|
||||||
|
String derviedInvokerPackage = deriveInvokerPackageName((String)additionalProperties.get(CodegenConstants.API_PACKAGE));
|
||||||
|
this.additionalProperties.put(CodegenConstants.INVOKER_PACKAGE, derviedInvokerPackage);
|
||||||
|
this.setInvokerPackage((String) additionalProperties.get(CodegenConstants.INVOKER_PACKAGE));
|
||||||
|
LOGGER.info("Invoker Package Name, originally not set, is now dervied from api package name: " + derviedInvokerPackage);
|
||||||
|
} else if (additionalProperties.containsKey(CodegenConstants.MODEL_PACKAGE)) {
|
||||||
|
// guess from model package
|
||||||
|
String derviedInvokerPackage = deriveInvokerPackageName((String)additionalProperties.get(CodegenConstants.MODEL_PACKAGE));
|
||||||
|
this.additionalProperties.put(CodegenConstants.INVOKER_PACKAGE, derviedInvokerPackage);
|
||||||
|
this.setInvokerPackage((String) additionalProperties.get(CodegenConstants.INVOKER_PACKAGE));
|
||||||
|
LOGGER.info("Invoker Package Name, originally not set, is now dervied from model package name: " + derviedInvokerPackage);
|
||||||
} else {
|
} else {
|
||||||
//not set, use default to be passed to template
|
//not set, use default to be passed to template
|
||||||
additionalProperties.put(CodegenConstants.INVOKER_PACKAGE, invokerPackage);
|
additionalProperties.put(CodegenConstants.INVOKER_PACKAGE, invokerPackage);
|
||||||
@ -845,4 +857,23 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
|||||||
return input.replace("*/", "*_/").replace("/*", "/_*");
|
return input.replace("*/", "*_/").replace("/*", "/_*");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Derive invoker package name based on the input
|
||||||
|
* e.g. foo.bar.model => foo.bar
|
||||||
|
*
|
||||||
|
* @param input API package/model name
|
||||||
|
* @return Derived invoker package name based on API package/model name
|
||||||
|
*/
|
||||||
|
private String deriveInvokerPackageName(String input) {
|
||||||
|
String[] parts = input.split(Pattern.quote(".")); // Split on period.
|
||||||
|
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
String delim = "";
|
||||||
|
for (String p : Arrays.copyOf(parts, parts.length-1)) {
|
||||||
|
sb.append(delim).append(p);
|
||||||
|
delim = ".";
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user