diff options
Diffstat (limited to 'jobs')
-rw-r--r-- | jobs/gtad.yaml | 1 | ||||
-rw-r--r-- | jobs/{{base}}.cpp.mustache | 49 | ||||
-rw-r--r-- | jobs/{{base}}.h.mustache | 13 |
3 files changed, 31 insertions, 32 deletions
diff --git a/jobs/gtad.yaml b/jobs/gtad.yaml index a19415a6..b9d128b4 100644 --- a/jobs/gtad.yaml +++ b/jobs/gtad.yaml @@ -45,7 +45,6 @@ types: file: type: QByteArray imports: <QtCore/QByteArray> - returnFile?: true object: type: QJsonObject avoidCopy?: true diff --git a/jobs/{{base}}.cpp.mustache b/jobs/{{base}}.cpp.mustache index b303c053..6621f173 100644 --- a/jobs/{{base}}.cpp.mustache +++ b/jobs/{{base}}.cpp.mustache @@ -1,10 +1,10 @@ {{#@filePartial}}preamble{{/@filePartial}} - #include "{{filenameBase}}.h" - +{{^allModels}} #include "converters.h" -{{#operations}} -#include <QtCore/QStringBuilder> +{{/allModels}}{{#operations}} +{{#producesNotJson?}}#include <QtNetwork/QNetworkReply> +{{/producesNotJson?}}#include <QtCore/QStringBuilder> {{/operations}} using namespace QMatrixClient; {{#models.model}}{{^trivial?}} @@ -50,14 +50,13 @@ namespace QMatrixClient } }; } // namespace QMatrixClient -{{/ trivial?}}{{/models.model}}{{#responses}}{{#normalResponse?}}{{#properties?}} +{{/ trivial?}}{{/models.model}}{{#responses}}{{#normalResponse?}}{{#allProperties?}} class {{camelCaseOperationId}}Job::Private { - public: - {{#properties}}{{dataType.name}} {{paramName}};{{#@join}}{{!EOL except the last line}} - {{/@join}}{{/properties}} + public:{{#allProperties}} + {{dataType.name}} {{paramName}};{{/allProperties}} }; -{{/ properties?}}{{/normalResponse?}}{{/responses}} +{{/ 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}}, @@ -65,30 +64,32 @@ class {{camelCaseOperationId}}Job::Private {{#queryParams}}{ "{{baseName}}", toJson({{paramName}}).toString() }{{#@join}}, {{/@join}}{{/queryParams}} }{{/queryParams?}}{{#skipAuth}}, Data { }, false{{/skipAuth}} - ){{#responses}}{{#normalResponse?}}{{#properties?}}, d(new Private){{/properties?}}{{/normalResponse?}}{{/responses}} + ){{#responses}}{{#normalResponse?}}{{#allProperties?}}, d(new Private){{/allProperties?}}{{/normalResponse?}}{{/responses}} {{#bodyParams?}}{ -{{#inlineBody}} setRequestData(Data({{paramName}}));{{/inlineBody}}{{! +{{#headerParams?}}{{#headerParams}} setRequestHeader("{{baseName}}", {{paramName}}.toLatin1()); +{{/headerParams}} +{{/headerParams?}}{{#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}} + setRequestData(_data);{{/inlineBody}}{{#produces?}} +{{#produces}} + addExpectedContentType({{_}});{{/produces}}{{/produces?}} }{{/bodyParams?}}{{^bodyParams?}}{ }{{/bodyParams?}} -{{# responses}}{{#normalResponse?}}{{#properties?}} -{{camelCaseOperationId}}Job::~{{camelCaseOperationId}}Job() -{ - delete d; -} -{{# properties}} +{{# responses}}{{#normalResponse?}}{{#allProperties?}} +{{camelCaseOperationId}}Job::~{{camelCaseOperationId}}Job() = default; +{{# allProperties}} {{>qualifiedMaybeCrefType}} {{camelCaseOperationId}}Job::{{paramName}}() const { return d->{{paramName}}; } -{{/ properties}}{{#returnFile?}} -BaseJob::Status {{camelCaseOperationId}}Job::parseReply(QByteArray data) +{{/ allProperties}}{{#producesNotJson?}} +BaseJob::Status {{camelCaseOperationId}}Job::parseReply(QNetworkReply* reply) { - {{properties.nameCamelCase}} = data; + {{#headers}}d->{{paramName}} = reply->rawHeader("{{baseName}}"); {{! We don't check for required headers yet }} + {{/headers}}{{#properties}}d->{{paramName}} = reply->readAll();{{/properties}} return Success; -}{{/ returnFile?}}{{^returnFile?}} +}{{/ producesNotJson?}}{{^producesNotJson?}} BaseJob::Status {{camelCaseOperationId}}Job::parseJson(const QJsonDocument& data) { auto json = data.object(); @@ -97,5 +98,5 @@ BaseJob::Status {{camelCaseOperationId}}Job::parseJson(const QJsonDocument& data "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}} +}{{/ producesNotJson?}} +{{/allProperties?}}{{/normalResponse?}}{{/responses}}{{/operation}}{{/operations}} diff --git a/jobs/{{base}}.h.mustache b/jobs/{{base}}.h.mustache index 76ae4f51..b5106dbe 100644 --- a/jobs/{{base}}.h.mustache +++ b/jobs/{{base}}.h.mustache @@ -1,5 +1,4 @@ {{#@filePartial}}preamble{{/@filePartial}} - #pragma once {{#operations}}#include "../basejob.h" @@ -45,17 +44,17 @@ namespace QMatrixClient // End of inner data structures {{/models}} explicit {{camelCaseOperationId}}Job({{#allParams}}{{>maybeCrefType}} {{paramName}}{{^required?}} = {{defaultValue}}{{^defaultValue}}{}{{/defaultValue}}{{/required?}}{{#@join}}, {{/@join}}{{/allParams}});{{!skip EOL -}}{{# responses}}{{#normalResponse?}}{{#properties?}} +}}{{# responses}}{{#normalResponse?}}{{#allProperties?}} ~{{camelCaseOperationId}}Job() override; +{{#allProperties}} + {{>maybeCrefType}} {{paramName}}() const;{{/allProperties}} - {{#properties}}{{>maybeCrefType}} {{paramName}}() const; - {{/properties}} protected: - {{^returnFile}}Status parseJson(const QJsonDocument& data) override;{{/returnFile}} - {{#returnFile?}}Status parseReply(QByteArray data) override;{{/returnFile?}} + Status {{#producesNotJson?}}parseReply(QNetworkReply* reply){{/producesNotJson?}}{{^producesNotJson?}}parseJson(const QJsonDocument& data){{/producesNotJson?}} override; + private: class Private; - Private* d;{{/properties?}}{{/normalResponse?}}{{/responses}} + QScopedPointer<Private> d;{{/allProperties?}}{{/normalResponse?}}{{/responses}} }; {{/operation}}{{/operations}}{{!skip EOL }}} // namespace QMatrixClient |