aboutsummaryrefslogtreecommitdiff
path: root/lib/csapi/{{base}}.cpp.mustache
diff options
context:
space:
mode:
Diffstat (limited to 'lib/csapi/{{base}}.cpp.mustache')
-rw-r--r--lib/csapi/{{base}}.cpp.mustache44
1 files changed, 22 insertions, 22 deletions
diff --git a/lib/csapi/{{base}}.cpp.mustache b/lib/csapi/{{base}}.cpp.mustache
index eced328c..64fd8bf3 100644
--- a/lib/csapi/{{base}}.cpp.mustache
+++ b/lib/csapi/{{base}}.cpp.mustache
@@ -10,19 +10,18 @@ using namespace QMatrixClient;
{{#models.model}}{{#in?}}
QJsonObject QMatrixClient::toJson(const {{qualifiedName}}& pod)
{
- QJsonObject _json{{#propertyMap}} = toJson(pod.{{nameCamelCase}}){{/propertyMap}};{{#vars}}
- addParam<{{^required?}}IfNotEmpty{{/required?}}>(_json, QStringLiteral("{{baseName}}"), pod.{{nameCamelCase}});{{/vars}}
- return _json;
+ QJsonObject jo{{#propertyMap}} = toJson(pod.{{nameCamelCase}}){{/propertyMap}};{{#vars}}
+ addParam<{{^required?}}IfNotEmpty{{/required?}}>(jo, QStringLiteral("{{baseName}}"), pod.{{nameCamelCase}});{{/vars}}
+ return jo;
}
{{/in?}}{{#out?}}
-{{qualifiedName}} FromJson<{{qualifiedName}}>::operator()(const QJsonValue& jv)
+{{qualifiedName}} FromJsonObject<{{qualifiedName}}>::operator()({{^propertyMap}}const QJsonObject&{{/propertyMap}}{{#propertyMap}}QJsonObject{{/propertyMap}} jo) const
{
- {{^propertyMap}}const auto&{{/propertyMap}}{{#propertyMap}}auto{{/propertyMap}} _json = jv.toObject();
{{qualifiedName}} result;
- {{#vars}}result.{{nameCamelCase}} =
- fromJson<{{dataType.name}}>(_json.{{#propertyMap}}take{{/propertyMap}}{{^propertyMap}}value{{/propertyMap}}("{{baseName}}"_ls));
- {{/vars}}{{#propertyMap}}
- result.{{nameCamelCase}} = fromJson<{{dataType.name}}>(_json);{{/propertyMap}}
+{{#vars}} result.{{nameCamelCase}} =
+ fromJson<{{dataType.qualifiedName}}>(jo.{{#propertyMap}}take{{/propertyMap}}{{^propertyMap}}value{{/propertyMap}}("{{baseName}}"_ls));
+{{/vars}}{{#propertyMap}}
+ result.{{nameCamelCase}} = fromJson<{{dataType.qualifiedName}}>(jo);{{/propertyMap}}
return result;
}
{{/out?}}{{/models.model}}{{#operations}}
@@ -34,20 +33,20 @@ namespace QMatrixClient
{{#model}}{{#in?}}
QJsonObject toJson(const {{qualifiedName}}& pod)
{
- QJsonObject _json;{{#vars}}
- addParam<{{^required?}}IfNotEmpty{{/required?}}>(_json, QStringLiteral("{{baseName}}"), pod.{{nameCamelCase}});{{/vars}}
- return _json;
+ QJsonObject jo{{#propertyMap}} = toJson(pod.{{nameCamelCase}}){{/propertyMap}};{{#vars}}
+ addParam<{{^required?}}IfNotEmpty{{/required?}}>(jo, QStringLiteral("{{baseName}}"), pod.{{nameCamelCase}});{{/vars}}
+ return jo;
}
{{/in?}}{{#out?}}
- template <> struct FromJson<{{qualifiedName}}>
+ template <> struct FromJsonObject<{{qualifiedName}}>
{
- {{qualifiedName}} operator()(const QJsonValue& jv)
+ {{qualifiedName}} operator()({{^propertyMap}}const QJsonObject&{{/propertyMap}}{{#propertyMap}}QJsonObject{{/propertyMap}} jo) const
{
- const auto& _json = jv.toObject();
{{qualifiedName}} result;
{{#vars}} result.{{nameCamelCase}} =
- fromJson<{{dataType.qualifiedName}}>(_json.value("{{baseName}}"_ls));
-{{/vars}}
+ fromJson<{{dataType.qualifiedName}}>(jo.{{#propertyMap}}take{{/propertyMap}}{{^propertyMap}}value{{/propertyMap}}("{{baseName}}"_ls));
+{{/vars}}{{#propertyMap}}
+ result.{{nameCamelCase}} = fromJson<{{dataType.qualifiedName}}>(jo);{{/propertyMap}}
return result;
}
};
@@ -104,17 +103,18 @@ static const auto {{camelCaseOperationId}}JobName = QStringLiteral("{{camelCaseO
{{/ allProperties}}{{#producesNonJson?}}
BaseJob::Status {{camelCaseOperationId}}Job::parseReply(QNetworkReply* reply)
{
- {{#headers}}d->{{paramName}} = reply->rawHeader("{{baseName}}"); {{! We don't check for required headers yet }}
+ {{#headers}}d->{{paramName}} = reply->rawHeader("{{baseName}}");{{! We don't check for required headers yet }}
{{/headers}}{{#properties}}d->{{paramName}} = reply;{{/properties}}
return Success;
}{{/ producesNonJson?}}{{^producesNonJson?}}
BaseJob::Status {{camelCaseOperationId}}Job::parseJson(const QJsonDocument& data)
{
- auto json = data.object();
- {{# properties}}{{#required?}}if (!json.contains("{{baseName}}"_ls))
+{{#inlineResponse}} d->{{paramName}} = fromJson<{{dataType.name}}>(data);
+{{/inlineResponse}}{{^inlineResponse}} auto json = data.object();
+{{#properties}}{{#required?}} if (!json.contains("{{baseName}}"_ls))
return { JsonParseError,
"The key '{{baseName}}' not found in the response" };
- {{/required?}}d->{{paramName}} = fromJson<{{dataType.name}}>(json.value("{{baseName}}"_ls));
- {{/ properties}}return Success;
+{{/required?}} d->{{paramName}} = fromJson<{{dataType.name}}>(json.value("{{baseName}}"_ls));
+{{/properties}}{{/inlineResponse}} return Success;
}{{/ producesNonJson?}}
{{/allProperties?}}{{/normalResponse?}}{{/responses}}{{/operation}}{{/operations}}