[QT5] Support optional params using QVariant (#8733)

Use QVariant for optional parameters
This commit is contained in:
Sean Kelly 2021-03-02 22:45:04 -08:00 committed by GitHub
parent d31875f505
commit 89b9802be3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 800 additions and 606 deletions

View File

@ -227,7 +227,7 @@ QString {{classname}}::getParamStyleDelimiter(QString style, QString name, bool
{{#operations}} {{#operations}}
{{#operation}} {{#operation}}
void {{classname}}::{{nickname}}({{#allParams}}const {{{dataType}}} &{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}) { void {{classname}}::{{nickname}}({{#allParams}}{{#required}}const {{{dataType}}} &{{/required}}{{^required}}const QVariant &{{/required}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}) {
QString fullPath = QString(_serverConfigs["{{nickname}}"][_serverIndices.value("{{nickname}}")].URL()+"{{{path}}}"); QString fullPath = QString(_serverConfigs["{{nickname}}"][_serverIndices.value("{{nickname}}")].URL()+"{{{path}}}");
{{#authMethods}}{{#isApiKey}}{{#isKeyInHeader}} {{#authMethods}}{{#isApiKey}}{{#isKeyInHeader}}
if(_apiKeys.contains("{{name}}")){ if(_apiKeys.contains("{{name}}")){
@ -250,220 +250,235 @@ void {{classname}}::{{nickname}}({{#allParams}}const {{{dataType}}} &{{paramName
b64.append(_username.toUtf8() + ":" + _password.toUtf8()); b64.append(_username.toUtf8() + ":" + _password.toUtf8());
addHeaders("Authorization","Basic " + b64.toBase64()); addHeaders("Authorization","Basic " + b64.toBase64());
}{{/isBasicBasic}}{{/authMethods}} }{{/isBasicBasic}}{{/authMethods}}
{{#pathParams}} {{#pathParams}}
QString {{paramName}}PathParam("{"); {{^required}}if(!{{paramName}}.isNull()){{/required}}
{{paramName}}PathParam.append("{{baseName}}").append("}"); {
QString pathPrefix, pathSuffix, pathDelimiter; QString {{paramName}}PathParam("{");
QString pathStyle = "{{style}}"; {{paramName}}PathParam.append("{{baseName}}").append("}");
if(pathStyle == "") QString pathPrefix, pathSuffix, pathDelimiter;
pathStyle = "simple"; QString pathStyle = "{{style}}";
pathPrefix = getParamStylePrefix(pathStyle); if(pathStyle == "")
pathSuffix = getParamStyleSuffix(pathStyle); pathStyle = "simple";
pathDelimiter = getParamStyleDelimiter(pathStyle, "{{baseName}}", {{isExplode}}); pathPrefix = getParamStylePrefix(pathStyle);
pathSuffix = getParamStyleSuffix(pathStyle);
pathDelimiter = getParamStyleDelimiter(pathStyle, "{{baseName}}", {{isExplode}});
{{^collectionFormat}} {{^collectionFormat}}
{{^isPrimitiveType}} {{^isPrimitiveType}}
QString paramString = (pathStyle == "matrix" && {{isExplode}}) ? pathPrefix : pathPrefix+"{{baseName}}"+pathSuffix; QString paramString = (pathStyle == "matrix" && {{isExplode}}) ? pathPrefix : pathPrefix+"{{baseName}}"+pathSuffix;
QJsonObject parameter = {{paramName}}.asJsonObject(); QJsonObject parameter = {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}.asJsonObject();
qint32 count = 0; qint32 count = 0;
foreach(const QString& key, parameter.keys()) { foreach(const QString& key, parameter.keys()) {
if (count > 0) { if (count > 0) {
pathDelimiter = (pathStyle == "matrix" && {{isExplode}}) ? ";" : getParamStyleDelimiter(pathStyle, key, {{isExplode}}); pathDelimiter = (pathStyle == "matrix" && {{isExplode}}) ? ";" : getParamStyleDelimiter(pathStyle, key, {{isExplode}});
paramString.append(pathDelimiter); paramString.append(pathDelimiter);
}
QString assignOperator = ({{isExplode}}) ? "=" : ",";
switch(parameter.value(key).type()) {
case QJsonValue::String:
{
paramString.append(key+assignOperator+parameter.value(key).toString());
break;
}
case QJsonValue::Double:
{
paramString.append(key+assignOperator+QString::number(parameter.value(key).toDouble()));
break;
}
case QJsonValue::Bool:
{
paramString.append(key+assignOperator+QVariant(parameter.value(key).toBool()).toString());
break;
}
case QJsonValue::Array:
{
paramString.append(key+assignOperator+QVariant(parameter.value(key).toArray()).toString());
break;
}
case QJsonValue::Object:
{
paramString.append(key+assignOperator+QVariant(parameter.value(key).toObject()).toString());
break;
}
case QJsonValue::Null:
case QJsonValue::Undefined:
break;
}
count++;
} }
QString assignOperator = ({{isExplode}}) ? "=" : ","; fullPath.replace({{paramName}}PathParam, QUrl::toPercentEncoding(paramString));
switch(parameter.value(key).type()) { {{/isPrimitiveType}}
case QJsonValue::String: {{#isPrimitiveType}}
{ QString paramString = (pathStyle == "matrix") ? pathPrefix+"{{baseName}}"+pathSuffix : pathPrefix;
paramString.append(key+assignOperator+parameter.value(key).toString()); fullPath.replace({{paramName}}PathParam, paramString+QUrl::toPercentEncoding(::{{cppNamespace}}::toStringValue({{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}})));
break; {{/isPrimitiveType}}
} {{/collectionFormat}}
case QJsonValue::Double: {{#collectionFormat}}
{ if ({{{paramName}}}{{^required}}.value<{{{dataType}}}>(){{/required}}.size() > 0) {
paramString.append(key+assignOperator+QString::number(parameter.value(key).toDouble()));
break;
}
case QJsonValue::Bool:
{
paramString.append(key+assignOperator+QVariant(parameter.value(key).toBool()).toString());
break;
}
case QJsonValue::Array:
{
paramString.append(key+assignOperator+QVariant(parameter.value(key).toArray()).toString());
break;
}
case QJsonValue::Object:
{
paramString.append(key+assignOperator+QVariant(parameter.value(key).toObject()).toString());
break;
}
case QJsonValue::Null:
case QJsonValue::Undefined:
break;
}
count++;
}
fullPath.replace({{paramName}}PathParam, QUrl::toPercentEncoding(paramString));
{{/isPrimitiveType}}
{{#isPrimitiveType}}
QString paramString = (pathStyle == "matrix") ? pathPrefix+"{{baseName}}"+pathSuffix : pathPrefix;
fullPath.replace({{paramName}}PathParam, paramString+QUrl::toPercentEncoding(::{{cppNamespace}}::toStringValue({{paramName}})));
{{/isPrimitiveType}}{{/collectionFormat}}{{#collectionFormat}}
if ({{{paramName}}}.size() > 0) {
QString paramString = (pathStyle == "matrix") ? pathPrefix+"{{baseName}}"+pathSuffix : pathPrefix; QString paramString = (pathStyle == "matrix") ? pathPrefix+"{{baseName}}"+pathSuffix : pathPrefix;
qint32 count = 0; qint32 count = 0;
foreach ({{{baseType}}} t, {{paramName}}) { foreach ({{{baseType}}} t, {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}) {
if (count > 0) { if (count > 0) {
fullPath.append(pathDelimiter); fullPath.append(pathDelimiter);
} }
fullPath.append(QUrl::toPercentEncoding(::{{cppNamespace}}::toStringValue(t))); fullPath.append(QUrl::toPercentEncoding(::{{cppNamespace}}::toStringValue(t)));
count++; count++;
} }
fullPath.replace({{paramName}}PathParam, paramString); fullPath.replace({{paramName}}PathParam, paramString);
}
{{/collectionFormat}}
} }
{{/collectionFormat}}{{/pathParams}}
{{/pathParams}}
{{#hasQueryParams}} {{#hasQueryParams}}
QString queryPrefix, querySuffix, queryDelimiter, queryStyle; QString queryPrefix, querySuffix, queryDelimiter, queryStyle;
{{/hasQueryParams}} {{/hasQueryParams}}
{{#queryParams}} {{#queryParams}}
queryStyle = "{{style}}"; {{^required}}if(!{{paramName}}.isNull()){{/required}}
if(queryStyle == "") {
queryStyle = "form"; queryStyle = "{{style}}";
queryPrefix = getParamStylePrefix(queryStyle); if(queryStyle == "")
querySuffix = getParamStyleSuffix(queryStyle); queryStyle = "form";
queryDelimiter = getParamStyleDelimiter(queryStyle, "{{baseName}}", {{isExplode}}); queryPrefix = getParamStylePrefix(queryStyle);
{{^collectionFormat}} querySuffix = getParamStyleSuffix(queryStyle);
if (fullPath.indexOf("?") > 0) queryDelimiter = getParamStyleDelimiter(queryStyle, "{{baseName}}", {{isExplode}});
fullPath.append(queryPrefix); {{^collectionFormat}}
else if (fullPath.indexOf("?") > 0)
fullPath.append("?"); fullPath.append(queryPrefix);
{{^isPrimitiveType}} else
QString paramString = (queryStyle == "form" && {{isExplode}}) ? "" : (queryStyle == "form" && !({{isExplode}})) ? "{{baseName}}"+querySuffix : ""; fullPath.append("?");
QJsonObject parameter = {{paramName}}.asJsonObject(); {{^isPrimitiveType}}
qint32 count = 0; QString paramString = (queryStyle == "form" && {{isExplode}}) ? "" : (queryStyle == "form" && !({{isExplode}})) ? "{{baseName}}"+querySuffix : "";
foreach(const QString& key, parameter.keys()) { QJsonObject parameter = {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}.asJsonObject();
if (count > 0) { qint32 count = 0;
queryDelimiter = ((queryStyle == "form" || queryStyle == "deepObject") && {{isExplode}}) ? "&" : getParamStyleDelimiter(queryStyle, key, {{isExplode}}); foreach(const QString& key, parameter.keys()) {
paramString.append(queryDelimiter); if (count > 0) {
queryDelimiter = ((queryStyle == "form" || queryStyle == "deepObject") && {{isExplode}}) ? "&" : getParamStyleDelimiter(queryStyle, key, {{isExplode}});
paramString.append(queryDelimiter);
}
QString assignOperator;
if (queryStyle == "form")
assignOperator = ({{isExplode}}) ? "=" : ",";
else if (queryStyle == "deepObject")
assignOperator = ({{isExplode}}) ? "=" : "none";
switch(parameter.value(key).type()) {
case QJsonValue::String:
{
paramString.append(((queryStyle == "form") ? key : QString("{{baseName}}").append("[").append(key).append("]"))+assignOperator+parameter.value(key).toString());
break;
}
case QJsonValue::Double:
{
paramString.append(((queryStyle == "form") ? key : QString("{{baseName}}").append("[").append(key).append("]"))+assignOperator+QString::number(parameter.value(key).toDouble()));
break;
}
case QJsonValue::Bool:
{
paramString.append(((queryStyle == "form") ? key : QString("{{baseName}}").append("[").append(key).append("]"))+assignOperator+QVariant(parameter.value(key).toBool()).toString());
break;
}
case QJsonValue::Array:
{
paramString.append(((queryStyle == "form") ? key : QString("{{baseName}}").append("[").append(key).append("]"))+assignOperator+QVariant(parameter.value(key).toArray()).toString());
break;
}
case QJsonValue::Object:
{
paramString.append(((queryStyle == "form") ? key : QString("{{baseName}}").append("[").append(key).append("]"))+assignOperator+QVariant(parameter.value(key).toObject()).toString());
break;
}
case QJsonValue::Null:
case QJsonValue::Undefined:
break;
}
count++;
} }
QString assignOperator; fullPath.append(paramString);
if (queryStyle == "form") {{/isPrimitiveType}}{{#isPrimitiveType}}
assignOperator = ({{isExplode}}) ? "=" : ","; fullPath.append(QUrl::toPercentEncoding("{{baseName}}")).append(querySuffix).append(QUrl::toPercentEncoding(::{{cppNamespace}}::toStringValue({{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}})));
else if (queryStyle == "deepObject") {{/isPrimitiveType}}
assignOperator = ({{isExplode}}) ? "=" : "none"; {{/collectionFormat}}
switch(parameter.value(key).type()) { {{#collectionFormat}}
case QJsonValue::String: if ({{{paramName}}}{{^required}}.value<{{{dataType}}}>(){{/required}}.size() > 0) {
{ if (QString("{{collectionFormat}}").indexOf("multi") == 0) {
paramString.append(((queryStyle == "form") ? key : QString("{{baseName}}").append("[").append(key).append("]"))+assignOperator+parameter.value(key).toString()); foreach ({{{baseType}}} t, {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}) {
break; if (fullPath.indexOf("?") > 0)
} fullPath.append(queryPrefix);
case QJsonValue::Double: else
{ fullPath.append("?");
paramString.append(((queryStyle == "form") ? key : QString("{{baseName}}").append("[").append(key).append("]"))+assignOperator+QString::number(parameter.value(key).toDouble())); fullPath.append("{{{baseName}}}=").append(::{{cppNamespace}}::toStringValue(t));
break; }
} } else if (QString("{{collectionFormat}}").indexOf("ssv") == 0) {
case QJsonValue::Bool:
{
paramString.append(((queryStyle == "form") ? key : QString("{{baseName}}").append("[").append(key).append("]"))+assignOperator+QVariant(parameter.value(key).toBool()).toString());
break;
}
case QJsonValue::Array:
{
paramString.append(((queryStyle == "form") ? key : QString("{{baseName}}").append("[").append(key).append("]"))+assignOperator+QVariant(parameter.value(key).toArray()).toString());
break;
}
case QJsonValue::Object:
{
paramString.append(((queryStyle == "form") ? key : QString("{{baseName}}").append("[").append(key).append("]"))+assignOperator+QVariant(parameter.value(key).toObject()).toString());
break;
}
case QJsonValue::Null:
case QJsonValue::Undefined:
break;
}
count++;
}
fullPath.append(paramString);
{{/isPrimitiveType}}{{#isPrimitiveType}}
fullPath.append(QUrl::toPercentEncoding("{{baseName}}")).append(querySuffix).append(QUrl::toPercentEncoding(::{{cppNamespace}}::toStringValue({{paramName}})));
{{/isPrimitiveType}}{{/collectionFormat}}{{#collectionFormat}}
if ({{{paramName}}}.size() > 0) {
if (QString("{{collectionFormat}}").indexOf("multi") == 0) {
foreach ({{{baseType}}} t, {{paramName}}) {
if (fullPath.indexOf("?") > 0) if (fullPath.indexOf("?") > 0)
fullPath.append(queryPrefix); fullPath.append("&");
else else
fullPath.append("?"); fullPath.append("?").append(queryPrefix).append("{{baseName}}").append(querySuffix);
fullPath.append("{{{baseName}}}=").append(::{{cppNamespace}}::toStringValue(t)); qint32 count = 0;
} foreach ({{{baseType}}} t, {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}) {
} else if (QString("{{collectionFormat}}").indexOf("ssv") == 0) { if (count > 0) {
if (fullPath.indexOf("?") > 0) fullPath.append(({{isExplode}})? queryDelimiter : QUrl::toPercentEncoding(queryDelimiter));
fullPath.append("&"); }
else fullPath.append(::{{cppNamespace}}::toStringValue(t));
fullPath.append("?").append(queryPrefix).append("{{baseName}}").append(querySuffix); count++;
qint32 count = 0;
foreach ({{{baseType}}} t, {{paramName}}) {
if (count > 0) {
fullPath.append(({{isExplode}})? queryDelimiter : QUrl::toPercentEncoding(queryDelimiter));
} }
fullPath.append(::{{cppNamespace}}::toStringValue(t)); } else if (QString("{{collectionFormat}}").indexOf("tsv") == 0) {
count++; if (fullPath.indexOf("?") > 0)
} fullPath.append("&");
} else if (QString("{{collectionFormat}}").indexOf("tsv") == 0) { else
if (fullPath.indexOf("?") > 0) fullPath.append("?").append(queryPrefix).append("{{baseName}}").append(querySuffix);
fullPath.append("&"); qint32 count = 0;
else foreach ({{{baseType}}} t, {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}) {
fullPath.append("?").append(queryPrefix).append("{{baseName}}").append(querySuffix); if (count > 0) {
qint32 count = 0; fullPath.append("\t");
foreach ({{{baseType}}} t, {{paramName}}) { }
if (count > 0) { fullPath.append(::{{cppNamespace}}::toStringValue(t));
fullPath.append("\t"); count++;
} }
fullPath.append(::{{cppNamespace}}::toStringValue(t)); } else if (QString("{{collectionFormat}}").indexOf("csv") == 0) {
count++; if (fullPath.indexOf("?") > 0)
} fullPath.append("&");
} else if (QString("{{collectionFormat}}").indexOf("csv") == 0) { else
if (fullPath.indexOf("?") > 0) fullPath.append("?").append(queryPrefix).append("{{baseName}}").append(querySuffix);
fullPath.append("&"); qint32 count = 0;
else foreach ({{{baseType}}} t, {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}) {
fullPath.append("?").append(queryPrefix).append("{{baseName}}").append(querySuffix); if (count > 0) {
qint32 count = 0; fullPath.append(queryDelimiter);
foreach ({{{baseType}}} t, {{paramName}}) { }
if (count > 0) { fullPath.append(::{{cppNamespace}}::toStringValue(t));
fullPath.append(queryDelimiter); count++;
} }
fullPath.append(::{{cppNamespace}}::toStringValue(t)); } else if (QString("{{collectionFormat}}").indexOf("pipes") == 0) {
count++; if (fullPath.indexOf("?") > 0)
} fullPath.append("&");
} else if (QString("{{collectionFormat}}").indexOf("pipes") == 0) { else
if (fullPath.indexOf("?") > 0) fullPath.append("?").append(queryPrefix).append("{{baseName}}").append(querySuffix);
fullPath.append("&"); qint32 count = 0;
else foreach ({{{baseType}}} t, {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}) {
fullPath.append("?").append(queryPrefix).append("{{baseName}}").append(querySuffix); if (count > 0) {
qint32 count = 0; fullPath.append(queryDelimiter);
foreach ({{{baseType}}} t, {{paramName}}) { }
if (count > 0) { fullPath.append(::{{cppNamespace}}::toStringValue(t));
fullPath.append(queryDelimiter); count++;
} }
fullPath.append(::{{cppNamespace}}::toStringValue(t)); } else if (QString("{{collectionFormat}}").indexOf("deepObject") == 0) {
count++; if (fullPath.indexOf("?") > 0)
fullPath.append("&");
else
fullPath.append("?").append(queryPrefix).append("{{baseName}}").append(querySuffix);
qint32 count = 0;
foreach ({{{baseType}}} t, {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}) {
if (count > 0) {
fullPath.append(queryDelimiter);
}
fullPath.append(::{{cppNamespace}}::toStringValue(t));
count++;
}
} }
} else if (QString("{{collectionFormat}}").indexOf("deepObject") == 0) {
if (fullPath.indexOf("?") > 0)
fullPath.append("&");
else
fullPath.append("?").append(queryPrefix).append("{{baseName}}").append(querySuffix);
qint32 count = 0;
foreach ({{{baseType}}} t, {{paramName}}) {
if (count > 0) {
fullPath.append(queryDelimiter);
}
fullPath.append(::{{cppNamespace}}::toStringValue(t));
count++;
}
} }
{{/collectionFormat}}
} }
{{/collectionFormat}}{{/queryParams}}
{{/queryParams}}
{{prefix}}HttpRequestWorker *worker = new {{prefix}}HttpRequestWorker(this, _manager); {{prefix}}HttpRequestWorker *worker = new {{prefix}}HttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut); worker->setTimeOut(_timeOut);
worker->setWorkingDirectory(_workingDirectory);{{#contentCompression}} worker->setWorkingDirectory(_workingDirectory);{{#contentCompression}}
@ -481,142 +496,171 @@ void {{classname}}::{{nickname}}({{#allParams}}const {{{dataType}}} &{{paramName
formSuffix = getParamStyleSuffix(formStyle); formSuffix = getParamStyleSuffix(formStyle);
formDelimiter = getParamStyleDelimiter(formStyle, "{{baseName}}", {{isExplode}}); formDelimiter = getParamStyleDelimiter(formStyle, "{{baseName}}", {{isExplode}});
{{/first}} {{/first}}
{{^required}}if(!{{paramName}}.isNull()){{/required}}
{
{{^isFile}} {{^isFile}}
input.add_var("{{baseName}}", ::{{cppNamespace}}::toStringValue({{paramName}}));{{/isFile}}{{#isFile}} input.add_var("{{baseName}}", ::{{cppNamespace}}::toStringValue({{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}));
input.add_file("{{baseName}}", {{paramName}}.local_filename, {{paramName}}.request_filename, {{paramName}}.mime_type);{{/isFile}}{{/formParams}}{{#bodyParams}}{{#isContainer}}{{#isArray}} {{/isFile}}
QJsonDocument doc(::{{cppNamespace}}::toJsonValue({{paramName}}).toArray());{{/isArray}}{{#isMap}} {{#isFile}}
QJsonDocument doc(::{{cppNamespace}}::toJsonValue({{paramName}}).toObject());{{/isMap}} input.add_file("{{baseName}}", {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}.local_filename, {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}.request_filename, {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}.mime_type);
{{/isFile}}
}
{{/formParams}}
{{#bodyParams}}
{{#isContainer}}
{{#isArray}}
QJsonDocument doc(::{{cppNamespace}}::toJsonValue({{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}).toArray());{{/isArray}}{{#isMap}}
QJsonDocument doc(::{{cppNamespace}}::toJsonValue({{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}).toObject());{{/isMap}}
QByteArray bytes = doc.toJson(); QByteArray bytes = doc.toJson();
input.request_body.append(bytes); input.request_body.append(bytes);
{{/isContainer}}{{^isContainer}}{{#isString}} {{/isContainer}}{{^isContainer}}{{#isString}}
QByteArray output = {{paramName}}.toUtf8();{{/isString}}{{#isByteArray}}QByteArray output({{paramName}});{{/isByteArray}}{{^isString}}{{^isByteArray}}{{^isFile}} QByteArray output = {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}.toUtf8();{{/isString}}{{#isByteArray}}QByteArray output({{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}});{{/isByteArray}}{{^isString}}{{^isByteArray}}{{^isFile}}
QByteArray output = {{paramName}}.asJson().toUtf8();{{/isFile}}{{/isByteArray}}{{/isString}}{{#isFile}}{{#hasConsumes}}input.headers.insert("Content-Type", {{#consumes}}{{^-first}}, {{/-first}}"{{mediaType}}"{{/consumes}});{{/hasConsumes}} QByteArray output = {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}.asJson().toUtf8();{{/isFile}}{{/isByteArray}}{{/isString}}{{#isFile}}{{#hasConsumes}}input.headers.insert("Content-Type", {{#consumes}}{{^-first}}, {{/-first}}"{{mediaType}}"{{/consumes}});{{/hasConsumes}}
QByteArray output = {{paramName}}.asByteArray();{{/isFile}} QByteArray output = {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}.asByteArray();{{/isFile}}
input.request_body.append(output); input.request_body.append(output);
{{/isContainer}}{{/bodyParams}}{{#headerParams}} {{/isContainer}}
{{^collectionFormat}}{{^isPrimitiveType}} {{/bodyParams}}
QString headerString; {{#headerParams}}
QJsonObject parameter = {{paramName}}.asJsonObject(); {{^required}}if(!{{paramName}}.isNull()){{/required}}
qint32 count = 0; {
foreach(const QString& key, parameter.keys()) { {{^collectionFormat}}
if (count > 0) { {{^isPrimitiveType}}
headerString.append(","); QString headerString;
QJsonObject parameter = {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}.asJsonObject();
qint32 count = 0;
foreach(const QString& key, parameter.keys()) {
if (count > 0) {
headerString.append(",");
}
QString assignOperator = ({{isExplode}}) ? "=" : ",";
switch(parameter.value(key).type()) {
case QJsonValue::String:
{
headerString.append(key+assignOperator+parameter.value(key).toString());
break;
}
case QJsonValue::Double:
{
headerString.append(key+assignOperator+QString::number(parameter.value(key).toDouble()));
break;
}
case QJsonValue::Bool:
{
headerString.append(key+assignOperator+QVariant(parameter.value(key).toBool()).toString());
break;
}
case QJsonValue::Array:
{
headerString.append(key+assignOperator+QVariant(parameter.value(key).toArray()).toString());
break;
}
case QJsonValue::Object:
{
headerString.append(key+assignOperator+QVariant(parameter.value(key).toObject()).toString());
break;
}
case QJsonValue::Null:
case QJsonValue::Undefined:
break;
}
count++;
} }
QString assignOperator = ({{isExplode}}) ? "=" : ","; input.headers.insert("{{baseName}}", headerString);
switch(parameter.value(key).type()) { {{/isPrimitiveType}}
case QJsonValue::String: {{#isPrimitiveType}}
{ if (!::{{cppNamespace}}::toStringValue({{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}).isEmpty()) {
headerString.append(key+assignOperator+parameter.value(key).toString()); input.headers.insert("{{baseName}}", ::{{cppNamespace}}::toStringValue({{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}));
break;
}
case QJsonValue::Double:
{
headerString.append(key+assignOperator+QString::number(parameter.value(key).toDouble()));
break;
}
case QJsonValue::Bool:
{
headerString.append(key+assignOperator+QVariant(parameter.value(key).toBool()).toString());
break;
}
case QJsonValue::Array:
{
headerString.append(key+assignOperator+QVariant(parameter.value(key).toArray()).toString());
break;
}
case QJsonValue::Object:
{
headerString.append(key+assignOperator+QVariant(parameter.value(key).toObject()).toString());
break;
}
case QJsonValue::Null:
case QJsonValue::Undefined:
break;
} }
count++; {{/isPrimitiveType}}{{/collectionFormat}}{{#collectionFormat}}
} QString headerString;
input.headers.insert("{{baseName}}", headerString); if ({{{paramName}}}{{^required}}.value<{{{dataType}}}>(){{/required}}.size() > 0) {
{{/isPrimitiveType}}{{#isPrimitiveType}} qint32 count = 0;
if (!::{{cppNamespace}}::toStringValue({{paramName}}).isEmpty()) { foreach ({{{baseType}}} t, {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}) {
input.headers.insert("{{baseName}}", ::{{cppNamespace}}::toStringValue({{paramName}})); if (count > 0) {
} headerString.append(",");
{{/isPrimitiveType}}{{/collectionFormat}}{{#collectionFormat}} }
QString headerString; headerString.append(::{{cppNamespace}}::toStringValue(t));
if ({{{paramName}}}.size() > 0) { count++;
qint32 count = 0;
foreach ({{{baseType}}} t, {{paramName}}) {
if (count > 0) {
headerString.append(",");
} }
headerString.append(::{{cppNamespace}}::toStringValue(t)); input.headers.insert("{{baseName}}", headerString);
count++; }
} {{/collectionFormat}}
input.headers.insert("{{baseName}}", headerString); }
}
{{/collectionFormat}}
{{/headerParams}} {{/headerParams}}
{{#cookieParams}} {{#cookieParams}}
if(QString("{{style}}").indexOf("form") == 0){ {{^required}}if(!{{paramName}}.isNull()){{/required}}
{{^collectionFormat}}{{^isPrimitiveType}}{{^isExplode}} {
QString cookieString = "{{baseName}}="; if(QString("{{style}}").indexOf("form") == 0){
QJsonObject parameter = {{paramName}}.asJsonObject(); {{^collectionFormat}}
qint32 count = 0; {{^isPrimitiveType}}
foreach(const QString& key, parameter.keys()) { {{^isExplode}}
if (count > 0) { QString cookieString = "{{baseName}}=";
cookieString.append(","); QJsonObject parameter = {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}.asJsonObject();
qint32 count = 0;
foreach(const QString& key, parameter.keys()) {
if (count > 0) {
cookieString.append(",");
}
switch(parameter.value(key).type()) {
case QJsonValue::String:
{
cookieString.append(key+","+parameter.value(key).toString());
break;
}
case QJsonValue::Double:
{
cookieString.append(key+","+QString::number(parameter.value(key).toDouble()));
break;
}
case QJsonValue::Bool:
{
cookieString.append(key+","+QVariant(parameter.value(key).toBool()).toString());
break;
}
case QJsonValue::Array:
{
cookieString.append(key+","+QVariant(parameter.value(key).toArray()).toString());
break;
}
case QJsonValue::Object:
{
cookieString.append(key+","+QVariant(parameter.value(key).toObject()).toString());
break;
}
case QJsonValue::Null:
case QJsonValue::Undefined:
break;
}
count++;
}
input.headers.insert("Cookie", cookieString);
{{/isExplode}}
{{/isPrimitiveType}}
{{#isPrimitiveType}}
if (!::{{cppNamespace}}::toStringValue({{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}).isEmpty()) {
input.headers.insert("Cookie", "{{baseName}}="+::{{cppNamespace}}::toStringValue({{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}));
}
{{/isPrimitiveType}}
{{/collectionFormat}}
{{#collectionFormat}}
{{^isExplode}}
QString cookieString = "{{baseName}}=";
if ({{{paramName}}}.size() > 0) {
qint32 count = 0;
foreach ({{{baseType}}} t, {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}) {
if (count > 0) {
cookieString.append(",");
}
cookieString.append(::{{cppNamespace}}::toStringValue(t));
count++;
}
input.headers.insert("Cookie", cookieString);
}
{{/isExplode}}{{/collectionFormat}}
} }
switch(parameter.value(key).type()) {
case QJsonValue::String:
{
cookieString.append(key+","+parameter.value(key).toString());
break;
}
case QJsonValue::Double:
{
cookieString.append(key+","+QString::number(parameter.value(key).toDouble()));
break;
}
case QJsonValue::Bool:
{
cookieString.append(key+","+QVariant(parameter.value(key).toBool()).toString());
break;
}
case QJsonValue::Array:
{
cookieString.append(key+","+QVariant(parameter.value(key).toArray()).toString());
break;
}
case QJsonValue::Object:
{
cookieString.append(key+","+QVariant(parameter.value(key).toObject()).toString());
break;
}
case QJsonValue::Null:
case QJsonValue::Undefined:
break;
}
count++;
} }
input.headers.insert("Cookie", cookieString);
{{/isExplode}}{{/isPrimitiveType}}{{#isPrimitiveType}}
if (!::{{cppNamespace}}::toStringValue({{paramName}}).isEmpty()) {
input.headers.insert("Cookie", "{{baseName}}="+::{{cppNamespace}}::toStringValue({{paramName}}));
}
{{/isPrimitiveType}}{{/collectionFormat}}{{#collectionFormat}}{{^isExplode}}
QString cookieString = "{{baseName}}=";
if ({{{paramName}}}.size() > 0) {
qint32 count = 0;
foreach ({{{baseType}}} t, {{paramName}}) {
if (count > 0) {
cookieString.append(",");
}
cookieString.append(::{{cppNamespace}}::toStringValue(t));
count++;
}
input.headers.insert("Cookie", cookieString);
}
{{/isExplode}}{{/collectionFormat}}
}
{{/cookieParams}} {{/cookieParams}}
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); } foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }

View File

@ -13,6 +13,7 @@
#include <QStringList> #include <QStringList>
#include <QList> #include <QList>
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
#include <QVariant>
{{#cppNamespaceDeclarations}} {{#cppNamespaceDeclarations}}
namespace {{this}} { namespace {{this}} {
@ -46,7 +47,18 @@ public:
QString getParamStyleSuffix(QString style); QString getParamStyleSuffix(QString style);
QString getParamStyleDelimiter(QString style, QString name, bool isExplode); QString getParamStyleDelimiter(QString style, QString name, bool isExplode);
{{#operations}}{{#operation}} {{#operations}}{{#operation}}
{{#isDeprecated}}Q_DECL_DEPRECATED {{/isDeprecated}}void {{nickname}}({{#allParams}}const {{{dataType}}} &{{paramName}}{{^-last}}, {{/-last}}{{/allParams}});{{/operation}}{{/operations}} {{#hasParams}} /**
{{#allParams}}
{{#required}}
* @param[in] {{paramName}} {{{dataType}}} [required]
{{/required}}
{{^required}}
* @param[in] {{paramName}} {{{dataType}}} [optional]
{{/required}}
{{/allParams}}
*/{{/hasParams}}
{{#isDeprecated}}Q_DECL_DEPRECATED {{/isDeprecated}}void {{nickname}}({{#allParams}}{{#required}}const {{{dataType}}} &{{/required}}{{^required}}const QVariant &{{/required}}{{paramName}}{{^required}} = QVariant(){{/required}}{{^-last}}, {{/-last}}{{/allParams}});
{{/operation}}{{/operations}}
private: private:
QMap<QString,int> _serverIndices; QMap<QString,int> _serverIndices;

View File

@ -235,7 +235,7 @@ void PetApiTests::updatePetWithFormTest() {
}); });
QString name("gorilla"); QString name("gorilla");
api.updatePetWithForm(id, name, nullptr); api.updatePetWithForm(id, name);
QTimer::singleShot(5000, &loop, &QEventLoop::quit); QTimer::singleShot(5000, &loop, &QEventLoop::quit);
loop.exec(); loop.exec();
QVERIFY2(petUpdated, "didn't finish within timeout"); QVERIFY2(petUpdated, "didn't finish within timeout");

View File

@ -235,7 +235,6 @@ void PFXPetApi::addPet(const PFXPet &body) {
QString fullPath = QString(_serverConfigs["addPet"][_serverIndices.value("addPet")].URL()+"/pet"); QString fullPath = QString(_serverConfigs["addPet"][_serverIndices.value("addPet")].URL()+"/pet");
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut); worker->setTimeOut(_timeOut);
worker->setWorkingDirectory(_workingDirectory); worker->setWorkingDirectory(_workingDirectory);
@ -273,31 +272,35 @@ void PFXPetApi::addPetCallback(PFXHttpRequestWorker *worker) {
} }
} }
void PFXPetApi::deletePet(const qint64 &pet_id, const QString &api_key) { void PFXPetApi::deletePet(const qint64 &pet_id, const QVariant &api_key) {
QString fullPath = QString(_serverConfigs["deletePet"][_serverIndices.value("deletePet")].URL()+"/pet/{petId}"); QString fullPath = QString(_serverConfigs["deletePet"][_serverIndices.value("deletePet")].URL()+"/pet/{petId}");
QString pet_idPathParam("{");
pet_idPathParam.append("petId").append("}");
QString pathPrefix, pathSuffix, pathDelimiter;
QString pathStyle = "";
if(pathStyle == "")
pathStyle = "simple";
pathPrefix = getParamStylePrefix(pathStyle);
pathSuffix = getParamStyleSuffix(pathStyle);
pathDelimiter = getParamStyleDelimiter(pathStyle, "petId", false);
QString paramString = (pathStyle == "matrix") ? pathPrefix+"petId"+pathSuffix : pathPrefix;
fullPath.replace(pet_idPathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(pet_id)));
{
QString pet_idPathParam("{");
pet_idPathParam.append("petId").append("}");
QString pathPrefix, pathSuffix, pathDelimiter;
QString pathStyle = "";
if(pathStyle == "")
pathStyle = "simple";
pathPrefix = getParamStylePrefix(pathStyle);
pathSuffix = getParamStyleSuffix(pathStyle);
pathDelimiter = getParamStyleDelimiter(pathStyle, "petId", false);
QString paramString = (pathStyle == "matrix") ? pathPrefix+"petId"+pathSuffix : pathPrefix;
fullPath.replace(pet_idPathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(pet_id)));
}
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut); worker->setTimeOut(_timeOut);
worker->setWorkingDirectory(_workingDirectory); worker->setWorkingDirectory(_workingDirectory);
PFXHttpRequestInput input(fullPath, "DELETE"); PFXHttpRequestInput input(fullPath, "DELETE");
if(!api_key.isNull())
{
if (!::test_namespace::toStringValue(api_key).isEmpty()) { if (!::test_namespace::toStringValue(api_key.value<QString>()).isEmpty()) {
input.headers.insert("api_key", ::test_namespace::toStringValue(api_key)); input.headers.insert("api_key", ::test_namespace::toStringValue(api_key.value<QString>()));
}
} }
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); } foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
@ -333,87 +336,89 @@ void PFXPetApi::findPetsByStatus(const QList<QString> &status) {
QString queryPrefix, querySuffix, queryDelimiter, queryStyle; QString queryPrefix, querySuffix, queryDelimiter, queryStyle;
queryStyle = "form";
if(queryStyle == "") {
queryStyle = "form"; queryStyle = "form";
queryPrefix = getParamStylePrefix(queryStyle); if(queryStyle == "")
querySuffix = getParamStyleSuffix(queryStyle); queryStyle = "form";
queryDelimiter = getParamStyleDelimiter(queryStyle, "status", false); queryPrefix = getParamStylePrefix(queryStyle);
querySuffix = getParamStyleSuffix(queryStyle);
if (status.size() > 0) { queryDelimiter = getParamStyleDelimiter(queryStyle, "status", false);
if (QString("csv").indexOf("multi") == 0) { if (status.size() > 0) {
foreach (QString t, status) { if (QString("csv").indexOf("multi") == 0) {
foreach (QString t, status) {
if (fullPath.indexOf("?") > 0)
fullPath.append(queryPrefix);
else
fullPath.append("?");
fullPath.append("status=").append(::test_namespace::toStringValue(t));
}
} else if (QString("csv").indexOf("ssv") == 0) {
if (fullPath.indexOf("?") > 0) if (fullPath.indexOf("?") > 0)
fullPath.append(queryPrefix); fullPath.append("&");
else else
fullPath.append("?"); fullPath.append("?").append(queryPrefix).append("status").append(querySuffix);
fullPath.append("status=").append(::test_namespace::toStringValue(t)); qint32 count = 0;
} foreach (QString t, status) {
} else if (QString("csv").indexOf("ssv") == 0) { if (count > 0) {
if (fullPath.indexOf("?") > 0) fullPath.append((false)? queryDelimiter : QUrl::toPercentEncoding(queryDelimiter));
fullPath.append("&"); }
else fullPath.append(::test_namespace::toStringValue(t));
fullPath.append("?").append(queryPrefix).append("status").append(querySuffix); count++;
qint32 count = 0;
foreach (QString t, status) {
if (count > 0) {
fullPath.append((false)? queryDelimiter : QUrl::toPercentEncoding(queryDelimiter));
} }
fullPath.append(::test_namespace::toStringValue(t)); } else if (QString("csv").indexOf("tsv") == 0) {
count++; if (fullPath.indexOf("?") > 0)
} fullPath.append("&");
} else if (QString("csv").indexOf("tsv") == 0) { else
if (fullPath.indexOf("?") > 0) fullPath.append("?").append(queryPrefix).append("status").append(querySuffix);
fullPath.append("&"); qint32 count = 0;
else foreach (QString t, status) {
fullPath.append("?").append(queryPrefix).append("status").append(querySuffix); if (count > 0) {
qint32 count = 0; fullPath.append("\t");
foreach (QString t, status) { }
if (count > 0) { fullPath.append(::test_namespace::toStringValue(t));
fullPath.append("\t"); count++;
} }
fullPath.append(::test_namespace::toStringValue(t)); } else if (QString("csv").indexOf("csv") == 0) {
count++; if (fullPath.indexOf("?") > 0)
} fullPath.append("&");
} else if (QString("csv").indexOf("csv") == 0) { else
if (fullPath.indexOf("?") > 0) fullPath.append("?").append(queryPrefix).append("status").append(querySuffix);
fullPath.append("&"); qint32 count = 0;
else foreach (QString t, status) {
fullPath.append("?").append(queryPrefix).append("status").append(querySuffix); if (count > 0) {
qint32 count = 0; fullPath.append(queryDelimiter);
foreach (QString t, status) { }
if (count > 0) { fullPath.append(::test_namespace::toStringValue(t));
fullPath.append(queryDelimiter); count++;
} }
fullPath.append(::test_namespace::toStringValue(t)); } else if (QString("csv").indexOf("pipes") == 0) {
count++; if (fullPath.indexOf("?") > 0)
} fullPath.append("&");
} else if (QString("csv").indexOf("pipes") == 0) { else
if (fullPath.indexOf("?") > 0) fullPath.append("?").append(queryPrefix).append("status").append(querySuffix);
fullPath.append("&"); qint32 count = 0;
else foreach (QString t, status) {
fullPath.append("?").append(queryPrefix).append("status").append(querySuffix); if (count > 0) {
qint32 count = 0; fullPath.append(queryDelimiter);
foreach (QString t, status) { }
if (count > 0) { fullPath.append(::test_namespace::toStringValue(t));
fullPath.append(queryDelimiter); count++;
} }
fullPath.append(::test_namespace::toStringValue(t)); } else if (QString("csv").indexOf("deepObject") == 0) {
count++; if (fullPath.indexOf("?") > 0)
fullPath.append("&");
else
fullPath.append("?").append(queryPrefix).append("status").append(querySuffix);
qint32 count = 0;
foreach (QString t, status) {
if (count > 0) {
fullPath.append(queryDelimiter);
}
fullPath.append(::test_namespace::toStringValue(t));
count++;
}
} }
} else if (QString("csv").indexOf("deepObject") == 0) {
if (fullPath.indexOf("?") > 0)
fullPath.append("&");
else
fullPath.append("?").append(queryPrefix).append("status").append(querySuffix);
qint32 count = 0;
foreach (QString t, status) {
if (count > 0) {
fullPath.append(queryDelimiter);
}
fullPath.append(::test_namespace::toStringValue(t));
count++;
}
} }
} }
@ -466,87 +471,89 @@ void PFXPetApi::findPetsByTags(const QList<QString> &tags) {
QString queryPrefix, querySuffix, queryDelimiter, queryStyle; QString queryPrefix, querySuffix, queryDelimiter, queryStyle;
queryStyle = "form";
if(queryStyle == "") {
queryStyle = "form"; queryStyle = "form";
queryPrefix = getParamStylePrefix(queryStyle); if(queryStyle == "")
querySuffix = getParamStyleSuffix(queryStyle); queryStyle = "form";
queryDelimiter = getParamStyleDelimiter(queryStyle, "tags", false); queryPrefix = getParamStylePrefix(queryStyle);
querySuffix = getParamStyleSuffix(queryStyle);
if (tags.size() > 0) { queryDelimiter = getParamStyleDelimiter(queryStyle, "tags", false);
if (QString("csv").indexOf("multi") == 0) { if (tags.size() > 0) {
foreach (QString t, tags) { if (QString("csv").indexOf("multi") == 0) {
foreach (QString t, tags) {
if (fullPath.indexOf("?") > 0)
fullPath.append(queryPrefix);
else
fullPath.append("?");
fullPath.append("tags=").append(::test_namespace::toStringValue(t));
}
} else if (QString("csv").indexOf("ssv") == 0) {
if (fullPath.indexOf("?") > 0) if (fullPath.indexOf("?") > 0)
fullPath.append(queryPrefix); fullPath.append("&");
else else
fullPath.append("?"); fullPath.append("?").append(queryPrefix).append("tags").append(querySuffix);
fullPath.append("tags=").append(::test_namespace::toStringValue(t)); qint32 count = 0;
} foreach (QString t, tags) {
} else if (QString("csv").indexOf("ssv") == 0) { if (count > 0) {
if (fullPath.indexOf("?") > 0) fullPath.append((false)? queryDelimiter : QUrl::toPercentEncoding(queryDelimiter));
fullPath.append("&"); }
else fullPath.append(::test_namespace::toStringValue(t));
fullPath.append("?").append(queryPrefix).append("tags").append(querySuffix); count++;
qint32 count = 0;
foreach (QString t, tags) {
if (count > 0) {
fullPath.append((false)? queryDelimiter : QUrl::toPercentEncoding(queryDelimiter));
} }
fullPath.append(::test_namespace::toStringValue(t)); } else if (QString("csv").indexOf("tsv") == 0) {
count++; if (fullPath.indexOf("?") > 0)
} fullPath.append("&");
} else if (QString("csv").indexOf("tsv") == 0) { else
if (fullPath.indexOf("?") > 0) fullPath.append("?").append(queryPrefix).append("tags").append(querySuffix);
fullPath.append("&"); qint32 count = 0;
else foreach (QString t, tags) {
fullPath.append("?").append(queryPrefix).append("tags").append(querySuffix); if (count > 0) {
qint32 count = 0; fullPath.append("\t");
foreach (QString t, tags) { }
if (count > 0) { fullPath.append(::test_namespace::toStringValue(t));
fullPath.append("\t"); count++;
} }
fullPath.append(::test_namespace::toStringValue(t)); } else if (QString("csv").indexOf("csv") == 0) {
count++; if (fullPath.indexOf("?") > 0)
} fullPath.append("&");
} else if (QString("csv").indexOf("csv") == 0) { else
if (fullPath.indexOf("?") > 0) fullPath.append("?").append(queryPrefix).append("tags").append(querySuffix);
fullPath.append("&"); qint32 count = 0;
else foreach (QString t, tags) {
fullPath.append("?").append(queryPrefix).append("tags").append(querySuffix); if (count > 0) {
qint32 count = 0; fullPath.append(queryDelimiter);
foreach (QString t, tags) { }
if (count > 0) { fullPath.append(::test_namespace::toStringValue(t));
fullPath.append(queryDelimiter); count++;
} }
fullPath.append(::test_namespace::toStringValue(t)); } else if (QString("csv").indexOf("pipes") == 0) {
count++; if (fullPath.indexOf("?") > 0)
} fullPath.append("&");
} else if (QString("csv").indexOf("pipes") == 0) { else
if (fullPath.indexOf("?") > 0) fullPath.append("?").append(queryPrefix).append("tags").append(querySuffix);
fullPath.append("&"); qint32 count = 0;
else foreach (QString t, tags) {
fullPath.append("?").append(queryPrefix).append("tags").append(querySuffix); if (count > 0) {
qint32 count = 0; fullPath.append(queryDelimiter);
foreach (QString t, tags) { }
if (count > 0) { fullPath.append(::test_namespace::toStringValue(t));
fullPath.append(queryDelimiter); count++;
} }
fullPath.append(::test_namespace::toStringValue(t)); } else if (QString("csv").indexOf("deepObject") == 0) {
count++; if (fullPath.indexOf("?") > 0)
fullPath.append("&");
else
fullPath.append("?").append(queryPrefix).append("tags").append(querySuffix);
qint32 count = 0;
foreach (QString t, tags) {
if (count > 0) {
fullPath.append(queryDelimiter);
}
fullPath.append(::test_namespace::toStringValue(t));
count++;
}
} }
} else if (QString("csv").indexOf("deepObject") == 0) {
if (fullPath.indexOf("?") > 0)
fullPath.append("&");
else
fullPath.append("?").append(queryPrefix).append("tags").append(querySuffix);
qint32 count = 0;
foreach (QString t, tags) {
if (count > 0) {
fullPath.append(queryDelimiter);
}
fullPath.append(::test_namespace::toStringValue(t));
count++;
}
} }
} }
@ -601,18 +608,21 @@ void PFXPetApi::getPetById(const qint64 &pet_id) {
addHeaders("api_key",_apiKeys.find("api_key").value()); addHeaders("api_key",_apiKeys.find("api_key").value());
} }
QString pet_idPathParam("{");
pet_idPathParam.append("petId").append("}");
QString pathPrefix, pathSuffix, pathDelimiter;
QString pathStyle = "";
if(pathStyle == "")
pathStyle = "simple";
pathPrefix = getParamStylePrefix(pathStyle);
pathSuffix = getParamStyleSuffix(pathStyle);
pathDelimiter = getParamStyleDelimiter(pathStyle, "petId", false);
QString paramString = (pathStyle == "matrix") ? pathPrefix+"petId"+pathSuffix : pathPrefix;
fullPath.replace(pet_idPathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(pet_id)));
{
QString pet_idPathParam("{");
pet_idPathParam.append("petId").append("}");
QString pathPrefix, pathSuffix, pathDelimiter;
QString pathStyle = "";
if(pathStyle == "")
pathStyle = "simple";
pathPrefix = getParamStylePrefix(pathStyle);
pathSuffix = getParamStyleSuffix(pathStyle);
pathDelimiter = getParamStyleDelimiter(pathStyle, "petId", false);
QString paramString = (pathStyle == "matrix") ? pathPrefix+"petId"+pathSuffix : pathPrefix;
fullPath.replace(pet_idPathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(pet_id)));
}
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut); worker->setTimeOut(_timeOut);
@ -653,7 +663,6 @@ void PFXPetApi::updatePet(const PFXPet &body) {
QString fullPath = QString(_serverConfigs["updatePet"][_serverIndices.value("updatePet")].URL()+"/pet"); QString fullPath = QString(_serverConfigs["updatePet"][_serverIndices.value("updatePet")].URL()+"/pet");
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut); worker->setTimeOut(_timeOut);
worker->setWorkingDirectory(_workingDirectory); worker->setWorkingDirectory(_workingDirectory);
@ -691,28 +700,43 @@ void PFXPetApi::updatePetCallback(PFXHttpRequestWorker *worker) {
} }
} }
void PFXPetApi::updatePetWithForm(const qint64 &pet_id, const QString &name, const QString &status) { void PFXPetApi::updatePetWithForm(const qint64 &pet_id, const QVariant &name, const QVariant &status) {
QString fullPath = QString(_serverConfigs["updatePetWithForm"][_serverIndices.value("updatePetWithForm")].URL()+"/pet/{petId}"); QString fullPath = QString(_serverConfigs["updatePetWithForm"][_serverIndices.value("updatePetWithForm")].URL()+"/pet/{petId}");
QString pet_idPathParam("{");
pet_idPathParam.append("petId").append("}");
QString pathPrefix, pathSuffix, pathDelimiter;
QString pathStyle = "";
if(pathStyle == "")
pathStyle = "simple";
pathPrefix = getParamStylePrefix(pathStyle);
pathSuffix = getParamStyleSuffix(pathStyle);
pathDelimiter = getParamStyleDelimiter(pathStyle, "petId", false);
QString paramString = (pathStyle == "matrix") ? pathPrefix+"petId"+pathSuffix : pathPrefix;
fullPath.replace(pet_idPathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(pet_id)));
{
QString pet_idPathParam("{");
pet_idPathParam.append("petId").append("}");
QString pathPrefix, pathSuffix, pathDelimiter;
QString pathStyle = "";
if(pathStyle == "")
pathStyle = "simple";
pathPrefix = getParamStylePrefix(pathStyle);
pathSuffix = getParamStyleSuffix(pathStyle);
pathDelimiter = getParamStyleDelimiter(pathStyle, "petId", false);
QString paramString = (pathStyle == "matrix") ? pathPrefix+"petId"+pathSuffix : pathPrefix;
fullPath.replace(pet_idPathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(pet_id)));
}
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut); worker->setTimeOut(_timeOut);
worker->setWorkingDirectory(_workingDirectory); worker->setWorkingDirectory(_workingDirectory);
PFXHttpRequestInput input(fullPath, "POST"); PFXHttpRequestInput input(fullPath, "POST");
input.add_var("name", ::test_namespace::toStringValue(name)); input.add_var("status", ::test_namespace::toStringValue(status)); foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
if(!name.isNull())
{
input.add_var("name", ::test_namespace::toStringValue(name.value<QString>()));
}
if(!status.isNull())
{
input.add_var("status", ::test_namespace::toStringValue(status.value<QString>()));
}
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::updatePetWithFormCallback); connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::updatePetWithFormCallback);
connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater); connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater);
@ -741,29 +765,43 @@ void PFXPetApi::updatePetWithFormCallback(PFXHttpRequestWorker *worker) {
} }
} }
void PFXPetApi::uploadFile(const qint64 &pet_id, const QString &additional_metadata, const PFXHttpFileElement &file) { void PFXPetApi::uploadFile(const qint64 &pet_id, const QVariant &additional_metadata, const QVariant &file) {
QString fullPath = QString(_serverConfigs["uploadFile"][_serverIndices.value("uploadFile")].URL()+"/pet/{petId}/uploadImage"); QString fullPath = QString(_serverConfigs["uploadFile"][_serverIndices.value("uploadFile")].URL()+"/pet/{petId}/uploadImage");
QString pet_idPathParam("{");
pet_idPathParam.append("petId").append("}");
QString pathPrefix, pathSuffix, pathDelimiter;
QString pathStyle = "";
if(pathStyle == "")
pathStyle = "simple";
pathPrefix = getParamStylePrefix(pathStyle);
pathSuffix = getParamStyleSuffix(pathStyle);
pathDelimiter = getParamStyleDelimiter(pathStyle, "petId", false);
QString paramString = (pathStyle == "matrix") ? pathPrefix+"petId"+pathSuffix : pathPrefix;
fullPath.replace(pet_idPathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(pet_id)));
{
QString pet_idPathParam("{");
pet_idPathParam.append("petId").append("}");
QString pathPrefix, pathSuffix, pathDelimiter;
QString pathStyle = "";
if(pathStyle == "")
pathStyle = "simple";
pathPrefix = getParamStylePrefix(pathStyle);
pathSuffix = getParamStyleSuffix(pathStyle);
pathDelimiter = getParamStyleDelimiter(pathStyle, "petId", false);
QString paramString = (pathStyle == "matrix") ? pathPrefix+"petId"+pathSuffix : pathPrefix;
fullPath.replace(pet_idPathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(pet_id)));
}
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut); worker->setTimeOut(_timeOut);
worker->setWorkingDirectory(_workingDirectory); worker->setWorkingDirectory(_workingDirectory);
PFXHttpRequestInput input(fullPath, "POST"); PFXHttpRequestInput input(fullPath, "POST");
input.add_var("additionalMetadata", ::test_namespace::toStringValue(additional_metadata));
input.add_file("file", file.local_filename, file.request_filename, file.mime_type); foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); } if(!additional_metadata.isNull())
{
input.add_var("additionalMetadata", ::test_namespace::toStringValue(additional_metadata.value<QString>()));
}
if(!file.isNull())
{
input.add_file("file", file.value<PFXHttpFileElement>().local_filename, file.value<PFXHttpFileElement>().request_filename, file.value<PFXHttpFileElement>().mime_type);
}
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::uploadFileCallback); connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::uploadFileCallback);
connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater); connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater);

View File

@ -25,6 +25,7 @@
#include <QStringList> #include <QStringList>
#include <QList> #include <QList>
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
#include <QVariant>
namespace test_namespace { namespace test_namespace {
@ -56,14 +57,51 @@ public:
QString getParamStyleSuffix(QString style); QString getParamStyleSuffix(QString style);
QString getParamStyleDelimiter(QString style, QString name, bool isExplode); QString getParamStyleDelimiter(QString style, QString name, bool isExplode);
/**
* @param[in] body PFXPet [required]
*/
void addPet(const PFXPet &body); void addPet(const PFXPet &body);
void deletePet(const qint64 &pet_id, const QString &api_key);
/**
* @param[in] pet_id qint64 [required]
* @param[in] api_key QString [optional]
*/
void deletePet(const qint64 &pet_id, const QVariant &api_key = QVariant());
/**
* @param[in] status QList<QString> [required]
*/
void findPetsByStatus(const QList<QString> &status); void findPetsByStatus(const QList<QString> &status);
/**
* @param[in] tags QList<QString> [required]
*/
Q_DECL_DEPRECATED void findPetsByTags(const QList<QString> &tags); Q_DECL_DEPRECATED void findPetsByTags(const QList<QString> &tags);
/**
* @param[in] pet_id qint64 [required]
*/
void getPetById(const qint64 &pet_id); void getPetById(const qint64 &pet_id);
/**
* @param[in] body PFXPet [required]
*/
void updatePet(const PFXPet &body); void updatePet(const PFXPet &body);
void updatePetWithForm(const qint64 &pet_id, const QString &name, const QString &status);
void uploadFile(const qint64 &pet_id, const QString &additional_metadata, const PFXHttpFileElement &file); /**
* @param[in] pet_id qint64 [required]
* @param[in] name QString [optional]
* @param[in] status QString [optional]
*/
void updatePetWithForm(const qint64 &pet_id, const QVariant &name = QVariant(), const QVariant &status = QVariant());
/**
* @param[in] pet_id qint64 [required]
* @param[in] additional_metadata QString [optional]
* @param[in] file PFXHttpFileElement [optional]
*/
void uploadFile(const qint64 &pet_id, const QVariant &additional_metadata = QVariant(), const QVariant &file = QVariant());
private: private:
QMap<QString,int> _serverIndices; QMap<QString,int> _serverIndices;

View File

@ -222,18 +222,21 @@ QString PFXStoreApi::getParamStyleDelimiter(QString style, QString name, bool is
void PFXStoreApi::deleteOrder(const QString &order_id) { void PFXStoreApi::deleteOrder(const QString &order_id) {
QString fullPath = QString(_serverConfigs["deleteOrder"][_serverIndices.value("deleteOrder")].URL()+"/store/order/{orderId}"); QString fullPath = QString(_serverConfigs["deleteOrder"][_serverIndices.value("deleteOrder")].URL()+"/store/order/{orderId}");
QString order_idPathParam("{");
order_idPathParam.append("orderId").append("}");
QString pathPrefix, pathSuffix, pathDelimiter;
QString pathStyle = "";
if(pathStyle == "")
pathStyle = "simple";
pathPrefix = getParamStylePrefix(pathStyle);
pathSuffix = getParamStyleSuffix(pathStyle);
pathDelimiter = getParamStyleDelimiter(pathStyle, "orderId", false);
QString paramString = (pathStyle == "matrix") ? pathPrefix+"orderId"+pathSuffix : pathPrefix;
fullPath.replace(order_idPathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(order_id)));
{
QString order_idPathParam("{");
order_idPathParam.append("orderId").append("}");
QString pathPrefix, pathSuffix, pathDelimiter;
QString pathStyle = "";
if(pathStyle == "")
pathStyle = "simple";
pathPrefix = getParamStylePrefix(pathStyle);
pathSuffix = getParamStyleSuffix(pathStyle);
pathDelimiter = getParamStyleDelimiter(pathStyle, "orderId", false);
QString paramString = (pathStyle == "matrix") ? pathPrefix+"orderId"+pathSuffix : pathPrefix;
fullPath.replace(order_idPathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(order_id)));
}
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut); worker->setTimeOut(_timeOut);
@ -277,7 +280,6 @@ void PFXStoreApi::getInventory() {
} }
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut); worker->setTimeOut(_timeOut);
worker->setWorkingDirectory(_workingDirectory); worker->setWorkingDirectory(_workingDirectory);
@ -325,18 +327,21 @@ void PFXStoreApi::getInventoryCallback(PFXHttpRequestWorker *worker) {
void PFXStoreApi::getOrderById(const qint64 &order_id) { void PFXStoreApi::getOrderById(const qint64 &order_id) {
QString fullPath = QString(_serverConfigs["getOrderById"][_serverIndices.value("getOrderById")].URL()+"/store/order/{orderId}"); QString fullPath = QString(_serverConfigs["getOrderById"][_serverIndices.value("getOrderById")].URL()+"/store/order/{orderId}");
QString order_idPathParam("{");
order_idPathParam.append("orderId").append("}");
QString pathPrefix, pathSuffix, pathDelimiter;
QString pathStyle = "";
if(pathStyle == "")
pathStyle = "simple";
pathPrefix = getParamStylePrefix(pathStyle);
pathSuffix = getParamStyleSuffix(pathStyle);
pathDelimiter = getParamStyleDelimiter(pathStyle, "orderId", false);
QString paramString = (pathStyle == "matrix") ? pathPrefix+"orderId"+pathSuffix : pathPrefix;
fullPath.replace(order_idPathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(order_id)));
{
QString order_idPathParam("{");
order_idPathParam.append("orderId").append("}");
QString pathPrefix, pathSuffix, pathDelimiter;
QString pathStyle = "";
if(pathStyle == "")
pathStyle = "simple";
pathPrefix = getParamStylePrefix(pathStyle);
pathSuffix = getParamStyleSuffix(pathStyle);
pathDelimiter = getParamStyleDelimiter(pathStyle, "orderId", false);
QString paramString = (pathStyle == "matrix") ? pathPrefix+"orderId"+pathSuffix : pathPrefix;
fullPath.replace(order_idPathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(order_id)));
}
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut); worker->setTimeOut(_timeOut);
@ -377,7 +382,6 @@ void PFXStoreApi::placeOrder(const PFXOrder &body) {
QString fullPath = QString(_serverConfigs["placeOrder"][_serverIndices.value("placeOrder")].URL()+"/store/order"); QString fullPath = QString(_serverConfigs["placeOrder"][_serverIndices.value("placeOrder")].URL()+"/store/order");
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut); worker->setTimeOut(_timeOut);
worker->setWorkingDirectory(_workingDirectory); worker->setWorkingDirectory(_workingDirectory);

View File

@ -24,6 +24,7 @@
#include <QStringList> #include <QStringList>
#include <QList> #include <QList>
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
#include <QVariant>
namespace test_namespace { namespace test_namespace {
@ -55,11 +56,25 @@ public:
QString getParamStyleSuffix(QString style); QString getParamStyleSuffix(QString style);
QString getParamStyleDelimiter(QString style, QString name, bool isExplode); QString getParamStyleDelimiter(QString style, QString name, bool isExplode);
/**
* @param[in] order_id QString [required]
*/
void deleteOrder(const QString &order_id); void deleteOrder(const QString &order_id);
void getInventory(); void getInventory();
/**
* @param[in] order_id qint64 [required]
*/
void getOrderById(const qint64 &order_id); void getOrderById(const qint64 &order_id);
/**
* @param[in] body PFXOrder [required]
*/
void placeOrder(const PFXOrder &body); void placeOrder(const PFXOrder &body);
private: private:
QMap<QString,int> _serverIndices; QMap<QString,int> _serverIndices;
QMap<QString,QList<PFXServerConfiguration>> _serverConfigs; QMap<QString,QList<PFXServerConfiguration>> _serverConfigs;

View File

@ -235,7 +235,6 @@ void PFXUserApi::createUser(const PFXUser &body) {
QString fullPath = QString(_serverConfigs["createUser"][_serverIndices.value("createUser")].URL()+"/user"); QString fullPath = QString(_serverConfigs["createUser"][_serverIndices.value("createUser")].URL()+"/user");
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut); worker->setTimeOut(_timeOut);
worker->setWorkingDirectory(_workingDirectory); worker->setWorkingDirectory(_workingDirectory);
@ -277,13 +276,11 @@ void PFXUserApi::createUsersWithArrayInput(const QList<PFXUser> &body) {
QString fullPath = QString(_serverConfigs["createUsersWithArrayInput"][_serverIndices.value("createUsersWithArrayInput")].URL()+"/user/createWithArray"); QString fullPath = QString(_serverConfigs["createUsersWithArrayInput"][_serverIndices.value("createUsersWithArrayInput")].URL()+"/user/createWithArray");
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut); worker->setTimeOut(_timeOut);
worker->setWorkingDirectory(_workingDirectory); worker->setWorkingDirectory(_workingDirectory);
PFXHttpRequestInput input(fullPath, "POST"); PFXHttpRequestInput input(fullPath, "POST");
QJsonDocument doc(::test_namespace::toJsonValue(body).toArray()); QJsonDocument doc(::test_namespace::toJsonValue(body).toArray());
QByteArray bytes = doc.toJson(); QByteArray bytes = doc.toJson();
input.request_body.append(bytes); input.request_body.append(bytes);
@ -320,13 +317,11 @@ void PFXUserApi::createUsersWithListInput(const QList<PFXUser> &body) {
QString fullPath = QString(_serverConfigs["createUsersWithListInput"][_serverIndices.value("createUsersWithListInput")].URL()+"/user/createWithList"); QString fullPath = QString(_serverConfigs["createUsersWithListInput"][_serverIndices.value("createUsersWithListInput")].URL()+"/user/createWithList");
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut); worker->setTimeOut(_timeOut);
worker->setWorkingDirectory(_workingDirectory); worker->setWorkingDirectory(_workingDirectory);
PFXHttpRequestInput input(fullPath, "POST"); PFXHttpRequestInput input(fullPath, "POST");
QJsonDocument doc(::test_namespace::toJsonValue(body).toArray()); QJsonDocument doc(::test_namespace::toJsonValue(body).toArray());
QByteArray bytes = doc.toJson(); QByteArray bytes = doc.toJson();
input.request_body.append(bytes); input.request_body.append(bytes);
@ -362,18 +357,21 @@ void PFXUserApi::createUsersWithListInputCallback(PFXHttpRequestWorker *worker)
void PFXUserApi::deleteUser(const QString &username) { void PFXUserApi::deleteUser(const QString &username) {
QString fullPath = QString(_serverConfigs["deleteUser"][_serverIndices.value("deleteUser")].URL()+"/user/{username}"); QString fullPath = QString(_serverConfigs["deleteUser"][_serverIndices.value("deleteUser")].URL()+"/user/{username}");
QString usernamePathParam("{");
usernamePathParam.append("username").append("}");
QString pathPrefix, pathSuffix, pathDelimiter;
QString pathStyle = "";
if(pathStyle == "")
pathStyle = "simple";
pathPrefix = getParamStylePrefix(pathStyle);
pathSuffix = getParamStyleSuffix(pathStyle);
pathDelimiter = getParamStyleDelimiter(pathStyle, "username", false);
QString paramString = (pathStyle == "matrix") ? pathPrefix+"username"+pathSuffix : pathPrefix;
fullPath.replace(usernamePathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(username)));
{
QString usernamePathParam("{");
usernamePathParam.append("username").append("}");
QString pathPrefix, pathSuffix, pathDelimiter;
QString pathStyle = "";
if(pathStyle == "")
pathStyle = "simple";
pathPrefix = getParamStylePrefix(pathStyle);
pathSuffix = getParamStyleSuffix(pathStyle);
pathDelimiter = getParamStyleDelimiter(pathStyle, "username", false);
QString paramString = (pathStyle == "matrix") ? pathPrefix+"username"+pathSuffix : pathPrefix;
fullPath.replace(usernamePathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(username)));
}
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut); worker->setTimeOut(_timeOut);
@ -412,18 +410,21 @@ void PFXUserApi::deleteUserCallback(PFXHttpRequestWorker *worker) {
void PFXUserApi::getUserByName(const QString &username) { void PFXUserApi::getUserByName(const QString &username) {
QString fullPath = QString(_serverConfigs["getUserByName"][_serverIndices.value("getUserByName")].URL()+"/user/{username}"); QString fullPath = QString(_serverConfigs["getUserByName"][_serverIndices.value("getUserByName")].URL()+"/user/{username}");
QString usernamePathParam("{");
usernamePathParam.append("username").append("}");
QString pathPrefix, pathSuffix, pathDelimiter;
QString pathStyle = "";
if(pathStyle == "")
pathStyle = "simple";
pathPrefix = getParamStylePrefix(pathStyle);
pathSuffix = getParamStyleSuffix(pathStyle);
pathDelimiter = getParamStyleDelimiter(pathStyle, "username", false);
QString paramString = (pathStyle == "matrix") ? pathPrefix+"username"+pathSuffix : pathPrefix;
fullPath.replace(usernamePathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(username)));
{
QString usernamePathParam("{");
usernamePathParam.append("username").append("}");
QString pathPrefix, pathSuffix, pathDelimiter;
QString pathStyle = "";
if(pathStyle == "")
pathStyle = "simple";
pathPrefix = getParamStylePrefix(pathStyle);
pathSuffix = getParamStyleSuffix(pathStyle);
pathDelimiter = getParamStyleDelimiter(pathStyle, "username", false);
QString paramString = (pathStyle == "matrix") ? pathPrefix+"username"+pathSuffix : pathPrefix;
fullPath.replace(usernamePathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(username)));
}
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut); worker->setTimeOut(_timeOut);
@ -465,30 +466,37 @@ void PFXUserApi::loginUser(const QString &username, const QString &password) {
QString queryPrefix, querySuffix, queryDelimiter, queryStyle; QString queryPrefix, querySuffix, queryDelimiter, queryStyle;
queryStyle = "";
if(queryStyle == "") {
queryStyle = "form"; queryStyle = "";
queryPrefix = getParamStylePrefix(queryStyle); if(queryStyle == "")
querySuffix = getParamStyleSuffix(queryStyle); queryStyle = "form";
queryDelimiter = getParamStyleDelimiter(queryStyle, "username", false); queryPrefix = getParamStylePrefix(queryStyle);
if (fullPath.indexOf("?") > 0) querySuffix = getParamStyleSuffix(queryStyle);
fullPath.append(queryPrefix); queryDelimiter = getParamStyleDelimiter(queryStyle, "username", false);
else if (fullPath.indexOf("?") > 0)
fullPath.append("?"); fullPath.append(queryPrefix);
else
fullPath.append("?");
fullPath.append(QUrl::toPercentEncoding("username")).append(querySuffix).append(QUrl::toPercentEncoding(::test_namespace::toStringValue(username))); fullPath.append(QUrl::toPercentEncoding("username")).append(querySuffix).append(QUrl::toPercentEncoding(::test_namespace::toStringValue(username)));
queryStyle = ""; }
if(queryStyle == "")
queryStyle = "form";
queryPrefix = getParamStylePrefix(queryStyle);
querySuffix = getParamStyleSuffix(queryStyle);
queryDelimiter = getParamStyleDelimiter(queryStyle, "password", false);
if (fullPath.indexOf("?") > 0)
fullPath.append(queryPrefix);
else
fullPath.append("?");
fullPath.append(QUrl::toPercentEncoding("password")).append(querySuffix).append(QUrl::toPercentEncoding(::test_namespace::toStringValue(password)));
{
queryStyle = "";
if(queryStyle == "")
queryStyle = "form";
queryPrefix = getParamStylePrefix(queryStyle);
querySuffix = getParamStyleSuffix(queryStyle);
queryDelimiter = getParamStyleDelimiter(queryStyle, "password", false);
if (fullPath.indexOf("?") > 0)
fullPath.append(queryPrefix);
else
fullPath.append("?");
fullPath.append(QUrl::toPercentEncoding("password")).append(querySuffix).append(QUrl::toPercentEncoding(::test_namespace::toStringValue(password)));
}
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut); worker->setTimeOut(_timeOut);
@ -530,7 +538,6 @@ void PFXUserApi::logoutUser() {
QString fullPath = QString(_serverConfigs["logoutUser"][_serverIndices.value("logoutUser")].URL()+"/user/logout"); QString fullPath = QString(_serverConfigs["logoutUser"][_serverIndices.value("logoutUser")].URL()+"/user/logout");
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut); worker->setTimeOut(_timeOut);
worker->setWorkingDirectory(_workingDirectory); worker->setWorkingDirectory(_workingDirectory);
@ -568,18 +575,21 @@ void PFXUserApi::logoutUserCallback(PFXHttpRequestWorker *worker) {
void PFXUserApi::updateUser(const QString &username, const PFXUser &body) { void PFXUserApi::updateUser(const QString &username, const PFXUser &body) {
QString fullPath = QString(_serverConfigs["updateUser"][_serverIndices.value("updateUser")].URL()+"/user/{username}"); QString fullPath = QString(_serverConfigs["updateUser"][_serverIndices.value("updateUser")].URL()+"/user/{username}");
QString usernamePathParam("{");
usernamePathParam.append("username").append("}");
QString pathPrefix, pathSuffix, pathDelimiter;
QString pathStyle = "";
if(pathStyle == "")
pathStyle = "simple";
pathPrefix = getParamStylePrefix(pathStyle);
pathSuffix = getParamStyleSuffix(pathStyle);
pathDelimiter = getParamStyleDelimiter(pathStyle, "username", false);
QString paramString = (pathStyle == "matrix") ? pathPrefix+"username"+pathSuffix : pathPrefix;
fullPath.replace(usernamePathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(username)));
{
QString usernamePathParam("{");
usernamePathParam.append("username").append("}");
QString pathPrefix, pathSuffix, pathDelimiter;
QString pathStyle = "";
if(pathStyle == "")
pathStyle = "simple";
pathPrefix = getParamStylePrefix(pathStyle);
pathSuffix = getParamStyleSuffix(pathStyle);
pathDelimiter = getParamStyleDelimiter(pathStyle, "username", false);
QString paramString = (pathStyle == "matrix") ? pathPrefix+"username"+pathSuffix : pathPrefix;
fullPath.replace(usernamePathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(username)));
}
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut); worker->setTimeOut(_timeOut);

View File

@ -24,6 +24,7 @@
#include <QStringList> #include <QStringList>
#include <QList> #include <QList>
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
#include <QVariant>
namespace test_namespace { namespace test_namespace {
@ -55,15 +56,47 @@ public:
QString getParamStyleSuffix(QString style); QString getParamStyleSuffix(QString style);
QString getParamStyleDelimiter(QString style, QString name, bool isExplode); QString getParamStyleDelimiter(QString style, QString name, bool isExplode);
/**
* @param[in] body PFXUser [required]
*/
void createUser(const PFXUser &body); void createUser(const PFXUser &body);
/**
* @param[in] body QList<PFXUser> [required]
*/
void createUsersWithArrayInput(const QList<PFXUser> &body); void createUsersWithArrayInput(const QList<PFXUser> &body);
/**
* @param[in] body QList<PFXUser> [required]
*/
void createUsersWithListInput(const QList<PFXUser> &body); void createUsersWithListInput(const QList<PFXUser> &body);
/**
* @param[in] username QString [required]
*/
void deleteUser(const QString &username); void deleteUser(const QString &username);
/**
* @param[in] username QString [required]
*/
void getUserByName(const QString &username); void getUserByName(const QString &username);
/**
* @param[in] username QString [required]
* @param[in] password QString [required]
*/
void loginUser(const QString &username, const QString &password); void loginUser(const QString &username, const QString &password);
void logoutUser(); void logoutUser();
/**
* @param[in] username QString [required]
* @param[in] body PFXUser [required]
*/
void updateUser(const QString &username, const PFXUser &body); void updateUser(const QString &username, const PFXUser &body);
private: private:
QMap<QString,int> _serverIndices; QMap<QString,int> _serverIndices;
QMap<QString,QList<PFXServerConfiguration>> _serverConfigs; QMap<QString,QList<PFXServerConfiguration>> _serverConfigs;