Skip to content

Commit d2b5959

Browse files
Add support for reserved-words-mappings to cpprest
* Also handles automatic escaping for reserved words, i.e. by default, no need to provide a mapping. Fix #6498
1 parent 8067612 commit d2b5959

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractCppCodegen.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,25 @@ public String toVarName(String name) {
101101
return sanitizeName(name);
102102
}
103103

104+
if (isReservedWord(name)) {
105+
return escapeReservedWord(name);
106+
}
107+
104108
if (name.length() > 1) {
105109
return sanitizeName(Character.toUpperCase(name.charAt(0)) + name.substring(1));
106110
}
107111

108112
return sanitizeName(name);
109113
}
110114

115+
@Override
116+
public String escapeReservedWord(String name) {
117+
if(this.reservedWordsMappings().containsKey(name)) {
118+
return this.reservedWordsMappings().get(name);
119+
}
120+
return sanitizeName("_" + name);
121+
}
122+
111123
@Override
112124
public String toParamName(String name) {
113125
return sanitizeName(super.toParamName(name));

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/CppRestClientCodegen.java

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public class CppRestClientCodegen extends AbstractCppCodegen {
5555

5656
/**
5757
* Configures the type of generator.
58-
*
58+
*
5959
* @return the CodegenType for this generator
6060
* @see io.swagger.codegen.CodegenType
6161
*/
@@ -66,7 +66,7 @@ public CodegenType getTag() {
6666
/**
6767
* Configures a friendly name for the generator. This will be used by the
6868
* generator to select the library with the -l flag.
69-
*
69+
*
7070
* @return the friendly name for the generator
7171
*/
7272
public String getName() {
@@ -76,7 +76,7 @@ public String getName() {
7676
/**
7777
* Returns human-friendly help for the generator. Provide the consumer with
7878
* help tips, parameters here
79-
*
79+
*
8080
* @return A string value for the help message
8181
*/
8282
public String getHelp() {
@@ -111,8 +111,6 @@ public CppRestClientCodegen() {
111111
"The default include statement that should be placed in all headers for including things like the declspec (convention: #include \"Commons.h\" ",
112112
this.defaultInclude);
113113

114-
reservedWords = new HashSet<String>();
115-
116114
supportingFiles.add(new SupportingFile("modelbase-header.mustache", "", "ModelBase.h"));
117115
supportingFiles.add(new SupportingFile("modelbase-source.mustache", "", "ModelBase.cpp"));
118116
supportingFiles.add(new SupportingFile("apiclient-header.mustache", "", "ApiClient.h"));
@@ -187,18 +185,6 @@ public void processOpts() {
187185
additionalProperties.put("defaultInclude", defaultInclude);
188186
}
189187

190-
/**
191-
* Escapes a reserved word as defined in the `reservedWords` array. Handle
192-
* escaping those terms here. This logic is only called if a variable
193-
* matches the reseved words
194-
*
195-
* @return the escaped term
196-
*/
197-
@Override
198-
public String escapeReservedWord(String name) {
199-
return "_" + name; // add an underscore to the name
200-
}
201-
202188
/**
203189
* Location to write model files. You can use the modelPackage() as defined
204190
* when the class is instantiated

0 commit comments

Comments
 (0)