forked from loafle/openapi-generator-original
Add removeOperationIdPrefix option (#5674)
* add removeOperationIdPrefix option * remove removeOperationIdPrefix from cli option for generators
This commit is contained in:
parent
7edf744426
commit
8314f4e78a
@ -125,6 +125,9 @@ public class Generate implements Runnable {
|
||||
@Option(name = {"--ignore-file-override"}, title = "ignore file override location", description = CodegenConstants.IGNORE_FILE_OVERRIDE_DESC)
|
||||
private String ignoreFileOverride;
|
||||
|
||||
@Option(name = {"--remove-operation-id-prefix"}, title = "remove prefix of the operationId", description = CodegenConstants.REMOVE_OPERATION_ID_PREFIX_DESC)
|
||||
private Boolean removeOperationIdPrefix;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
@ -222,6 +225,10 @@ public class Generate implements Runnable {
|
||||
configurator.setIgnoreFileOverride(ignoreFileOverride);
|
||||
}
|
||||
|
||||
if (removeOperationIdPrefix != null) {
|
||||
configurator.setRemoveOperationIdPrefix(removeOperationIdPrefix);
|
||||
}
|
||||
|
||||
applySystemPropertiesKvp(systemProperties, configurator);
|
||||
applyInstantiationTypesKvp(instantiationTypes, configurator);
|
||||
applyImportMappingsKvp(importMappings, configurator);
|
||||
|
@ -108,6 +108,12 @@ public class CodeGenMojo extends AbstractMojo {
|
||||
@Parameter(name="skipOverwrite", required=false)
|
||||
private Boolean skipOverwrite;
|
||||
|
||||
/**
|
||||
* Specifies if the existing files should be overwritten during the generation.
|
||||
*/
|
||||
@Parameter(name="removeOperationIdPrefix", required=false)
|
||||
private Boolean removeOperationIdPrefix;
|
||||
|
||||
/**
|
||||
* The package to use for generated api objects/classes
|
||||
*/
|
||||
@ -283,6 +289,10 @@ public class CodeGenMojo extends AbstractMojo {
|
||||
configurator.setSkipOverwrite(skipOverwrite);
|
||||
}
|
||||
|
||||
if(removeOperationIdPrefix != null) {
|
||||
configurator.setRemoveOperationIdPrefix(removeOperationIdPrefix);
|
||||
}
|
||||
|
||||
if(isNotEmpty(inputSpec)) {
|
||||
configurator.setInputSpec(inputSpec);
|
||||
}
|
||||
|
@ -171,6 +171,10 @@ public interface CodegenConfig {
|
||||
|
||||
void setSkipOverwrite(boolean skipOverwrite);
|
||||
|
||||
boolean isRemoveOperationIdPrefix();
|
||||
|
||||
void setRemoveOperationIdPrefix(boolean removeOperationIdPrefix);
|
||||
|
||||
Map<String, String> supportedLibraries();
|
||||
|
||||
void setLibrary(String library);
|
||||
|
@ -191,4 +191,6 @@ public class CodegenConstants {
|
||||
public static final String IGNORE_FILE_OVERRIDE = "ignoreFileOverride";
|
||||
public static final String IGNORE_FILE_OVERRIDE_DESC = "Specifies an override location for the .swagger-codegen-ignore file. Most useful on initial generation.";
|
||||
|
||||
public static final String REMOVE_OPERATION_ID_PREFIX = "removeOperationIdPrefix";
|
||||
public static final String REMOVE_OPERATION_ID_PREFIX_DESC = "Remove prefix of operationId, e.g. config_getId => getId";
|
||||
}
|
||||
|
@ -102,6 +102,7 @@ public class DefaultCodegen {
|
||||
protected List<SupportingFile> supportingFiles = new ArrayList<SupportingFile>();
|
||||
protected List<CliOption> cliOptions = new ArrayList<CliOption>();
|
||||
protected boolean skipOverwrite;
|
||||
protected boolean removeOperationIdPrefix;
|
||||
protected boolean supportsInheritance;
|
||||
protected boolean supportsMixins;
|
||||
protected Map<String, String> supportedLibraries = new LinkedHashMap<String, String>();
|
||||
@ -160,6 +161,11 @@ public class DefaultCodegen {
|
||||
if(additionalProperties.containsKey(CodegenConstants.MODEL_NAME_SUFFIX)){
|
||||
this.setModelNameSuffix((String) additionalProperties.get(CodegenConstants.MODEL_NAME_SUFFIX));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.REMOVE_OPERATION_ID_PREFIX)) {
|
||||
this.setSortParamsByRequiredFlag(Boolean.valueOf(additionalProperties
|
||||
.get(CodegenConstants.REMOVE_OPERATION_ID_PREFIX).toString()));
|
||||
}
|
||||
}
|
||||
|
||||
// override with any special post-processing for all models
|
||||
@ -849,7 +855,7 @@ public class DefaultCodegen {
|
||||
cliOptions.add(CliOption.newBoolean(CodegenConstants.ENSURE_UNIQUE_PARAMS, CodegenConstants
|
||||
.ENSURE_UNIQUE_PARAMS_DESC).defaultValue(Boolean.TRUE.toString()));
|
||||
|
||||
//name formatting options
|
||||
// name formatting options
|
||||
cliOptions.add(CliOption.newBoolean(CodegenConstants.ALLOW_UNICODE_IDENTIFIERS, CodegenConstants
|
||||
.ALLOW_UNICODE_IDENTIFIERS_DESC).defaultValue(Boolean.FALSE.toString()));
|
||||
|
||||
@ -1982,6 +1988,13 @@ public class DefaultCodegen {
|
||||
op.vendorExtensions = operation.getVendorExtensions();
|
||||
|
||||
String operationId = getOrGenerateOperationId(operation, path, httpMethod);
|
||||
// remove prefix in operationId
|
||||
if (removeOperationIdPrefix) {
|
||||
int offset = operationId.indexOf('_');
|
||||
if (offset > -1) {
|
||||
operationId = operationId.substring(offset+1);
|
||||
}
|
||||
}
|
||||
operationId = removeNonNameElementToCamelCase(operationId);
|
||||
op.path = path;
|
||||
op.operationId = toOperationId(operationId);
|
||||
@ -3195,6 +3208,14 @@ public class DefaultCodegen {
|
||||
this.skipOverwrite = skipOverwrite;
|
||||
}
|
||||
|
||||
public boolean isRemoveOperationIdPrefix() {
|
||||
return removeOperationIdPrefix;
|
||||
}
|
||||
|
||||
public void setRemoveOperationIdPrefix(boolean removeOperationIdPrefix) {
|
||||
this.removeOperationIdPrefix = removeOperationIdPrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* All library templates supported.
|
||||
* (key: library name, value: library description)
|
||||
|
@ -44,6 +44,7 @@ public class CodegenConfigurator implements Serializable {
|
||||
private String outputDir;
|
||||
private boolean verbose;
|
||||
private boolean skipOverwrite;
|
||||
private boolean removeOperationIdPrefix;
|
||||
private String templateDir;
|
||||
private String auth;
|
||||
private String apiPackage;
|
||||
@ -116,6 +117,15 @@ public class CodegenConfigurator implements Serializable {
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean getRemoveOperationIdPrefix() {
|
||||
return removeOperationIdPrefix;
|
||||
}
|
||||
|
||||
public CodegenConfigurator setRemoveOperationIdPrefix(boolean removeOperationIdPrefix) {
|
||||
this.removeOperationIdPrefix = removeOperationIdPrefix;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getModelNameSuffix() {
|
||||
return modelNameSuffix;
|
||||
}
|
||||
@ -383,6 +393,7 @@ public class CodegenConfigurator implements Serializable {
|
||||
config.setOutputDir(outputDir);
|
||||
config.setSkipOverwrite(skipOverwrite);
|
||||
config.setIgnoreFilePathOverride(ignoreFileOverride);
|
||||
config.setRemoveOperationIdPrefix(removeOperationIdPrefix);
|
||||
|
||||
config.instantiationTypes().putAll(instantiationTypes);
|
||||
config.typeMapping().putAll(typeMappings);
|
||||
|
@ -56,7 +56,6 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
// at the moment
|
||||
importMapping.clear();
|
||||
|
||||
|
||||
supportsInheritance = true;
|
||||
outputFolder = "generated-code" + File.separator + "php";
|
||||
modelTemplateFiles.put("model.mustache", ".php");
|
||||
|
@ -228,7 +228,8 @@ use \{{invokerPackage}}\ObjectSerializer;
|
||||
{{/isFile}}
|
||||
}
|
||||
{{/formParams}}
|
||||
{{#bodyParams}}// body params
|
||||
{{#bodyParams}}
|
||||
// body params
|
||||
$_tempBody = null;
|
||||
if (isset(${{paramName}})) {
|
||||
$_tempBody = ${{paramName}};
|
||||
|
1
samples/client/petstore/php/.swagger-codegen/VERSION
Normal file
1
samples/client/petstore/php/.swagger-codegen/VERSION
Normal file
@ -0,0 +1 @@
|
||||
2.2.3-SNAPSHOT
|
Loading…
x
Reference in New Issue
Block a user