Skip to content

Added apiNameSuffix parameter for JaxRsSpec code generator #7160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ public class Generate implements Runnable {
description = CodegenConstants.API_PACKAGE_DESC)
private String apiPackage;

@Option(name = {"--api-name-suffix"}, title = "api name suffix",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this should be here at all. If I'm not mistaken, these are the general swagger-codegen wide parameters that all generator should support. I think you only need to add you parameters to your specific codegen. See this for an example:

https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaPlayFrameworkCodegen.java#L22

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, I check all your code, it seems you are indeed trying to create an "all generators" parameter... I'm not sure it is really safe to add that kind of parameters. I will add @wing328 and @cbornet to the conversation to have their advices.

description = CodegenConstants.API_NAME_SUFFIX_DESC)
private String apiNameSuffix;

@Option(name = {"--model-package"}, title = "model package",
description = CodegenConstants.MODEL_PACKAGE_DESC)
private String modelPackage;
Expand Down Expand Up @@ -217,6 +221,10 @@ public void run() {
configurator.setApiPackage(apiPackage);
}

if (isNotEmpty(apiNameSuffix)) {
configurator.setApiNameSuffix(apiNameSuffix);
}

if (isNotEmpty(modelPackage)) {
configurator.setModelPackage(modelPackage);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ public class CodeGenMojo extends AbstractMojo {
@Parameter(name = "library", required = false)
private String library;

/**
* Sets the suffix for api classes
*/
@Parameter(name = "apiNameSuffix", required = false)
private String apiNameSuffix;

/**
* Sets the prefix for model enums and classes
*/
Expand Down Expand Up @@ -391,6 +397,10 @@ public void execute() throws MojoExecutionException {
configurator.setLibrary(library);
}

if (isNotEmpty(apiNameSuffix)) {
configurator.setApiNameSuffix(apiNameSuffix);
}

if (isNotEmpty(modelNamePrefix)) {
configurator.setModelNamePrefix(modelNamePrefix);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ public static enum ENUM_PROPERTY_NAMING_TYPE {camelCase, PascalCase, snake_case,
public static final String ENUM_PROPERTY_NAMING = "enumPropertyNaming";
public static final String ENUM_PROPERTY_NAMING_DESC = "Naming convention for enum properties: 'camelCase', 'PascalCase', 'snake_case', 'UPPERCASE', and 'original'";

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. Default is \"Api\".";

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. Default is the empty string.";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public class DefaultCodegen {
protected Set<String> languageSpecificPrimitives = new HashSet<String>();
protected Map<String, String> importMapping = new HashMap<String, String>();
protected String modelPackage = "", apiPackage = "", fileSuffix;
protected String apiNameSuffix = "Api";
protected String modelNamePrefix = "", modelNameSuffix = "";
protected String testPackage = "";
protected Map<String, String> apiTemplateFiles = new HashMap<String, String>();
Expand Down Expand Up @@ -143,6 +144,10 @@ public void processOpts() {
.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));
}
Expand Down Expand Up @@ -567,6 +572,10 @@ public void setTemplateDir(String templateDir) {
this.templateDir = templateDir;
}

public void setApiNameSuffix(String apiNameSuffix) {
this.apiNameSuffix = apiNameSuffix;
}

public void setModelPackage(String modelPackage) {
this.modelPackage = modelPackage;
}
Expand Down Expand Up @@ -1266,7 +1275,7 @@ public String toApiName(String name) {
if (name.length() == 0) {
return "DefaultApi";
}
return initialCaps(name) + "Api";
return initialCaps(name) + apiNameSuffix;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class CodegenConfigurator implements Serializable {
private String templateDir;
private String auth;
private String apiPackage;
private String apiNameSuffix;
private String modelPackage;
private String invokerPackage;
private String modelNamePrefix;
Expand Down Expand Up @@ -99,6 +100,15 @@ public CodegenConfigurator setOutputDir(String outputDir) {
return this;
}

public String getApiNameSuffix() {
return apiNameSuffix;
}

public CodegenConfigurator setApiNameSuffix(String apiNameSuffix) {
this.apiNameSuffix = apiNameSuffix;
return this;
}

public String getModelPackage() {
return modelPackage;
}
Expand Down Expand Up @@ -402,6 +412,7 @@ public ClientOptInput toClientOptInput() {
config.reservedWordsMappings().putAll(reservedWordMappings);

checkAndSetAdditionalProperty(apiPackage, CodegenConstants.API_PACKAGE);
checkAndSetAdditionalProperty(apiNameSuffix, CodegenConstants.API_NAME_SUFFIX);
checkAndSetAdditionalProperty(modelPackage, CodegenConstants.MODEL_PACKAGE);
checkAndSetAdditionalProperty(invokerPackage, CodegenConstants.INVOKER_PACKAGE);
checkAndSetAdditionalProperty(groupId, CodegenConstants.GROUP_ID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ public String toApiName(String name) {
if (name.length() == 0) {
return "DefaultApi";
}
return camelize(name) + "Api";
return camelize(name) + apiNameSuffix;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public String toApiName(final String name) {
return "DefaultApi";
}
computed = sanitizeName(computed);
return camelize(computed) + "Api";
return camelize(computed) + apiNameSuffix;
}

@Override
Expand Down