aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/csapi/gtad.yaml12
-rw-r--r--lib/csapi/{{base}}.cpp.mustache173
-rw-r--r--lib/csapi/{{base}}.h.mustache145
3 files changed, 193 insertions, 137 deletions
diff --git a/lib/csapi/gtad.yaml b/lib/csapi/gtad.yaml
index a44f803a..301ee0b6 100644
--- a/lib/csapi/gtad.yaml
+++ b/lib/csapi/gtad.yaml
@@ -118,24 +118,32 @@ mustache:
# _rightQuote: '"'
# _joinChar: ',' # The character used by {{_join}} - not working yet
_comment: '//'
+ copyrightName: Kitsune Ral
+ copyrightEmail: <kitsune-ral@users.sf.net>
+
partials:
_typeRenderer: "{{#scope}}{{scopeCamelCase}}Job::{{/scope}}{{>name}}"
omittedValue: '{}' # default value to initialize omitted parameters with
initializer: '{{defaultValue}}'
cjoin: '{{#hasMore}}, {{/hasMore}}'
+
openOmittable: "{{^required?}}{{#useOmittable}}{{^defaultValue}}Omittable<{{/defaultValue}}{{/useOmittable}}{{/required?}}"
closeOmittable: "{{^required?}}{{#useOmittable}}{{^defaultValue}}>{{/defaultValue}}{{/useOmittable}}{{/required?}}"
+
maybeOmittableType: "{{>openOmittable}}{{dataType.name}}{{>closeOmittable}}"
qualifiedMaybeOmittableType: "{{>openOmittable}}{{dataType.qualifiedName}}{{>closeOmittable}}"
+
maybeCrefType: "{{#avoidCopy}}const {{/avoidCopy}}{{>maybeOmittableType}}{{#avoidCopy}}&{{/avoidCopy}}{{#moveOnly}}&&{{/moveOnly}}"
qualifiedMaybeCrefType:
"{{#avoidCopy}}const {{/avoidCopy}}{{>qualifiedMaybeOmittableType}}{{#avoidCopy}}&{{/avoidCopy}}{{#moveOnly}}&&{{/moveOnly}}"
+
+ maybeCrefJsonObject: "{{^propertyMap}}const QJsonObject&{{/propertyMap}}{{#propertyMap}}QJsonObject{{/propertyMap}}"
+ takeOrValue: "{{#propertyMap}}take{{/propertyMap}}{{^propertyMap}}value{{/propertyMap}}"
+
initializeDefaultValue: "{{#defaultValue}}{{>initializer}}{{/defaultValue}}{{^defaultValue}}{{>omittedValue}}{{/defaultValue}}"
joinedParamDecl: '{{>maybeCrefType}} {{paramName}}{{^required?}} = {{>initializeDefaultValue}}{{/required?}}{{>cjoin}}'
joinedParamDef: '{{>maybeCrefType}} {{paramName}}{{>cjoin}}'
passQueryParams: '{{#queryParams}}{{paramName}}{{>cjoin}}{{/queryParams}}'
- copyrightName: Kitsune Ral
- copyrightEmail: <kitsune-ral@users.sf.net>
templates:
- "{{base}}.h.mustache"
diff --git a/lib/csapi/{{base}}.cpp.mustache b/lib/csapi/{{base}}.cpp.mustache
index ff888d76..f9a63412 100644
--- a/lib/csapi/{{base}}.cpp.mustache
+++ b/lib/csapi/{{base}}.cpp.mustache
@@ -1,80 +1,98 @@
{{>preamble}}
#include "{{filenameBase}}.h"
{{^models}}
-#include "converters.h"
-{{/models}}{{#operations}}
-{{#producesNonJson?}}#include <QtNetwork/QNetworkReply>
-{{/producesNonJson?}}#include <QtCore/QStringBuilder>
+#include "converters.h"{{/models}}
+{{#operations}}
+{{#producesNonJson?}}
+#include <QtNetwork/QNetworkReply>
+{{/producesNonJson?}}
+#include <QtCore/QStringBuilder>
{{/operations}}
using namespace QMatrixClient;
-{{#models.model}}{{#in?}}
-void JsonObjectConverter<{{qualifiedName}}>::dumpTo(
- QJsonObject& jo, const {{qualifiedName}}& pod)
+{{#models.model}}
+ {{#in?}}
+void JsonObjectConverter<{{qualifiedName}}>::dumpTo(QJsonObject& jo, const {{qualifiedName}}& pod)
{
-{{#propertyMap}} fillJson(jo, pod.{{nameCamelCase}});
-{{/propertyMap}}{{#parents}} fillJson<{{name}}>(jo, pod);
-{{/parents}}{{#vars}} addParam<{{^required?}}IfNotEmpty{{/required?}}>(jo, QStringLiteral("{{baseName}}"), pod.{{nameCamelCase}});
-{{/vars}}}{{!<- dumpTo() ends here}}
-{{/in?}}{{#out?}}
-void JsonObjectConverter<{{qualifiedName}}>::fillFrom(
- {{^propertyMap}}const QJsonObject&{{/propertyMap
- }}{{#propertyMap}}QJsonObject{{/propertyMap}} jo, {{qualifiedName}}& result)
+{{#propertyMap
+}} fillJson(jo, pod.{{nameCamelCase}});
+{{/propertyMap}}{{#parents
+}} fillJson<{{name}}>(jo, pod);
+{{/parents}}{{#vars
+}} addParam<{{^required?}}IfNotEmpty{{/required?}}>(jo, QStringLiteral("{{baseName}}"), pod.{{nameCamelCase}});
+{{/vars}}
+}
+ {{/in?}}{{#out?}}
+void JsonObjectConverter<{{qualifiedName}}>::fillFrom({{>maybeCrefJsonObject}} jo, {{qualifiedName}}& result)
{
-{{#parents}} fillFromJson<{{qualifiedName}}>(jo, result);
-{{/parents}}{{#vars}} fromJson(jo.{{#propertyMap}}take{{/propertyMap
- }}{{^propertyMap}}value{{/propertyMap}}("{{baseName}}"_ls), result.{{nameCamelCase}});
-{{/vars}}{{#propertyMap}}
- fromJson(jo, result.{{nameCamelCase}});
-{{/propertyMap}}}
-{{/out?}}{{/models.model}}{{#operations}}
+{{#parents
+}} fillFromJson<{{qualifiedName}}>(jo, result);
+{{/parents}}{{#vars
+}} fromJson(jo.{{>takeOrValue}}("{{baseName}}"_ls), result.{{nameCamelCase}});
+{{/vars}}{{#propertyMap
+}} fromJson(jo, result.{{nameCamelCase}});
+{{/propertyMap}}
+}
+ {{/out?}}
+{{/models.model}}
+{{#operations}}
static const auto basePath = QStringLiteral("{{basePathWithoutHost}}");
-{{# operation}}{{#models}}
+ {{#operation}}{{#models}}
+// Converters
namespace QMatrixClient
{
- // Converters
-{{#model}}
- template <> struct JsonObjectConverter<{{qualifiedName}}>
+ {{#model}}
+template <> struct JsonObjectConverter<{{qualifiedName}}>
+{
+ {{#in?
+}} static void dumpTo(QJsonObject& jo, const {{qualifiedName}}& pod)
+ {
+{{#propertyMap
+}} fillJson(jo, pod.{{nameCamelCase}});
+{{/propertyMap}}{{#parents
+}} fillJson<{{name}}>(jo, pod);
+{{/parents}}{{#vars
+}} addParam<{{^required?}}IfNotEmpty{{/required?}}>(jo, QStringLiteral("{{baseName}}"), pod.{{nameCamelCase}});
+{{/vars}}
+ }
+ {{/in?}}{{#out?
+}} static void fillFrom({{>maybeCrefJsonObject}} jo, {{qualifiedName}}& result)
{
-{{#in?}} static void dumpTo(QJsonObject& jo, const {{qualifiedName}}& pod)
- {
-{{#propertyMap}} fillJson(jo, pod.{{nameCamelCase}});
- {{/propertyMap}}{{#parents}}fillJson<{{name}}>(jo, pod);
- {{/parents}}{{#vars
-}} addParam<{{^required?}}IfNotEmpty{{/required?}}>(jo, QStringLiteral("{{baseName}}"), pod.{{nameCamelCase}});
-{{/vars}} }
-{{/in?}}{{#out?
-}} static void fillFrom({{^propertyMap}}const QJsonObject&{{/propertyMap
- }}{{#propertyMap}}QJsonObject{{/propertyMap}} jo, {{qualifiedName}}& result)
- {
-{{#parents}} fillFromJson<{{qualifiedName}}{{!of the parent!}}>(jo, result);
- {{/parents}}{{#vars
-}} fromJson(jo.{{#propertyMap}}take{{/propertyMap
- }}{{^propertyMap}}value{{/propertyMap}}("{{baseName}}"_ls), result.{{nameCamelCase}});
-{{/vars}}{{#propertyMap}} fromJson(jo, result.{{nameCamelCase}});
-{{/propertyMap}} }
-{{/out?}} };
-{{/model}}} // namespace QMatrixClient
-{{/ models}}{{#responses}}{{#normalResponse?}}{{#allProperties?}}
+{{#parents
+}} fillFromJson<{{qualifiedName}}{{!of the parent!}}>(jo, result);
+{{/parents}}{{#vars
+}} fromJson(jo.{{>takeOrValue}}("{{baseName}}"_ls), result.{{nameCamelCase}});
+{{/vars}}{{#propertyMap
+}} fromJson(jo, result.{{nameCamelCase}});
+{{/propertyMap}}
+ }
+ {{/out?}}
+};
+ {{/model}}
+} // namespace QMatrixClient
+ {{/models}}
+ {{#responses}}{{#normalResponse?}}{{#allProperties?}}
class {{camelCaseOperationId}}Job::Private
{
public:{{#allProperties}}
{{>maybeOmittableType}} {{paramName}};{{/allProperties}}
};
-{{/ allProperties?}}{{/normalResponse?}}{{/responses}}{{#queryParams?}}
+ {{/allProperties?}}{{/normalResponse?}}{{/responses}}
+ {{#queryParams?}}
BaseJob::Query queryTo{{camelCaseOperationId}}({{#queryParams}}{{>joinedParamDef}}{{/queryParams}})
{
BaseJob::Query _q;{{#queryParams}}
addParam<{{^required?}}IfNotEmpty{{/required?}}>(_q, QStringLiteral("{{baseName}}"), {{paramName}});{{/queryParams}}
return _q;
}
-{{/queryParams?}}{{^bodyParams}}
+ {{/queryParams?}}
+ {{^bodyParams}}
QUrl {{camelCaseOperationId}}Job::makeRequestUrl(QUrl baseUrl{{#allParams?}}, {{#allParams}}{{>joinedParamDef}}{{/allParams}}{{/allParams?}})
{
return BaseJob::makeRequestUrl(std::move(baseUrl),
basePath{{#pathParts}} % {{_}}{{/pathParts}}{{#queryParams?}},
queryTo{{camelCaseOperationId}}({{>passQueryParams}}){{/queryParams?}});
}
-{{/ bodyParams}}
+ {{/bodyParams}}
static const auto {{camelCaseOperationId}}JobName = QStringLiteral("{{camelCaseOperationId}}Job");
{{camelCaseOperationId}}Job::{{camelCaseOperationId}}Job({{#allParams}}{{>joinedParamDef}}{{/allParams}})
@@ -84,40 +102,53 @@ static const auto {{camelCaseOperationId}}JobName = QStringLiteral("{{camelCaseO
{}{{/queryParams?}}, false{{/skipAuth}}){{#responses}}{{#normalResponse?}}{{#allProperties?}}
, d(new Private){{/allProperties?}}{{/normalResponse?}}{{/responses}}
{
-{{#headerParams?}}{{#headerParams}} setRequestHeader("{{baseName}}", {{paramName}}.toLatin1());
-{{/headerParams}}
-{{/headerParams?
-}}{{#bodyParams?
-}}{{#inlineBody}} setRequestData(Data({{!
- }}{{#consumesNonJson?}}{{nameCamelCase}}{{/consumesNonJson?
- }}{{^consumesNonJson?}}toJson({{nameCamelCase}}){{/consumesNonJson?}}));{{/inlineBody
-}}{{^inlineBody}} QJsonObject _data;{{#bodyParams}}
+{{#headerParams?}}{{#headerParams
+}} setRequestHeader("{{baseName}}", {{paramName}}.toLatin1());{{/headerParams}}
+{{/headerParams?}}{{#bodyParams?
+}}{{#inlineBody
+}} setRequestData(Data({{#consumesNonJson?}}{{nameCamelCase}}{{/consumesNonJson?
+ }}{{^consumesNonJson?}}toJson({{nameCamelCase}}){{/consumesNonJson?}}));
+{{/inlineBody}}{{^inlineBody
+}} QJsonObject _data;{{#bodyParams}}
addParam<{{^required?}}IfNotEmpty{{/required?}}>(_data, QStringLiteral("{{baseName}}"), {{paramName}});{{/bodyParams}}
- setRequestData(_data);{{/inlineBody}}
-{{/bodyParams?}}{{#producesNonJson?}} setExpectedContentTypes({ {{#produces}}"{{_}}"{{>cjoin}}{{/produces}} });
-{{/producesNonJson?}}}{{!<- mind the actual brace}}
-{{# responses}}{{#normalResponse?}}{{#allProperties?}}
+ setRequestData(_data);
+{{/inlineBody}}{{/bodyParams?
+}}{{#producesNonJson?
+}} setExpectedContentTypes({ {{#produces}}"{{_}}"{{>cjoin}}{{/produces}} });
+{{/producesNonJson?}}
+}
+ {{#responses}}{{#normalResponse?}}{{#allProperties?}}
{{camelCaseOperationId}}Job::~{{camelCaseOperationId}}Job() = default;
-{{# allProperties}}
+ {{#allProperties}}
{{>qualifiedMaybeCrefType}} {{camelCaseOperationId}}Job::{{paramName}}(){{^moveOnly}} const{{/moveOnly}}
{
return {{#moveOnly}}std::move({{/moveOnly}}d->{{paramName}}{{#moveOnly}}){{/moveOnly}};
}
-{{/ allProperties}}{{#producesNonJson?}}
+ {{/allProperties}}
+ {{#producesNonJson?}}
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;
-}{{/ producesNonJson?}}{{^producesNonJson?}}
+}
+ {{/producesNonJson?}}{{^producesNonJson?}}
BaseJob::Status {{camelCaseOperationId}}Job::parseJson(const QJsonDocument& data)
{
-{{#inlineResponse}} fromJson(data, d->{{paramName}});
-{{/inlineResponse}}{{^inlineResponse}} auto json = data.object();
-{{#properties}}{{#required?}} if (!json.contains("{{baseName}}"_ls))
+{{#inlineResponse
+}} fromJson(data, d->{{paramName}});
+{{/inlineResponse}}{{^inlineResponse
+}} auto json = data.object();
+{{# properties}}{{#required?
+}} if (!json.contains("{{baseName}}"_ls))
return { JsonParseError,
"The key '{{baseName}}' not found in the response" };
-{{/required?}} fromJson(json.value("{{baseName}}"_ls), d->{{paramName}});
-{{/properties}}{{/inlineResponse}} return Success;
-}{{/ producesNonJson?}}
-{{/allProperties?}}{{/normalResponse?}}{{/responses}}{{/operation}}{{/operations}}
+{{/required?
+}} fromJson(json.value("{{baseName}}"_ls), d->{{paramName}});
+{{/ properties}}
+{{/inlineResponse
+}} return Success;
+}
+ {{/producesNonJson?}}
+ {{/allProperties?}}{{/normalResponse?}}{{/responses}}
+{{/operation}}{{/operations}}
diff --git a/lib/csapi/{{base}}.h.mustache b/lib/csapi/{{base}}.h.mustache
index a9c3a63a..61380ec6 100644
--- a/lib/csapi/{{base}}.h.mustache
+++ b/lib/csapi/{{base}}.h.mustache
@@ -1,78 +1,95 @@
{{>preamble}}
#pragma once
-{{#operations}}#include "jobs/basejob.h"
-{{/operations}}{{#models}}#include "converters.h"
-{{/models}}
-{{#imports}}#include {{_}}
-{{/imports}}
+{{#operations}}
+#include "jobs/basejob.h"{{/operations}}
+{{#models}}
+#include "converters.h"{{/models}}
+{{#imports}}
+#include {{_}}{{/imports}}
+
namespace QMatrixClient
{
-{{#models}} // Data structures
-{{# model}}{{#description}}
- /// {{_}}{{/description}}
+{{#models}}
+// Data structures
+{{# model}}
+{{#description}}/// {{_}}{{/description}}
+struct {{name}}{{#parents?}} : {{#parents}}{{name}}{{>cjoin}}{{/parents}}{{/parents?}}
+{
+{{# vars}}{{#description?}} /// {{#description}}{{_}}{{/description}}{{/description?}}
+ {{>maybeOmittableType}} {{nameCamelCase}};
+{{/ vars}}
+{{# propertyMap}}
+{{#description?}} /// {{#description}}{{_}}{{/description}}{{/description?}}
+ {{>maybeOmittableType}} {{nameCamelCase}};
+{{/ propertyMap}}
+};
+
+template <> struct JsonObjectConverter<{{name}}>
+{
+ {{#in?}}static void dumpTo(QJsonObject& jo, const {{name}}& pod);{{/in?}}
+ {{#out?}}static void fillFrom({{>maybeCrefJsonObject}} jo, {{name}}& pod);{{/out?}}};
+{{/ model}}
+{{/models}}
+{{#operations}}// Operations
+{{# operation}}
+{{#summary}}/// {{summary}}{{/summary}}
+{{#description?}}/*!{{#description}}
+ * {{_}}{{/description}}
+ */{{/description?}}
+class {{camelCaseOperationId}}Job : public BaseJob
+{
+public:{{#models}}
+ // Inner data structures
+{{# model}}
+{{#description?}} /// {{#description}}{{_}}{{/description}}{{/description?}}
struct {{name}}{{#parents?}} : {{#parents}}{{name}}{{>cjoin}}{{/parents}}{{/parents?}}
{
-{{#vars}}{{#description}} /// {{_}}
-{{/description}} {{>maybeOmittableType}} {{nameCamelCase}};
-{{/vars}}{{#propertyMap}}{{#description}} /// {{_}}
-{{/description}} {{>maybeOmittableType}} {{nameCamelCase}};
-{{/propertyMap}} };
- template <> struct JsonObjectConverter<{{name}}>
- {
- {{#in?}}static void dumpTo(QJsonObject& jo, const {{name}}& pod);
- {{/in?}}{{#out?}}static void fillFrom({{^propertyMap}}const QJsonObject&{{/propertyMap
- }}{{#propertyMap}}QJsonObject{{/propertyMap}} jo, {{name}}& pod);
-{{/out?}} };
-{{/model}}
-{{/models}}{{#operations}} // Operations
-{{# operation}}{{#summary}}
- /// {{summary}}{{#description?}}{{!add a linebreak between summary and description if both exist}}
- ///{{/description?}}{{/summary}}{{#description}}
- /// {{_}}{{/description}}
- class {{camelCaseOperationId}}Job : public BaseJob
- {
- public:{{#models}}
- // Inner data structures
-{{# model}}{{#description}}
- /// {{_}}{{/description}}
- struct {{name}}{{#parents?}} : {{#parents}}{{name}}{{>cjoin}}{{/parents}}{{/parents?}}
- {
-{{#vars}}{{#description}} /// {{_}}
-{{/description}} {{>maybeOmittableType}} {{nameCamelCase}};
-{{/vars}}{{#propertyMap}}{{#description}} /// {{_}}
-{{/description}} {{>maybeOmittableType}} {{nameCamelCase}};
-{{/propertyMap}} };
+{{# vars}}{{#description?}} /// {{#description}}{{_}}{{/description}}{{/description?}}
+ {{>maybeOmittableType}} {{nameCamelCase}};
+{{/ vars}}
+{{# propertyMap}}
+{{#description?}} /// {{#description}}{{_}}{{/description}}{{/description?}}
+ {{>maybeOmittableType}} {{nameCamelCase}};
+{{/ propertyMap}}
+ };
{{/ model}}
- // Construction/destruction
+ // Construction/destruction
{{/ models}}{{#allParams?}}
- /*! {{summary}}{{#allParams}}
- * \param {{nameCamelCase}}{{#description}}
- * {{_}}{{/description}}{{/allParams}}
- */{{/allParams?}}
- explicit {{camelCaseOperationId}}Job({{#allParams}}{{>joinedParamDecl}}{{/allParams}});{{^bodyParams}}
+ /*! {{summary}}{{#allParams}}
+ * \param {{nameCamelCase}}{{#description}}
+ * {{_}}{{/description}}{{/allParams}}
+ */{{/allParams?}}
+ explicit {{camelCaseOperationId}}Job({{#allParams}}{{>joinedParamDecl}}{{/allParams}});
+{{^ bodyParams}}
- /*! Construct a URL without creating a full-fledged job object
- *
- * 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}}{{# responses}}{{#normalResponse?}}{{#allProperties?}}
- ~{{camelCaseOperationId}}Job() override;
+ /*! Construct a URL without creating a full-fledged job object
+ *
+ * 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}}
+{{# responses}}{{#normalResponse?}}{{#allProperties?}}
+ ~{{camelCaseOperationId}}Job() override;
- // Result properties
+ // Result properties
{{#allProperties}}{{#description}}
- /// {{_}}{{/description}}
- {{>maybeCrefType}} {{paramName}}(){{^moveOnly}} const{{/moveOnly}};{{/allProperties}}
+ /// {{_}}{{/description}}
+ {{>maybeCrefType}} {{paramName}}(){{^moveOnly}} const{{/moveOnly}};{{/allProperties}}
- protected:
- Status {{#producesNonJson?}}parseReply(QNetworkReply* reply){{/producesNonJson?}}{{^producesNonJson?}}parseJson(const QJsonDocument& data){{/producesNonJson?}} override;
+protected:{{#producesNonJson?}}
+ Status parseReply(QNetworkReply* reply) override;
+{{/producesNonJson?}}{{^producesNonJson?}}
+ Status parseJson(const QJsonDocument& data) override;
+{{/producesNonJson?}}
- private:
- class Private;
- QScopedPointer<Private> d;{{/allProperties?}}{{/normalResponse?}}{{/responses}}
- };
-{{/operation}}{{/operations}}{{!skip EOL
-}}} // namespace QMatrixClient
+private:
+ class Private;
+ QScopedPointer<Private> d;
+{{/ allProperties?}}{{/normalResponse?}}{{/responses}}
+};
+{{/ operation}}
+{{/operations}}
+} // namespace QMatrixClient