From a0430b1fb722a77ad7cbd28f181727d46d92b3a2 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sat, 6 Jun 2020 20:47:56 +0200 Subject: gtad/*: optimise and use latest GTAD features - The generated code is updated to be compatible with the BaseJob changes introduced in the previous commit. This includes greatly reducing the number of header files that have to be explicitly #included, as basejob.h now #includes converters.h. Also, thanks to the changes in BaseJob, none of generated job classes needs a pimpl Private class. - gtad/template.*.mustache files are replaced with data.h.mustache for data structures (entirely defined in header files from now on) and operation.*.mustache for API operations (also massively moved to header files, possibly also becoming header-only in the future). - New variable-dropping and title-overring features in GTAD 0.7 allow to use the upstream matrix-doc repo to generate the code. - CMakeLists.txt makes use of file globbing with CONFIGURE_DEPENDS where possible to alleviate build reconfiguration after a GTAD call. --- gtad/operation.h.mustache | 128 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 gtad/operation.h.mustache (limited to 'gtad/operation.h.mustache') diff --git a/gtad/operation.h.mustache b/gtad/operation.h.mustache new file mode 100644 index 00000000..34c8a361 --- /dev/null +++ b/gtad/operation.h.mustache @@ -0,0 +1,128 @@ +{{>preamble}} +#pragma once + +#include "jobs/basejob.h" +{{#imports}} +#include {{_}}{{/imports}} +{{#operations.producesNonJson?}} +#include {{/operations.producesNonJson?}} + +namespace Quotient { +{{#operations.operation}} + +/*!{{>docCommentSummary}}{{#description}} + * {{_}}{{/description}} + */ +class {{camelCaseOperationId}}Job : public BaseJob { +public: + {{#models}} + // Inner data structures + {{#model}} + + {{>docCommentShort}} + struct {{name}}{{#parents?}} : + {{!Quotient:: is a workaround for cases when the same name is used for + the outer and the inner structure (unfortunately very easy + to hit if you don't give a title to the structure that has + $ref and other properties)}} + {{#parents}}Quotient::{{name}}{{>cjoin}}{{/parents}}{{/parents?}} + { + {{#vars}} + {{>docCommentShort}} + {{>maybeOmittableType}} {{nameCamelCase}}; + {{/vars}} + {{#propertyMap}} + {{>docCommentShort}} + {{>maybeOmittableType}} {{nameCamelCase}}; + {{/propertyMap}} + }; + {{/model}} + + // Construction/destruction + + {{/models}} + {{#allParams?}} + /*!{{>docCommentSummary}} + {{#allParams}} + * + * \param {{nameCamelCase}}{{#description}} + * {{_}}{{/description}} + {{/allParams}} + */ + {{/allParams?}}{{^allParams?}} + {{#summary}} + /// {{summary}} + {{/summary}} + {{/allParams?}} + explicit {{camelCaseOperationId}}Job({{#allParams}}{{>joinedParamDecl}}{{/allParams}}); + {{^hasBody?}} + + /*! \brief 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?}}); + {{/hasBody?}} + {{#responses}}{{#normalResponse?}}{{#allProperties?}} + + // Result properties + {{#headers}} + + {{>nonInlineResponseSignature}} + { + return reply()->rawHeader("{{baseName}}"); + } + {{/headers}}{{#inlineResponse}} + + {{>docCommentShort}} + {{dataType.name}} {{paramName}}(){{^moveOnly}}{{^producesNonJson?}} const{{/producesNonJson?}}{{/moveOnly}} + { + return {{#producesNonJson?}}reply(){{/producesNonJson?}} + {{^producesNonJson? + }}fromJson<{{dataType.name}}>(jsonData()){{/producesNonJson? + }}; + } + {{/inlineResponse}}{{#properties}} + + {{!there's nothing in #properties if the response is inline}} + {{>nonInlineResponseSignature}} + { + return {{>takeOrLoad}}FromJson<{{>maybeOmittableType}}>("{{baseName}}"_ls); + } + {{/properties}} + {{/allProperties?}}{{/normalResponse?}}{{/responses}} +}; + {{#models.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) + { {{#parents}} + fillFromJson<{{name}}{{!of the parent!}}>(jo, result); + {{/parents}}{{#vars}} + fromJson(jo.{{>takeOrValue}}("{{baseName}}"_ls), + result.{{nameCamelCase}}); + {{/vars}}{{#propertyMap}} + fromJson(jo, result.{{nameCamelCase}}); + {{/propertyMap}} + } + {{/out?}} +}; + {{/models.model}} +{{/operations.operation}} + +} // namespace Quotient -- cgit v1.2.3 From e0ac446f41fdb1c476196a5ebfb72c995a959b8d Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Thu, 18 Jun 2020 11:22:02 +0200 Subject: *.h.mustache: minor fixes The Quotient:: workaround seems no more necessary. --- gtad/operation.h.mustache | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'gtad/operation.h.mustache') diff --git a/gtad/operation.h.mustache b/gtad/operation.h.mustache index 34c8a361..36963b9a 100644 --- a/gtad/operation.h.mustache +++ b/gtad/operation.h.mustache @@ -21,11 +21,7 @@ public: {{>docCommentShort}} struct {{name}}{{#parents?}} : - {{!Quotient:: is a workaround for cases when the same name is used for - the outer and the inner structure (unfortunately very easy - to hit if you don't give a title to the structure that has - $ref and other properties)}} - {{#parents}}Quotient::{{name}}{{>cjoin}}{{/parents}}{{/parents?}} + {{#parents}}{{name}}{{>cjoin}}{{/parents}}{{/parents?}} { {{#vars}} {{>docCommentShort}} @@ -44,9 +40,9 @@ public: {{#allParams?}} /*!{{>docCommentSummary}} {{#allParams}} - * * \param {{nameCamelCase}}{{#description}} - * {{_}}{{/description}} + * {{_}}{{/description}}{{#_join}} + * {{/_join}} {{/allParams}} */ {{/allParams?}}{{^allParams?}} @@ -77,7 +73,8 @@ public: {{/headers}}{{#inlineResponse}} {{>docCommentShort}} - {{dataType.name}} {{paramName}}(){{^moveOnly}}{{^producesNonJson?}} const{{/producesNonJson?}}{{/moveOnly}} + {{dataType.name}} {{paramName}}() + {{^moveOnly}}{{^producesNonJson?}} const{{/producesNonJson?}}{{/moveOnly}} { return {{#producesNonJson?}}reply(){{/producesNonJson?}} {{^producesNonJson? -- cgit v1.2.3 From 0a775d9b3209be15dea8b8915fc0a1c8e0046ba6 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sat, 16 Jan 2021 18:19:45 +0100 Subject: Updated copyright statements upon Git audit After going through all the files and the history of commits on them it was clear that some copyright statements are obsolete (the code has been overwritten since) and some are missing. This commit tries best to remedy that, along with adding SPDX tags where they were still not used. Also, a minimal SPDX convention is documented for further contributions. Closes #426. --- gtad/operation.h.mustache | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'gtad/operation.h.mustache') diff --git a/gtad/operation.h.mustache b/gtad/operation.h.mustache index 36963b9a..135eee55 100644 --- a/gtad/operation.h.mustache +++ b/gtad/operation.h.mustache @@ -1,3 +1,7 @@ +{{! +SPDX-FileCopyrightText: 2020 Kitsune Ral +SPDX-License-Identifier: LGPL-2.1-or-later +}} {{>preamble}} #pragma once -- cgit v1.2.3 From 65e6ecd9711372e1e2afde769967ee46b3920307 Mon Sep 17 00:00:00 2001 From: Alexey Rusakov Date: Wed, 23 Jun 2021 19:12:26 +0200 Subject: *.mustache: Drop a stray leading end-of-line An SPDX comment in the source code did not collapse entirely. --- gtad/operation.h.mustache | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'gtad/operation.h.mustache') diff --git a/gtad/operation.h.mustache b/gtad/operation.h.mustache index 135eee55..f91dc66c 100644 --- a/gtad/operation.h.mustache +++ b/gtad/operation.h.mustache @@ -1,8 +1,7 @@ {{! SPDX-FileCopyrightText: 2020 Kitsune Ral SPDX-License-Identifier: LGPL-2.1-or-later -}} -{{>preamble}} +}}{{>preamble}} #pragma once #include "jobs/basejob.h" -- cgit v1.2.3 From f69e1c52246b986fb91f595ee0ee363e5343dbbb Mon Sep 17 00:00:00 2001 From: Alexey Rusakov Date: Wed, 29 Dec 2021 15:57:14 +0100 Subject: operation.h.mustache: Add QUOTIENT_API --- gtad/operation.h.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gtad/operation.h.mustache') diff --git a/gtad/operation.h.mustache b/gtad/operation.h.mustache index f91dc66c..063f0bbd 100644 --- a/gtad/operation.h.mustache +++ b/gtad/operation.h.mustache @@ -16,7 +16,7 @@ namespace Quotient { /*!{{>docCommentSummary}}{{#description}} * {{_}}{{/description}} */ -class {{camelCaseOperationId}}Job : public BaseJob { +class QUOTIENT_API {{camelCaseOperationId}}Job : public BaseJob { public: {{#models}} // Inner data structures -- cgit v1.2.3