diff options
Diffstat (limited to 'jobs')
-rw-r--r-- | jobs/basejob.cpp | 1 | ||||
-rw-r--r-- | jobs/gtad.yaml | 87 | ||||
-rw-r--r-- | jobs/preamble.mustache | 3 | ||||
-rw-r--r-- | jobs/{{base}}.cpp.mustache | 116 | ||||
-rw-r--r-- | jobs/{{base}}.h.mustache | 67 |
5 files changed, 273 insertions, 1 deletions
diff --git a/jobs/basejob.cpp b/jobs/basejob.cpp index c35a7711..0e3e59d0 100644 --- a/jobs/basejob.cpp +++ b/jobs/basejob.cpp @@ -25,7 +25,6 @@ #include <QtNetwork/QNetworkReply> #include <QtCore/QTimer> #include <QtCore/QRegularExpression> -//#include <QtCore/QStringBuilder> #include <array> diff --git a/jobs/gtad.yaml b/jobs/gtad.yaml new file mode 100644 index 00000000..78c879e4 --- /dev/null +++ b/jobs/gtad.yaml @@ -0,0 +1,87 @@ +preprocess: + "%CLIENT_RELEASE_LABEL%": r0 + "%CLIENT_MAJOR_VERSION%": r0 + # FIXME: the below only fixes C++ compilation but not actual work - the code + # will try to reach out for wrong values in JSON payloads + #"signed:": "signedData:" + #"unsigned:": "unsignedData:" + #"default:": "isDefault:" + +# Structure: +# swaggerType: <targetTypeSpec> +# OR +# swaggerType: +# - swaggerFormat: <targetTypeSpec> +# - /swaggerFormatRegEx/: <targetTypeSpec> +# - //: <targetTypeSpec> # default, if the format doesn't mach anything above +# WHERE +# targetTypeSpec = targetType OR +# { type: targetType, imports: <filename OR [ filenames... ]>, <other attributes...> } +types: + integer: + - int64: qint64 + - int32: qint32 + - //: int + number: + - float: float + - //: double + boolean: { type: bool, initializer: false } + string: + - byte: &ByteStream + type: QIODevice* + #initializer: '"{{defaultValue}}"' + #string?: true + imports: <QtCore/QIODevice> + - binary: *ByteStream + - date: + type: QDate + initializer: QDate::fromString("{{defaultValue}}") + avoidCopy?: true + imports: <QtCore/QDate> + - dateTime: + type: QDateTime + initializer: QDateTime::fromString("{{defaultValue}}") + avoidCopy?: true + imports: <QtCore/QDateTime> + - //: + type: QString + initializer: QStringLiteral("{{defaultValue}}") + string?: true + avoidCopy?: true + file: *ByteStream + object: + type: QJsonObject + avoidCopy?: true + imports: <QtCore/QJsonObject> + array: + - /.+/: + type: "QVector<{{1}}>" + avoidCopy?: true + imports: <QtCore/QVector> + - //: { type: QJsonArray, "avoidCopy?": true, imports: <QtCore/QJsonArray> } + schema: + avoidCopy?: true + +#operations: + +env: + _scopeRenderer: "{{scopeCamelCase}}Job::" + _literalQuote: '"' + maybeCrefType: "{{#avoidCopy?}}const {{/avoidCopy?}}{{dataType.name}}{{#avoidCopy?}}&{{/avoidCopy?}}" + qualifiedMaybeCrefType: "{{#avoidCopy?}}const {{/avoidCopy?}}{{dataType.qualifiedName}}{{#avoidCopy?}}&{{/avoidCopy?}}" + initializeDefaultValue: "{{#defaultValue}}{{>initializer}}{{/defaultValue}}{{^defaultValue}}{}{{/defaultValue}}" + joinedParamDecl: '{{>maybeCrefType}} {{paramName}}{{^required?}} = {{>initializeDefaultValue}}{{/required?}}{{#@join}}, {{/@join}}' + joinedParamDef: '{{>maybeCrefType}} {{paramName}}{{#@join}}, {{/@join}}' + passQueryParams: '{{#queryParams}}{{paramName}}{{#@join}}, {{/@join}}{{/queryParams}}' + paramToString: '{{#string?}}{{nameCamelCase}}{{/string?}}{{^string?}}QString("%1").arg({{nameCamelCase}}){{/string?}}' +# preamble: preamble.mustache + copyrightName: Kitsune Ral + copyrightEmail: <kitsune-ral@users.sf.net> +# imports: { set: } + +templates: +- "{{base}}.h.mustache" +- "{{base}}.cpp.mustache" + +#outFilesList: apifiles.txt + diff --git a/jobs/preamble.mustache b/jobs/preamble.mustache new file mode 100644 index 00000000..3ba87d61 --- /dev/null +++ b/jobs/preamble.mustache @@ -0,0 +1,3 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ diff --git a/jobs/{{base}}.cpp.mustache b/jobs/{{base}}.cpp.mustache new file mode 100644 index 00000000..b8532c51 --- /dev/null +++ b/jobs/{{base}}.cpp.mustache @@ -0,0 +1,116 @@ +{{#@filePartial}}preamble{{/@filePartial}} +#include "{{filenameBase}}.h" +{{^allModels}} +#include "converters.h" +{{/allModels}}{{#operations}} +{{#producesNotJson?}}#include <QtNetwork/QNetworkReply> +{{/producesNotJson?}}#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?}}{{#allProperties?}} +class {{camelCaseOperationId}}Job::Private +{ + public:{{#allProperties}} + {{dataType.name}} {{paramName}};{{/allProperties}} +}; +{{/ allProperties?}}{{/normalResponse?}}{{/responses}}{{#queryParams?}} +BaseJob::Query queryTo{{camelCaseOperationId}}({{#queryParams}}{{>joinedParamDef}}{{/queryParams}}) +{ + BaseJob::Query _q;{{#queryParams}} +{{^required?}}{{#string?}} if (!{{nameCamelCase}}.isEmpty()) + {{/string?}}{{/required?}} _q.addQueryItem("{{baseName}}", {{>paramToString}});{{/queryParams}} + return _q; +} +{{/queryParams?}}{{^bodyParams}} +QUrl {{camelCaseOperationId}}Job::makeRequestUrl(QUrl baseUrl{{#allParams?}}, {{#allParams}}{{>joinedParamDef}}{{/allParams}}{{/allParams?}}) +{ + return BaseJob::makeRequestUrl(baseUrl, + basePath{{#pathParts}} % {{_}}{{/pathParts}}{{#queryParams?}}, + queryTo{{camelCaseOperationId}}({{>passQueryParams}}){{/queryParams?}}); +} +{{/ bodyParams}} +{{camelCaseOperationId}}Job::{{camelCaseOperationId}}Job({{#allParams}}{{>joinedParamDef}}{{/allParams}}) + : BaseJob(HttpVerb::{{#@cap}}{{#@tolower}}{{httpMethod}}{{/@tolower}}{{/@cap}}, "{{camelCaseOperationId}}Job", + basePath{{#pathParts}} % {{_}}{{/pathParts}}{{#queryParams?}}, + queryTo{{camelCaseOperationId}}({{>passQueryParams}}){{/queryParams?}}{{#skipAuth}}{{#queryParams?}}, + {}{{/queryParams?}}, false{{/skipAuth}}){{#responses}}{{#normalResponse?}}{{#allProperties?}} + , d(new Private){{/allProperties?}}{{/normalResponse?}}{{/responses}} +{ +{{#headerParams?}}{{#headerParams}} setRequestHeader("{{baseName}}", {{paramName}}.toLatin1()); +{{/headerParams}} +{{/headerParams?}}{{! +}}{{#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;{{/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}} diff --git a/jobs/{{base}}.h.mustache b/jobs/{{base}}.h.mustache new file mode 100644 index 00000000..63aa53e7 --- /dev/null +++ b/jobs/{{base}}.h.mustache @@ -0,0 +1,67 @@ +{{#@filePartial}}preamble{{/@filePartial}} +#pragma once + +{{#operations}}#include "../basejob.h" +{{/operations}} +{{#imports}}#include {{_}} +{{/imports}} +{{#allModels}}#include "converters.h" +{{/allModels}} +namespace QMatrixClient +{ +{{#models}} // Data structures +{{# model}}{{#trivial?}} + using {{name}} = {{parent.name}}; +{{/ trivial?}}{{^trivial?}} + struct {{name}}{{#parents?}} : {{#parents}}{{name}}{{#@join}}, {{/@join}}{{/parents}}{{/parents?}} + { + {{#vars}}{{dataType.name}} {{nameCamelCase}}; + {{/vars}} + operator QJsonObject() const; + }; + + template <> struct FromJson<{{name}}> + { + {{name}} operator()(QJsonValue jv); + }; +{{/ trivial?}}{{/model}} +{{/models}}{{#operations}} // Operations +{{# operation}} + class {{camelCaseOperationId}}Job : public BaseJob + { + public:{{# models}} + // Inner data structures +{{# model}}{{#trivial?}} + using {{name}} = {{parent.name}}; +{{/ trivial?}}{{^trivial?}} + struct {{name}}{{#parents?}} : {{#parents}}{{name}}{{#@join}}, {{/@join}}{{/parents}}{{/parents?}} + { + {{#vars}}{{dataType.name}} {{nameCamelCase}}; + {{/vars}} + operator QJsonObject() const; + }; +{{/ trivial?}}{{/model}} + // End of inner data structures +{{/models}}{{^bodyParams}} + /** Construct a URL out of baseUrl and usual parameters passed to + * {{camelCaseOperationId}}Job. This function can be used when + * a URL for {{camelCaseOperationId}}Job is necessary but the job + * itself isn't. + */ + static QUrl makeRequestUrl(QUrl baseUrl{{#allParams?}}, {{#allParams}}{{>joinedParamDecl}}{{/allParams}}{{/allParams?}}); +{{/bodyParams}} + explicit {{camelCaseOperationId}}Job({{#allParams}}{{>joinedParamDecl}}{{/allParams}});{{!skip EOL +}}{{# responses}}{{#normalResponse?}}{{#allProperties?}} + ~{{camelCaseOperationId}}Job() override; +{{#allProperties}} + {{>maybeCrefType}} {{paramName}}() const;{{/allProperties}} + + protected: + Status {{#producesNotJson?}}parseReply(QNetworkReply* reply){{/producesNotJson?}}{{^producesNotJson?}}parseJson(const QJsonDocument& data){{/producesNotJson?}} override; + + private: + class Private; + QScopedPointer<Private> d;{{/allProperties?}}{{/normalResponse?}}{{/responses}} + }; +{{/operation}}{{/operations}}{{!skip EOL +}}} // namespace QMatrixClient |