refactor special mapping to defualt codegen

This commit is contained in:
wing328
2016-05-11 15:44:06 +08:00
parent 9df91a08cd
commit 3c117d5857
6 changed files with 146 additions and 58 deletions

View File

@@ -55,6 +55,10 @@ public class DefaultCodegen {
protected Boolean ensureUniqueParams = true;
protected String gitUserId, gitRepoId, releaseNote;
protected String httpUserAgent;
// How to encode special characters like $
// They are translated to words like "Dollar" and prefixed with '
// Then translated back during JSON encoding and decoding
protected Map<Character, String> specialCharReplacements = new HashMap<Character, String>();
public List<CliOption> cliOptions() {
return cliOptions;
@@ -728,6 +732,31 @@ public class DefaultCodegen {
CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG_DESC).defaultValue(Boolean.TRUE.toString()));
cliOptions.add(CliOption.newBoolean(CodegenConstants.ENSURE_UNIQUE_PARAMS, CodegenConstants
.ENSURE_UNIQUE_PARAMS_DESC).defaultValue(Boolean.TRUE.toString()));
// initalize special character mapping
initalizeSpecialCharacterMapping();
}
/**
* Initalize special character mapping
*/
protected void initalizeSpecialCharacterMapping() {
// Initialize special characters
specialCharReplacements.put('$', "Dollar");
specialCharReplacements.put('^', "Caret");
specialCharReplacements.put('|', "Pipe");
specialCharReplacements.put('=', "Equal");
specialCharReplacements.put('*', "Star");
specialCharReplacements.put('-', "Dash");
specialCharReplacements.put('&', "Ampersand");
specialCharReplacements.put('%', "Percent");
specialCharReplacements.put('#', "Hash");
specialCharReplacements.put('@', "At");
specialCharReplacements.put('!', "Exclamation");
specialCharReplacements.put('+', "Plus");
specialCharReplacements.put(':', "Colon");
specialCharReplacements.put('>', "GreaterThan");
specialCharReplacements.put('<', "LessThan");
}
/**

View File

@@ -18,12 +18,6 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
protected String sourceFolder = "src";
protected String apiVersion = "0.0.1";
// How to encode special characters like $
// They are translated to words like "Dollar" and prefixed with '
// Then translated back during JSON encoding and decoding
private Map<Character, String> specialCharReplacements = new HashMap<Character, String>();
/**
* Configures the type of generator.
*
@@ -57,21 +51,6 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
public HaskellServantCodegen() {
super();
// Initialize special characters
specialCharReplacements.put('$', "Dollar");
specialCharReplacements.put('^', "Caret");
specialCharReplacements.put('|', "Pipe");
specialCharReplacements.put('=', "Equal");
specialCharReplacements.put('*', "Star");
specialCharReplacements.put('-', "Dash");
specialCharReplacements.put('&', "Ampersand");
specialCharReplacements.put('%', "Percent");
specialCharReplacements.put('#', "Hash");
specialCharReplacements.put('@', "At");
specialCharReplacements.put('!', "Exclamation");
specialCharReplacements.put('+', "Plus");
// set the output folder here
outputFolder = "generated-code/haskell-servant";