forked from loafle/openapi-generator-original
[BUG][C++] Avoid using plain underscore when escaping reserved words (#5269)
* Don't use plain underscore when escaping reserved words * Regenerate petstore output * Add CLI option for reserved word prefix * Ensure CLI option isn't cleared in cpprest client codegen * Regenerate docs
This commit is contained in:
parent
23e76f2a50
commit
231ec6bcac
@ -12,6 +12,7 @@ sidebar_label: cpp-qt5-client
|
|||||||
|modelNamePrefix|Prefix that will be prepended to all model names.| |OAI|
|
|modelNamePrefix|Prefix that will be prepended to all model names.| |OAI|
|
||||||
|optionalProjectFile|Generate client.pri.| |true|
|
|optionalProjectFile|Generate client.pri.| |true|
|
||||||
|prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false|
|
|prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false|
|
||||||
|
|reservedWordPrefix|Prefix to prepend to reserved words in order to avoid conflicts| |r_|
|
||||||
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
|
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
|
||||||
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
|
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ sidebar_label: cpp-qt5-qhttpengine-server
|
|||||||
|ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true|
|
|ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true|
|
||||||
|modelNamePrefix|Prefix that will be prepended to all model names.| |OAI|
|
|modelNamePrefix|Prefix that will be prepended to all model names.| |OAI|
|
||||||
|prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false|
|
|prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false|
|
||||||
|
|reservedWordPrefix|Prefix to prepend to reserved words in order to avoid conflicts| |r_|
|
||||||
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
|
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
|
||||||
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
|
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ sidebar_label: cpp-restsdk
|
|||||||
|generateGMocksForApis|Generate Google Mock classes for APIs.| |null|
|
|generateGMocksForApis|Generate Google Mock classes for APIs.| |null|
|
||||||
|modelPackage|C++ namespace for models (convention: name.space.model).| |org.openapitools.client.model|
|
|modelPackage|C++ namespace for models (convention: name.space.model).| |org.openapitools.client.model|
|
||||||
|packageVersion|C++ package version.| |1.0.0|
|
|packageVersion|C++ package version.| |1.0.0|
|
||||||
|
|reservedWordPrefix|Prefix to prepend to reserved words in order to avoid conflicts| |r_|
|
||||||
|
|
||||||
## IMPORT MAPPING
|
## IMPORT MAPPING
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ sidebar_label: cpp-tizen
|
|||||||
|allowUnicodeIdentifiers|boolean, toggles whether unicode identifiers are allowed in names or not, default is false| |false|
|
|allowUnicodeIdentifiers|boolean, toggles whether unicode identifiers are allowed in names or not, default is false| |false|
|
||||||
|ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true|
|
|ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true|
|
||||||
|prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false|
|
|prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false|
|
||||||
|
|reservedWordPrefix|Prefix to prepend to reserved words in order to avoid conflicts| |r_|
|
||||||
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
|
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
|
||||||
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
|
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
|
||||||
|
|
||||||
|
@ -39,6 +39,10 @@ import java.util.Map;
|
|||||||
abstract public class AbstractCppCodegen extends DefaultCodegen implements CodegenConfig {
|
abstract public class AbstractCppCodegen extends DefaultCodegen implements CodegenConfig {
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractCppCodegen.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractCppCodegen.class);
|
||||||
|
|
||||||
|
protected static final String RESERVED_WORD_PREFIX_OPTION = "reservedWordPrefix";
|
||||||
|
protected static final String RESERVED_WORD_PREFIX_DESC = "Prefix to prepend to reserved words in order to avoid conflicts";
|
||||||
|
protected String reservedWordPrefix = "r_";
|
||||||
|
|
||||||
public AbstractCppCodegen() {
|
public AbstractCppCodegen() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
@ -135,6 +139,10 @@ abstract public class AbstractCppCodegen extends DefaultCodegen implements Codeg
|
|||||||
"xor",
|
"xor",
|
||||||
"xor_eq")
|
"xor_eq")
|
||||||
);
|
);
|
||||||
|
|
||||||
|
addOption(RESERVED_WORD_PREFIX_OPTION,
|
||||||
|
RESERVED_WORD_PREFIX_DESC,
|
||||||
|
this.reservedWordPrefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -200,7 +208,7 @@ abstract public class AbstractCppCodegen extends DefaultCodegen implements Codeg
|
|||||||
if (this.reservedWordsMappings().containsKey(name)) {
|
if (this.reservedWordsMappings().containsKey(name)) {
|
||||||
return this.reservedWordsMappings().get(name);
|
return this.reservedWordsMappings().get(name);
|
||||||
}
|
}
|
||||||
return sanitizeName("_" + name);
|
return sanitizeName(reservedWordPrefix + name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -259,6 +267,12 @@ abstract public class AbstractCppCodegen extends DefaultCodegen implements Codeg
|
|||||||
LOGGER.info("Environment variable CPP_POST_PROCESS_FILE not defined so the C++ code may not be properly formatted. To define it, try 'export CPP_POST_PROCESS_FILE=\"/usr/local/bin/clang-format -i\"' (Linux/Mac)");
|
LOGGER.info("Environment variable CPP_POST_PROCESS_FILE not defined so the C++ code may not be properly formatted. To define it, try 'export CPP_POST_PROCESS_FILE=\"/usr/local/bin/clang-format -i\"' (Linux/Mac)");
|
||||||
LOGGER.info("NOTE: To enable file post-processing, 'enablePostProcessFile' must be set to `true` (--enable-post-process-file for CLI).");
|
LOGGER.info("NOTE: To enable file post-processing, 'enablePostProcessFile' must be set to `true` (--enable-post-process-file for CLI).");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (additionalProperties.containsKey(RESERVED_WORD_PREFIX_OPTION)) {
|
||||||
|
reservedWordPrefix = (String) additionalProperties.get(RESERVED_WORD_PREFIX_OPTION);
|
||||||
|
}
|
||||||
|
|
||||||
|
additionalProperties.put(RESERVED_WORD_PREFIX_OPTION, reservedWordPrefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -129,6 +129,9 @@ public class CppRestSdkClientCodegen extends AbstractCppCodegen {
|
|||||||
addOption(GENERATE_GMOCKS_FOR_APIS,
|
addOption(GENERATE_GMOCKS_FOR_APIS,
|
||||||
"Generate Google Mock classes for APIs.",
|
"Generate Google Mock classes for APIs.",
|
||||||
null);
|
null);
|
||||||
|
addOption(RESERVED_WORD_PREFIX_OPTION,
|
||||||
|
RESERVED_WORD_PREFIX_DESC,
|
||||||
|
this.reservedWordPrefix);
|
||||||
|
|
||||||
supportingFiles.add(new SupportingFile("modelbase-header.mustache", "", "ModelBase.h"));
|
supportingFiles.add(new SupportingFile("modelbase-header.mustache", "", "ModelBase.h"));
|
||||||
supportingFiles.add(new SupportingFile("modelbase-source.mustache", "", "ModelBase.cpp"));
|
supportingFiles.add(new SupportingFile("modelbase-source.mustache", "", "ModelBase.cpp"));
|
||||||
@ -194,6 +197,10 @@ public class CppRestSdkClientCodegen extends AbstractCppCodegen {
|
|||||||
defaultInclude = additionalProperties.get(DEFAULT_INCLUDE).toString();
|
defaultInclude = additionalProperties.get(DEFAULT_INCLUDE).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (additionalProperties.containsKey(RESERVED_WORD_PREFIX_OPTION)) {
|
||||||
|
reservedWordPrefix = (String) additionalProperties.get(RESERVED_WORD_PREFIX_OPTION);
|
||||||
|
}
|
||||||
|
|
||||||
if (convertPropertyToBoolean(GENERATE_GMOCKS_FOR_APIS)) {
|
if (convertPropertyToBoolean(GENERATE_GMOCKS_FOR_APIS)) {
|
||||||
apiTemplateFiles.put("api-gmock.mustache", "GMock.h");
|
apiTemplateFiles.put("api-gmock.mustache", "GMock.h");
|
||||||
additionalProperties.put("gmockApis", "true");
|
additionalProperties.put("gmockApis", "true");
|
||||||
@ -207,6 +214,7 @@ public class CppRestSdkClientCodegen extends AbstractCppCodegen {
|
|||||||
additionalProperties.put("apiHeaderGuardPrefix", apiPackage.replaceAll("\\.", "_").toUpperCase(Locale.ROOT));
|
additionalProperties.put("apiHeaderGuardPrefix", apiPackage.replaceAll("\\.", "_").toUpperCase(Locale.ROOT));
|
||||||
additionalProperties.put("declspec", declspec);
|
additionalProperties.put("declspec", declspec);
|
||||||
additionalProperties.put("defaultInclude", defaultInclude);
|
additionalProperties.put("defaultInclude", defaultInclude);
|
||||||
|
additionalProperties.put(RESERVED_WORD_PREFIX_OPTION, reservedWordPrefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user