forked from loafle/openapi-generator-original
Add support for reserved-words-mappings to cpprest (#6501)
* Also handles automatic escaping for reserved words, i.e. by default, no need to provide a mapping. Fix #6498
This commit is contained in:
@@ -101,6 +101,10 @@ abstract public class AbstractCppCodegen extends DefaultCodegen implements Codeg
|
||||
return sanitizeName(name);
|
||||
}
|
||||
|
||||
if (isReservedWord(name)) {
|
||||
return escapeReservedWord(name);
|
||||
}
|
||||
|
||||
if (name.length() > 1) {
|
||||
return sanitizeName(Character.toUpperCase(name.charAt(0)) + name.substring(1));
|
||||
}
|
||||
@@ -108,6 +112,21 @@ abstract public class AbstractCppCodegen extends DefaultCodegen implements Codeg
|
||||
return sanitizeName(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Escapes a reserved word as defined in the `reservedWords` array. Handle
|
||||
* escaping those terms here. This logic is only called if a variable
|
||||
* matches the reseved words
|
||||
*
|
||||
* @return the escaped term
|
||||
*/
|
||||
@Override
|
||||
public String escapeReservedWord(String name) {
|
||||
if(this.reservedWordsMappings().containsKey(name)) {
|
||||
return this.reservedWordsMappings().get(name);
|
||||
}
|
||||
return sanitizeName("_" + name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toParamName(String name) {
|
||||
return sanitizeName(super.toParamName(name));
|
||||
|
||||
@@ -55,7 +55,7 @@ public class CppRestClientCodegen extends AbstractCppCodegen {
|
||||
|
||||
/**
|
||||
* Configures the type of generator.
|
||||
*
|
||||
*
|
||||
* @return the CodegenType for this generator
|
||||
* @see io.swagger.codegen.CodegenType
|
||||
*/
|
||||
@@ -66,7 +66,7 @@ public class CppRestClientCodegen extends AbstractCppCodegen {
|
||||
/**
|
||||
* Configures a friendly name for the generator. This will be used by the
|
||||
* generator to select the library with the -l flag.
|
||||
*
|
||||
*
|
||||
* @return the friendly name for the generator
|
||||
*/
|
||||
public String getName() {
|
||||
@@ -76,7 +76,7 @@ public class CppRestClientCodegen extends AbstractCppCodegen {
|
||||
/**
|
||||
* Returns human-friendly help for the generator. Provide the consumer with
|
||||
* help tips, parameters here
|
||||
*
|
||||
*
|
||||
* @return A string value for the help message
|
||||
*/
|
||||
public String getHelp() {
|
||||
@@ -111,8 +111,6 @@ public class CppRestClientCodegen extends AbstractCppCodegen {
|
||||
"The default include statement that should be placed in all headers for including things like the declspec (convention: #include \"Commons.h\" ",
|
||||
this.defaultInclude);
|
||||
|
||||
reservedWords = new HashSet<String>();
|
||||
|
||||
supportingFiles.add(new SupportingFile("modelbase-header.mustache", "", "ModelBase.h"));
|
||||
supportingFiles.add(new SupportingFile("modelbase-source.mustache", "", "ModelBase.cpp"));
|
||||
supportingFiles.add(new SupportingFile("apiclient-header.mustache", "", "ApiClient.h"));
|
||||
@@ -187,18 +185,6 @@ public class CppRestClientCodegen extends AbstractCppCodegen {
|
||||
additionalProperties.put("defaultInclude", defaultInclude);
|
||||
}
|
||||
|
||||
/**
|
||||
* Escapes a reserved word as defined in the `reservedWords` array. Handle
|
||||
* escaping those terms here. This logic is only called if a variable
|
||||
* matches the reseved words
|
||||
*
|
||||
* @return the escaped term
|
||||
*/
|
||||
@Override
|
||||
public String escapeReservedWord(String name) {
|
||||
return "_" + name; // add an underscore to the name
|
||||
}
|
||||
|
||||
/**
|
||||
* Location to write model files. You can use the modelPackage() as defined
|
||||
* when the class is instantiated
|
||||
|
||||
Reference in New Issue
Block a user