{{#@filePartial}}preamble{{/@filePartial}} #include "{{filenameBase}}.h" {{^allModels}} #include "converters.h" {{/allModels}}{{#operations}} {{#producesNotJson?}}#include {{/producesNotJson?}}#include {{/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?}}{{#allProperties?}} class {{camelCaseOperationId}}Job::Private { public:{{#allProperties}} {{dataType.name}} {{paramName}};{{/allProperties}} }; {{/ allProperties?}}{{/normalResponse?}}{{/responses}} {{camelCaseOperationId}}Job::{{camelCaseOperationId}}Job({{#allParams}}{{>maybeCrefType}} {{paramName}}{{#@join}}, {{/@join}}{{/allParams}}) : BaseJob(HttpVerb::{{#@cap}}{{#@tolower}}{{httpMethod}}{{/@tolower}}{{/@cap}}, "{{camelCaseOperationId}}Job", basePath{{#pathParts}} % {{_}}{{/pathParts}}{{#skipAuth}}, false{{/skipAuth}}){{#responses}}{{#normalResponse?}}{{#allProperties?}} , d(new Private){{/allProperties?}}{{/normalResponse?}}{{/responses}} { {{#headerParams?}}{{#headerParams}} setRequestHeader("{{baseName}}", {{paramName}}.toLatin1()); {{/headerParams}} {{/headerParams?}}{{! }}{{#queryParams?}} QUrlQuery _q;{{#queryParams}} {{^required?}}{{#string?}} if (!{{nameCamelCase}}.isEmpty()) {{/string?}}{{/required?}} _q.addQueryItem("{{baseName}}", {{>paramToString}});{{/queryParams}} setRequestQuery(_q); {{/queryParams?}}{{#bodyParams?}}{{! }}{{#inlineBody}} setRequestData(Data({{nameCamelCase}}));{{/inlineBody}}{{! }}{{^inlineBody}} QJsonObject _data;{{#bodyParams}} {{^required?}}{{#string?}} if (!{{paramName}}.isEmpty()) {{/string?}}{{/required?}} _data.insert("{{baseName}}", toJson({{paramName}}));{{/bodyParams}} setRequestData(_data);{{/inlineBody}} {{/bodyParams?}}{{#producesNotJson?}} setExpectedContentTypes({ {{#produces}}"{{_}}"{{#@join}}, {{/@join}}{{/produces}} }); {{/producesNotJson?}}}{{!<- mind the actual brace}} {{# responses}}{{#normalResponse?}}{{#allProperties?}} {{camelCaseOperationId}}Job::~{{camelCaseOperationId}}Job() = default; {{# allProperties}} {{>qualifiedMaybeCrefType}} {{camelCaseOperationId}}Job::{{paramName}}() const { return d->{{paramName}}; } {{/ allProperties}}{{#producesNotJson?}} BaseJob::Status {{camelCaseOperationId}}Job::parseReply(QNetworkReply* reply) { {{#headers}}d->{{paramName}} = reply->rawHeader("{{baseName}}"); {{! We don't check for required headers yet }} {{/headers}}{{#properties}}d->{{paramName}} = reply->readAll();{{/properties}} return Success; }{{/ producesNotJson?}}{{^producesNotJson?}} 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; }{{/ producesNotJson?}} {{/allProperties?}}{{/normalResponse?}}{{/responses}}{{/operation}}{{/operations}}