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.cpp.mustache | 58 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 gtad/operation.cpp.mustache (limited to 'gtad/operation.cpp.mustache') diff --git a/gtad/operation.cpp.mustache b/gtad/operation.cpp.mustache new file mode 100644 index 00000000..3c3396e9 --- /dev/null +++ b/gtad/operation.cpp.mustache @@ -0,0 +1,58 @@ +{{>preamble}} +#include "{{filenameBase}}.h" + +#include + +using namespace Quotient; +{{#operations}}{{#operation}} + {{#queryParams?}} + +auto queryTo{{camelCaseOperationId}}( + {{#queryParams}}{{>joinedParamDef}}{{/queryParams}}) +{ + BaseJob::Query _q;{{#queryParams}} + addParam<{{^required?}}IfNotEmpty{{/required?}}>(_q, + QStringLiteral("{{baseName}}"), {{paramName}});{{/queryParams}} + return _q; +} + {{/queryParams?}} + {{^hasBody?}} + +QUrl {{camelCaseOperationId}}Job::makeRequestUrl(QUrl baseUrl{{#allParams?}}, + {{#allParams}}{{>joinedParamDef}}{{/allParams}}{{/allParams?}}) +{ + return BaseJob::makeRequestUrl(std::move(baseUrl), {{>passPathAndMaybeQuery}}); +} {{/hasBody?}} + +{{camelCaseOperationId}}Job::{{camelCaseOperationId}}Job( + {{#allParams}}{{>joinedParamDef}}{{/allParams}}) + : BaseJob(HttpVerb::{{#_cap}}{{#_tolower}}{{httpMethod}}{{/_tolower}}{{/_cap}}, + {{!object name}}QStringLiteral("{{camelCaseOperationId}}Job"), + {{>passPathAndMaybeQuery}} + {{#skipAuth}}{{#queryParams?}}, {}{{/queryParams?}}, false{{/skipAuth}} ) +{ {{#headerParams}} + setRequestHeader("{{baseName}}", {{paramName}}.toLatin1()); + {{/headerParams}}{{#inlineBody}}{{^propertyMap}}{{^bodyParams?}} + setRequestData(Data({{#consumesNonJson?}}{{nameCamelCase}}{{/consumesNonJson? + }}{{^consumesNonJson?}}toJson({{nameCamelCase}}){{/consumesNonJson?}})); + {{/bodyParams?}}{{/propertyMap}}{{/inlineBody + }}{{^consumesNonJson?}}{{#bodyParams?}} + QJsonObject _data; + {{#propertyMap}} + fillJson(_data, {{nameCamelCase}}); + {{/propertyMap}}{{#inlineBody}} + fillJson<{{>maybeOmittableType}}>(_data, {{paramName}}); + {{/inlineBody}}{{#bodyParams}} + addParam<{{^required?}}IfNotEmpty{{/required?}}>(_data, + QStringLiteral("{{baseName}}"), {{paramName}}); + {{/bodyParams}} + setRequestData(std::move(_data)); + {{/bodyParams?}}{{/consumesNonJson?}}{{#producesNonJson?}} + setExpectedContentTypes({ {{#produces}}"{{_}}"{{>cjoin}}{{/produces}} }); + {{/producesNonJson?}}{{^producesNonJson? + }}{{#responses}}{{#normalResponse?}}{{#properties}}{{#required?}} + addExpectedKey("{{baseName}}"); + {{/required?}}{{/properties}}{{/normalResponse?}}{{/responses + }}{{/producesNonJson?}} +} +{{/operation}}{{/operations}} -- cgit v1.2.3