1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
{{#@filePartial}}preamble{{/@filePartial}}
#include "{{filenameBase}}.h"
#include "converters.h"
{{#operations}}
#include <QtCore/QStringBuilder>
{{/operations}}
using namespace QMatrixClient;
{{#models.model}}{{^trivial?}}
{{qualifiedName}}::operator QJsonValue() const
{
QJsonObject o;
{{#vars}}o.insert("{{baseName}}", toJson({{nameCamelCase}}));
{{/vars}}
return o;
}
{{qualifiedName}} FromJson<{{qualifiedName}}>::operator()(QJsonValue jv)
{
QJsonObject o = jv.toObject();
{{qualifiedName}} result;
{{#vars}}result.{{nameCamelCase}} =
fromJson<{{dataType.name}}>(o.value("{{baseName}}"));
{{/vars}}
return result;
}
{{/trivial?}}{{/models.model}}{{#operations}}
static const auto basePath = QStringLiteral("{{basePathWithoutHost}}");
{{# operation}}{{#models.model}}{{^trivial?}}
{{qualifiedName}}::operator QJsonObject() const
{
QJsonObject o;
{{#vars}}o.insert("{{baseName}}", toJson({{nameCamelCase}}));
{{/vars}}
return o;
}
namespace QMatrixClient
{
template <> struct FromJson<{{qualifiedName}}>
{
{{qualifiedName}} operator()(QJsonValue jv)
{
QJsonObject o = jv.toObject();
{{qualifiedName}} result;
{{#vars}}result.{{nameCamelCase}} =
fromJson<{{dataType.qualifiedName}}>(o.value("{{baseName}}"));
{{/vars}}
return result;
}
};
} // namespace QMatrixClient
{{/ trivial?}}{{/models.model}}{{#responses}}{{#normalResponse?}}{{#properties?}}
class {{camelCaseOperationId}}Job::Private
{
public:
{{#properties}}{{dataType.name}} {{paramName}};{{#@join}}{{!EOL except the last line}}
{{/@join}}{{/properties}}
};
{{/ properties?}}{{/normalResponse?}}{{/responses}}
{{camelCaseOperationId}}Job::{{camelCaseOperationId}}Job({{#allParams}}{{>maybeCrefType}} {{paramName}}{{#@join}}, {{/@join}}{{/allParams}})
: BaseJob(HttpVerb::{{#@cap}}{{#@tolower}}{{httpMethod}}{{/@tolower}}{{/@cap}}, "{{camelCaseOperationId}}Job",
basePath{{#pathParts}} % {{_}}{{/pathParts}},
Query {{^queryParams}}{ }{{/queryParams}}{{#queryParams?}}{
{{#queryParams}}{ "{{baseName}}", toJson({{paramName}}).toString() }{{#@join}},
{{/@join}}{{/queryParams}}
}{{/queryParams?}}{{#skipAuth}}, Data { }, false{{/skipAuth}}
){{#responses}}{{#normalResponse?}}{{#properties?}}, d(new Private){{/properties?}}{{/normalResponse?}}{{/responses}}
{{#bodyParams?}}{
{{#inlineBody}} setRequestData(Data({{paramName}}));{{/inlineBody}}{{!
}}{{^inlineBody}} QJsonObject _data;{{#bodyParams}}
{{^required?}}{{#string?}} if (!{{paramName}}.isEmpty())
{{/string?}}{{/required?}} _data.insert("{{baseName}}", toJson({{paramName}}));{{/bodyParams}}
setRequestData(_data);{{/inlineBody}}
}{{/bodyParams?}}{{^bodyParams?}}{ }{{/bodyParams?}}
{{# responses}}{{#normalResponse?}}{{#properties?}}
{{camelCaseOperationId}}Job::~{{camelCaseOperationId}}Job()
{
delete d;
}
{{# properties}}
{{>qualifiedMaybeCrefType}} {{camelCaseOperationId}}Job::{{paramName}}() const
{
return d->{{paramName}};
}
{{/ properties}}{{#returnFile?}}
BaseJob::Status {{camelCaseOperationId}}Job::parseReply(QByteArray data)
{
{{properties.nameCamelCase}} = data;
return Success;
}{{/ returnFile?}}{{^returnFile?}}
BaseJob::Status {{camelCaseOperationId}}Job::parseJson(const QJsonDocument& data)
{
auto json = data.object();
{{# properties}}{{#required?}}if (!json.contains("{{baseName}}"))
return { JsonParseError,
"The key '{{baseName}}' not found in the response" };
{{/required?}}d->{{paramName}} = fromJson<{{dataType.name}}>(json.value("{{baseName}}"));
{{/ properties}}return Success;
}{{/ returnFile?}}
{{/properties?}}{{/normalResponse?}}{{/responses}}{{/operation}}{{/operations}}
|