aboutsummaryrefslogtreecommitdiff
path: root/lib/csapi/{{base}}.cpp.mustache
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2018-09-29 22:22:49 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2018-09-29 22:22:49 +0900
commitb55334ac0fe89f780776bc4eab90ffe1ca3c57bb (patch)
tree1a45c0ccfec8f5f7ba37eb4385cdc7f61afa0c97 /lib/csapi/{{base}}.cpp.mustache
parentf5c2e47fa1ab84fdaffe03c30ba973d7dea5ac05 (diff)
parent1e6510790dab6b9141ae52993987b406399668cd (diff)
downloadlibquotient-b55334ac0fe89f780776bc4eab90ffe1ca3c57bb.tar.gz
libquotient-b55334ac0fe89f780776bc4eab90ffe1ca3c57bb.zip
Merge branch 'cs-api-0.4.0'
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}}