mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2026-03-16 23:49:08 +00:00
[Kotlin] add apiSuffix configuration (#2690)
* add apiSuffix configuration * Add default value for Api suffix * remove overriding method toApiName * refactor the global option apiSuffix to kotlin specific feature * add missing Option for apiSuffix * extend readme.md for apiSuffix configuration * update doc * add testcase
This commit is contained in:
@@ -37,6 +37,9 @@ public class CodegenConstants {
|
||||
public static final String API_PACKAGE = "apiPackage";
|
||||
public static final String API_PACKAGE_DESC = "package for generated api classes";
|
||||
|
||||
public static final String API_SUFFIX = "apiSuffix";
|
||||
public static final String API_SUFFIX_DESC = "suffix for api classes";
|
||||
|
||||
public static final String MODEL_PACKAGE = "modelPackage";
|
||||
public static final String MODEL_PACKAGE_DESC = "package for generated models";
|
||||
|
||||
|
||||
@@ -584,14 +584,6 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
return toModelName(name) + "Test";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiName(String name) {
|
||||
if (name.length() == 0) {
|
||||
return "DefaultApi";
|
||||
}
|
||||
return camelize(name) + "Api";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiFilename(String name) {
|
||||
return toApiName(name);
|
||||
|
||||
@@ -41,6 +41,7 @@ public abstract class AbstractKotlinCodegen extends DefaultCodegen implements Co
|
||||
protected String artifactVersion = "1.0.0";
|
||||
protected String groupId = "org.openapitools";
|
||||
protected String packageName = "org.openapitools";
|
||||
protected String apiSuffix = "Api";
|
||||
|
||||
protected String sourceFolder = "src/main/kotlin";
|
||||
|
||||
@@ -195,6 +196,7 @@ public abstract class AbstractKotlinCodegen extends DefaultCodegen implements Co
|
||||
cliOptions.clear();
|
||||
addOption(CodegenConstants.SOURCE_FOLDER, CodegenConstants.SOURCE_FOLDER_DESC, sourceFolder);
|
||||
addOption(CodegenConstants.PACKAGE_NAME, "Generated artifact package name.", packageName);
|
||||
addOption(CodegenConstants.API_SUFFIX, CodegenConstants.API_SUFFIX_DESC, apiSuffix);
|
||||
addOption(CodegenConstants.GROUP_ID, "Generated artifact package's organization (i.e. maven groupId).", groupId);
|
||||
addOption(CodegenConstants.ARTIFACT_ID, "Generated artifact id (name of jar).", artifactId);
|
||||
addOption(CodegenConstants.ARTIFACT_VERSION, "Generated artifact's package version.", artifactVersion);
|
||||
@@ -337,6 +339,10 @@ public abstract class AbstractKotlinCodegen extends DefaultCodegen implements Co
|
||||
additionalProperties.put(CodegenConstants.PACKAGE_NAME, packageName);
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.API_SUFFIX)) {
|
||||
this.setApiSuffix((String) additionalProperties.get(CodegenConstants.API_SUFFIX));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.ARTIFACT_ID)) {
|
||||
this.setArtifactId((String) additionalProperties.get(CodegenConstants.ARTIFACT_ID));
|
||||
} else {
|
||||
@@ -396,6 +402,10 @@ public abstract class AbstractKotlinCodegen extends DefaultCodegen implements Co
|
||||
this.packageName = packageName;
|
||||
}
|
||||
|
||||
public void setApiSuffix(String apiSuffix) {
|
||||
this.apiSuffix = apiSuffix;
|
||||
}
|
||||
|
||||
public void setSourceFolder(String sourceFolder) {
|
||||
this.sourceFolder = sourceFolder;
|
||||
}
|
||||
@@ -463,6 +473,14 @@ public abstract class AbstractKotlinCodegen extends DefaultCodegen implements Co
|
||||
return super.toInstantiationType(p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiName(String name) {
|
||||
if (name.length() == 0) {
|
||||
return "DefaultApi";
|
||||
}
|
||||
return (this.apiSuffix.isEmpty() ? camelize(name) : camelize(name) + this.apiSuffix);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the fully-qualified "Model" name for import
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user