forked from loafle/openapi-generator-original
[Qt5 C++] Replace illegal characters in param names for Qt5 generator (#3978)
* Fix illegal characters in param names * Re-generate the petstore sample
This commit is contained in:
@@ -336,6 +336,33 @@ public class Qt5CPPGenerator extends DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
// sanitize name
|
||||
name = sanitizeName(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
|
||||
// if it's all uppper case, convert to lower case
|
||||
if (name.matches("^[A-Z_]*$")) {
|
||||
name = name.toLowerCase();
|
||||
}
|
||||
|
||||
// camelize (lower first character) the variable name
|
||||
// petId => pet_id
|
||||
name = underscore(name);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (isReservedWord(name) || name.matches("^\\d.*")) {
|
||||
name = escapeReservedWord(name);
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toParamName(String name) {
|
||||
return toVarName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiName(String type) {
|
||||
return PREFIX + Character.toUpperCase(type.charAt(0)) + type.substring(1) + "Api";
|
||||
|
||||
@@ -24,7 +24,7 @@ void
|
||||
fullPath.append(this->host).append(this->basePath).append("{{path}}");
|
||||
|
||||
{{#pathParams}}
|
||||
QString {{paramName}}PathParam("{"); {{paramName}}PathParam.append("{{paramName}}").append("}");
|
||||
QString {{paramName}}PathParam("{"); {{paramName}}PathParam.append("{{baseName}}").append("}");
|
||||
fullPath.replace({{paramName}}PathParam, stringValue({{paramName}}));
|
||||
{{/pathParams}}
|
||||
|
||||
@@ -34,7 +34,7 @@ void
|
||||
fullPath.append("&");
|
||||
else
|
||||
fullPath.append("?");
|
||||
fullPath.append(QUrl::toPercentEncoding("{{paramName}}"))
|
||||
fullPath.append(QUrl::toPercentEncoding("{{baseName}}"))
|
||||
.append("=")
|
||||
.append(QUrl::toPercentEncoding(stringValue({{paramName}})));
|
||||
{{/collectionFormat}}
|
||||
@@ -48,7 +48,7 @@ void
|
||||
fullPath.append("&");
|
||||
else
|
||||
fullPath.append("?");
|
||||
fullPath.append("{{{paramName}}}=").append(stringValue(t));
|
||||
fullPath.append("{{{baseName}}}=").append(stringValue(t));
|
||||
}
|
||||
}
|
||||
else if (QString("{{collectionFormat}}").indexOf("ssv") == 0) {
|
||||
@@ -56,7 +56,7 @@ void
|
||||
fullPath.append("&");
|
||||
else
|
||||
fullPath.append("?");
|
||||
fullPath.append("{{paramName}}=");
|
||||
fullPath.append("{{baseName}}=");
|
||||
qint32 count = 0;
|
||||
foreach({{{baseType}}} t, *{{paramName}}) {
|
||||
if (count > 0) {
|
||||
@@ -70,7 +70,7 @@ void
|
||||
fullPath.append("&");
|
||||
else
|
||||
fullPath.append("?");
|
||||
fullPath.append("{{paramName}}=");
|
||||
fullPath.append("{{baseName}}=");
|
||||
qint32 count = 0;
|
||||
foreach({{{baseType}}} t, *{{paramName}}) {
|
||||
if (count > 0) {
|
||||
@@ -88,7 +88,7 @@ void
|
||||
HttpRequestInput input(fullPath, "{{httpMethod}}");
|
||||
|
||||
{{#formParams}}if ({{paramName}} != NULL) {
|
||||
{{^isFile}}input.add_var("{{paramName}}", *{{paramName}});{{/isFile}}{{#isFile}}input.add_file("{{paramName}}", (*{{paramName}}).local_filename, (*{{paramName}}).request_filename, (*{{paramName}}).mime_type);{{/isFile}}
|
||||
{{^isFile}}input.add_var("{{baseName}}", *{{paramName}});{{/isFile}}{{#isFile}}input.add_file("{{baseName}}", (*{{paramName}}).local_filename, (*{{paramName}}).request_filename, (*{{paramName}}).mime_type);{{/isFile}}
|
||||
}
|
||||
{{/formParams}}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user