mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2026-03-24 01:59:15 +00:00
Feature/api name suffix (#3918)
* added apiNameSuffix parameter to control the suffixes of API class/file/doc names * added --api-name-suffix in readme
This commit is contained in:
committed by
William Cheng
parent
7c7fa68737
commit
ebc9e291c3
@@ -206,6 +206,9 @@ public class CodegenConstants {
|
||||
// Codegen constants should define a description and provide proper input validation for the value of serializationLibrary
|
||||
public static final String SERIALIZATION_LIBRARY = "serializationLibrary";
|
||||
|
||||
public static final String API_NAME_SUFFIX = "apiNameSuffix";
|
||||
public static final String API_NAME_SUFFIX_DESC = "Suffix that will be appended to all api names.";
|
||||
|
||||
public static final String MODEL_NAME_PREFIX = "modelNamePrefix";
|
||||
public static final String MODEL_NAME_PREFIX_DESC = "Prefix that will be prepended to all model names.";
|
||||
|
||||
|
||||
@@ -85,6 +85,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
protected Map<String, String> importMapping = new HashMap<String, String>();
|
||||
protected String modelPackage = "", apiPackage = "", fileSuffix;
|
||||
protected String modelNamePrefix = "", modelNameSuffix = "";
|
||||
protected String apiNameSuffix = "Api";
|
||||
protected String testPackage = "";
|
||||
protected Map<String, String> apiTemplateFiles = new HashMap<String, String>();
|
||||
protected Map<String, String> modelTemplateFiles = new HashMap<String, String>();
|
||||
@@ -180,6 +181,10 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
.get(CodegenConstants.ALLOW_UNICODE_IDENTIFIERS).toString()));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.API_NAME_SUFFIX)) {
|
||||
this.setApiNameSuffix((String) additionalProperties.get(CodegenConstants.API_NAME_SUFFIX));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.MODEL_NAME_PREFIX)) {
|
||||
this.setModelNamePrefix((String) additionalProperties.get(CodegenConstants.MODEL_NAME_PREFIX));
|
||||
}
|
||||
@@ -779,6 +784,14 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
this.modelNameSuffix = modelNameSuffix;
|
||||
}
|
||||
|
||||
public String getApiNameSuffix() {
|
||||
return apiNameSuffix;
|
||||
}
|
||||
|
||||
public void setApiNameSuffix(String apiNameSuffix) {
|
||||
this.apiNameSuffix = apiNameSuffix;
|
||||
}
|
||||
|
||||
public void setApiPackage(String apiPackage) {
|
||||
this.apiPackage = apiPackage;
|
||||
}
|
||||
@@ -1692,17 +1705,17 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the API (class) name (capitalized) ending with "Api"
|
||||
* Output the API (class) name (capitalized) ending with the specified or default suffix
|
||||
* Return DefaultApi if name is empty
|
||||
*
|
||||
* @param name the name of the Api
|
||||
* @return capitalized Api name ending with "Api"
|
||||
* @return capitalized Api name
|
||||
*/
|
||||
public String toApiName(String name) {
|
||||
if (name.length() == 0) {
|
||||
return "DefaultApi";
|
||||
}
|
||||
return camelize(name) + "Api";
|
||||
return camelize(name + "_" + apiNameSuffix);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -287,6 +287,11 @@ public class CodegenConfigurator {
|
||||
return this;
|
||||
}
|
||||
|
||||
public CodegenConfigurator setApiNameSuffix(String suffix) {
|
||||
generatorSettingsBuilder.withApiNameSuffix(suffix);
|
||||
return this;
|
||||
}
|
||||
|
||||
public CodegenConfigurator setModelNamePrefix(String prefix) {
|
||||
generatorSettingsBuilder.withModelNamePrefix(prefix);
|
||||
return this;
|
||||
|
||||
@@ -151,7 +151,7 @@ abstract public class AbstractCppCodegen extends DefaultCodegen implements Codeg
|
||||
|
||||
@Override
|
||||
public String toApiName(String type) {
|
||||
return sanitizeName(modelNamePrefix + Character.toUpperCase(type.charAt(0)) + type.substring(1) + "Api");
|
||||
return sanitizeName(modelNamePrefix + super.toApiName(type));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -244,11 +244,10 @@ public abstract class AbstractJavaJAXRSServerCodegen extends AbstractJavaCodegen
|
||||
@Override
|
||||
public String toApiName(final String name) {
|
||||
String computed = name;
|
||||
if (computed.length() == 0) {
|
||||
return "DefaultApi";
|
||||
if (computed.length() > 0) {
|
||||
computed = sanitizeName(computed);
|
||||
}
|
||||
computed = sanitizeName(computed);
|
||||
return camelize(computed) + "Api";
|
||||
return super.toApiName(computed);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -531,7 +531,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
name = name.replaceAll("-", "_");
|
||||
|
||||
// e.g. PhoneNumberApi.py => phone_number_api.py
|
||||
return underscore(name) + "_api";
|
||||
return underscore(name+ "_" + apiNameSuffix);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -541,11 +541,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
|
||||
@Override
|
||||
public String toApiName(String name) {
|
||||
if (name.length() == 0) {
|
||||
return "DefaultApi";
|
||||
}
|
||||
// e.g. phone_number_api => PhoneNumberApi
|
||||
return camelize(name) + "Api";
|
||||
return super.toApiName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -553,7 +549,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
if (name.length() == 0) {
|
||||
return "default_api";
|
||||
}
|
||||
return underscore(name) + "_api";
|
||||
return underscore(name+ "_" + apiNameSuffix);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -387,7 +387,7 @@ public class RubyClientCodegen extends AbstractRubyCodegen {
|
||||
name = name.replaceAll("-", "_"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
|
||||
// e.g. PhoneNumberApi.rb => phone_number_api.rb
|
||||
return underscore(name) + "_api";
|
||||
return underscore(name + "_" + apiNameSuffix);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -407,11 +407,7 @@ public class RubyClientCodegen extends AbstractRubyCodegen {
|
||||
|
||||
@Override
|
||||
public String toApiName(String name) {
|
||||
if (name.length() == 0) {
|
||||
return "DefaultApi";
|
||||
}
|
||||
// e.g. phone_number_api => PhoneNumberApi
|
||||
return camelize(name) + "Api";
|
||||
return super.toApiName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user