aboutsummaryrefslogtreecommitdiff
path: root/jobs
diff options
context:
space:
mode:
Diffstat (limited to 'jobs')
-rw-r--r--jobs/apigen.yaml57
-rw-r--r--jobs/preamble.mustache3
-rw-r--r--jobs/{{base}}.cpp.mustache76
-rw-r--r--jobs/{{base}}.h.mustache65
4 files changed, 201 insertions, 0 deletions
diff --git a/jobs/apigen.yaml b/jobs/apigen.yaml
new file mode 100644
index 00000000..69662a5d
--- /dev/null
+++ b/jobs/apigen.yaml
@@ -0,0 +1,57 @@
+preprocess:
+ "%CLIENT_RELEASE_LABEL%": r0
+ "%CLIENT_MAJOR_VERSION%": r0
+
+# 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..c9b0eb5e
--- /dev/null
+++ b/jobs/{{base}}.cpp.mustache
@@ -0,0 +1,76 @@
+{{#@filePartial}}preamble{{/@filePartial}}
+
+#include "{{filenameBase}}.h"
+
+{{#operations}}
+#include "../converters.h"
+
+#include <QtCore/QStringBuilder>
+
+using namespace QMatrixClient;
+
+ {{#returns?}}
+class {{#@cap}}{{operationId}}{{/@cap}}Job::Private
+{
+ public:
+ {{#returns}}
+ {{type}} {{name}};
+ {{/returns}}
+};
+ {{/returns?}}
+
+static const auto basePath = QStringLiteral("{{basePathWithoutHost}}");
+
+ {{#operation}}
+{{#@cap}}{{operationId}}{{/@cap}}Job::{{#@cap}}{{operationId}}{{/@cap}}Job(const ConnectionData* connection{{#allParams}}, {{!}}
+ {{#avoidCopy?}}const {{dataType}}&{{/avoidCopy?}}{{^avoidCopy?}}{{dataType}}{{/avoidCopy?}} {{paramName}}
+ {{/allParams}})
+ : BaseJob(connection, HttpVerb::{{#@cap}}{{#@tolower}}{{httpMethod}}{{/@tolower}}{{/@cap}}, "{{#@cap}}{{operationId}}{{/@cap}}Job"
+ , basePath{{#pathParts}} % {{part}}{{/pathParts}}
+ , Query { {{#queryParams}}
+ { "{{baseName}}", toJson({{paramName}}).toString() }{{#hasMore}}, {{/hasMore}}
+ {{/queryParams}} }
+ , Data { {{#bodyParams}}
+ { "{{baseName}}", toJson({{paramName}}) }{{#hasMore}}, {{/hasMore}}
+ {{/bodyParams}} }
+ {{#skipAuth}}, false{{/skipAuth}}
+ ){{#returns?}}, d(new Private){{/returns?}}
+{ }
+ {{/operation}}
+
+ {{#returns?}}
+{{className}}Job::~{{className}}Job()
+{
+ delete d;
+}
+
+ {{#returns}}
+{{type}} {{className}}Job::{{name}}() const
+{
+ return d->{{name}};
+}
+ {{/returns}}
+
+ {{#returnFile?}}
+BaseJob::Status {{className}}Job::parseReply(QByteArray data)
+{
+ {{#returns}}{{name}}{{/returns}} = data;
+ return Success;
+}
+ {{/returnFile?}}
+ {{^returnFile?}}
+BaseJob::Status {{className}}Job::parseJson(const QJsonDocument& data)
+{
+ auto json = data.object();
+ {{#returns}}
+ {{#required?}}
+ if (!json.contains("{{name}}")
+ return { JsonParseError, "{{name}} not found in the response" };
+ {{/required?}}
+ d->{{name}} = fromJson<{{type}}>(json.value("{{name}}"));
+ {{/returns}}
+ return Success;
+}
+ {{/returnFile?}}
+ {{/returns?}}
+{{/operations}}
diff --git a/jobs/{{base}}.h.mustache b/jobs/{{base}}.h.mustache
new file mode 100644
index 00000000..6fb9caef
--- /dev/null
+++ b/jobs/{{base}}.h.mustache
@@ -0,0 +1,65 @@
+{{#@filePartial}}preamble{{/@filePartial}}
+
+#pragma once
+
+{{#operations}}
+#include "../basejob.h"
+{{/operations}}
+
+{{#imports}}
+#include {{.}}
+{{/imports}}
+
+{{#models}}
+#include <QtCore/QJsonValue> {{! FIXME: This should probably go inside imports }}
+{{/models}}
+
+namespace QMatrixClient
+{
+{{#models}}
+ // Data structures
+ {{#model}}
+ struct {{classname}}
+ {
+ {{#vars}}
+ {{datatype}} {{name}};
+ {{/vars}}
+ operator QJsonValue() const { return {}; }
+ };
+ {{/model}}
+{{/models}}
+{{#operations}}
+ // Operations
+ {{#operation}}
+ class {{#@cap}}{{operationId}}{{/@cap}}Job : public BaseJob
+ {
+ public:
+ {{#@cap}}{{operationId}}{{/@cap}}Job(const ConnectionData* connection
+ {{#allParams}}
+ , {{!}}
+ {{#avoidCopy?}}const {{dataType}}&{{/avoidCopy?}}
+ {{^avoidCopy?}}{{dataType}}{{/avoidCopy?}} {{paramName}}
+ {{/allParams}});
+ {{#returns?}}
+ virtual {{className}}Job();
+
+ {{#returns}}
+ {{type}} {{name}}() const;
+ {{/returns}}
+
+ protected:
+ {{#returnFile?}}
+ Status parseReply(QByteArray data) override;
+ {{/returnFile?}}
+ {{^returnFile}}
+ Status parseJson(const JsonDocument& data) override;
+ {{/returnFile}}
+
+ private:
+ class Private;
+ Private* d;
+ {{/returns?}}
+ };
+ {{/operation}}
+{{/operations}}
+} // namespace QMatrixClient