aboutsummaryrefslogtreecommitdiff
path: root/jobs
diff options
context:
space:
mode:
Diffstat (limited to 'jobs')
-rw-r--r--jobs/basejob.cpp1
-rw-r--r--jobs/gtad.yaml59
-rw-r--r--jobs/preamble.mustache3
-rw-r--r--jobs/{{base}}.cpp.mustache75
-rw-r--r--jobs/{{base}}.h.mustache47
5 files changed, 184 insertions, 1 deletions
diff --git a/jobs/basejob.cpp b/jobs/basejob.cpp
index eb78dec8..7794337e 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..d09de66c
--- /dev/null
+++ b/jobs/gtad.yaml
@@ -0,0 +1,59 @@
+preprocess:
+ "%CLIENT_RELEASE_LABEL%": r0
+ "%CLIENT_MAJOR_VERSION%": r0
+ "unsigned:": "unsigned_:"
+ "default:": "default_:"
+
+# 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: bool
+ string:
+ - byte: &QByteArray { type: QByteArray, imports: <QtCore/QByteArray> }
+ - binary: *QByteArray
+ - date:
+ type: QDate
+ avoidCopy?: true
+ imports: <QtCore/QDate>
+ - dateTime:
+ type: QDateTime
+ avoidCopy?: true
+ imports: <QtCore/QDateTime>
+ - //: { type: QString, imports: <QtCore/QString> }
+ file:
+ type: QByteArray
+ imports: <QtCore/QByteArray>
+ "returnFile?": true
+ object: { type: QJsonObject, "avoidCopy?": true, imports: <QtCore/QJsonObject> }
+ array: { type: "QVector<{{1}}>", "avoidCopy?": true, imports: <QtCore/QVector> }
+
+#operations:
+
+env:
+# preamble: preamble.mustache
+ copyrightName: Kitsune Ral
+ copyrightEmail: <kitsune-ral@users.sf.net>
+# imports: { set: }
+# returnFile?: { bool: false }
+
+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..45668d4c
--- /dev/null
+++ b/jobs/{{base}}.cpp.mustache
@@ -0,0 +1,75 @@
+{{#@filePartial}}preamble{{/@filePartial}}
+
+#include "{{filenameBase}}.h"
+
+{{^models}}#include "jobs/converters.h"{{/models}}
+{{#operations}}#include <QtCore/QStringBuilder>{{/operations}}
+
+using namespace QMatrixClient;
+{{#models}}{{#model}}
+{{classname}}::operator QJsonValue() const
+{
+ QJsonObject o;
+ {{#vars}}o.insert("{{name}}", toJson({{name}}));
+ {{/vars}}
+ return o;
+}
+
+{{classname}} FromJson<{{classname}}>::operator()(QJsonValue jv)
+{
+ QJsonObject o = jv.toObject();
+ {{classname}} result;
+ {{#vars}}result.{{name}} = fromJson<{{datatype}}>(o.value("{{name}}"));
+ {{/vars}}
+ return result;
+}
+{{/model}}{{/models}}{{#operations}}
+static const auto basePath = QStringLiteral("{{basePathWithoutHost}}");
+{{# operation}}{{#responses}}{{#normalResponse?}}{{#properties?}}
+class {{camelCaseOperationId}}Job::Private
+{
+ public:
+ {{#properties}}{{dataType}} {{paramName}};
+ {{/properties}}
+};
+{{/ properties?}}{{/normalResponse?}}{{/responses}}
+{{camelCaseOperationId}}Job::{{camelCaseOperationId}}Job({{#allParams}}{{#avoidCopy?}}const {{dataType}}&{{/avoidCopy?}}{{^avoidCopy?}}{{dataType}}{{/avoidCopy?}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}})
+ : BaseJob(HttpVerb::{{#@cap}}{{#@tolower}}{{httpMethod}}{{/@tolower}}{{/@cap}}, "{{camelCaseOperationId}}Job",
+ basePath{{#pathParts}} % {{part}}{{/pathParts}},
+ Query {{^queryParams}}{ }{{/queryParams}}{{#queryParams?}}{
+ {{#queryParams}}{ "{{baseName}}", toJson({{paramName}}).toString() }{{#hasMore}},
+ {{/hasMore}}{{/queryParams}}
+ }{{/queryParams?}},
+ Data {{^bodyParams}}{ }{{/bodyParams}}{{#bodyParams?}}{
+ {{#bodyParams}}{ "{{baseName}}", toJson({{paramName}}) }{{#hasMore}},
+ {{/hasMore}}{{/bodyParams}}
+ }{{/bodyParams?}}{{#skipAuth}}, false{{/skipAuth}}
+ ){{#responses}}{{#normalResponse?}}{{#properties?}}, d(new Private){{/properties?}}{{/normalResponse?}}{{/responses}}
+{ }
+{{# responses}}{{#normalResponse?}}{{#properties?}}
+{{camelCaseOperationId}}Job::~{{camelCaseOperationId}}Job()
+{
+ delete d;
+}
+{{# properties}}
+const {{dataType}}& {{camelCaseOperationId}}Job::{{paramName}}() const
+{
+ return d->{{paramName}};
+}
+{{/ properties}}{{#returnFile?}}
+BaseJob::Status {{camelCaseOperationId}}Job::parseReply(QByteArray data)
+{
+ {{#properties}}{{paramName}}{{/properties}} = data;
+ return Success;
+}{{/ returnFile?}}{{^returnFile?}}
+BaseJob::Status {{camelCaseOperationId}}Job::parseJson(const QJsonDocument& data)
+{
+ auto json = data.object();
+ {{# properties}}{{#required?}}if (!json.contains("{{paramName}}"))
+ return { JsonParseError,
+ "The key '{{paramName}}' not found in the response" };{{/required?}}
+ d->{{paramName}} = fromJson<{{dataType}}>(json.value("{{paramName}}"));
+{{/ properties}}
+ return Success;
+}{{/ returnFile?}}
+{{/properties?}}{{/normalResponse?}}{{/responses}}{{/operation}}{{/operations}}
diff --git a/jobs/{{base}}.h.mustache b/jobs/{{base}}.h.mustache
new file mode 100644
index 00000000..ad8a2f1f
--- /dev/null
+++ b/jobs/{{base}}.h.mustache
@@ -0,0 +1,47 @@
+{{#@filePartial}}preamble{{/@filePartial}}
+
+#pragma once
+
+{{#operations}}#include "../basejob.h"
+{{/operations}}
+{{#imports}}#include {{.}}
+{{/imports}}
+{{#models}}#include "jobs/converters.h"
+{{/models}}
+namespace QMatrixClient
+{
+{{#models}} // Data structures
+{{# model}}
+ struct {{classname}}
+ {
+ {{#vars}}{{datatype}} {{name}};
+ {{/vars}}
+ operator QJsonValue() const;
+ };
+
+ template <> struct FromJson<{{classname}}>
+ {
+ {{classname}} operator()(QJsonValue jv);
+ };
+{{/ model}}
+{{/models}}
+{{#operations}} // Operations
+{{# operation}}
+ class {{camelCaseOperationId}}Job : public BaseJob
+ {
+ public:
+ explicit {{camelCaseOperationId}}Job({{#allParams}}{{#avoidCopy?}}const {{dataType}}&{{/avoidCopy?}}{{^avoidCopy?}}{{dataType}}{{/avoidCopy?}} {{paramName}}{{^required?}} = {{defaultValue}}{{^defaultValue}}{}{{/defaultValue}}{{/required?}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
+{{# responses}}{{#normalResponse?}}{{#properties?}}
+ ~{{camelCaseOperationId}}Job() override;
+
+ {{#properties}}const {{dataType}}& {{paramName}}() const;
+ {{/properties}}
+ protected:
+ {{^returnFile}}Status parseJson(const QJsonDocument& data) override;{{/returnFile}}
+ {{#returnFile?}}Status parseReply(QByteArray data) override;{{/returnFile?}}
+ private:
+ class Private;
+ Private* d;{{/properties?}}{{/normalResponse?}}{{/responses}}
+ };{{/operation}}
+{{/operations}}
+} // namespace QMatrixClient