From c1b8780fff377979241bd04bcf4759ea6e004713 Mon Sep 17 00:00:00 2001 From: Daniel Renninghoff <1737566+danielrenninghoff@users.noreply.github.com> Date: Sat, 25 Jun 2022 03:40:28 +0200 Subject: [PATCH] [cpp-qt-client] Replace AnyType with QJsonValue (#12642) --- docs/generators/cpp-qt-client.md | 1 + .../codegen/languages/CppQtClientCodegen.java | 4 ++++ .../main/resources/cpp-qt-client/helpers-body.mustache | 9 +++++++++ .../main/resources/cpp-qt-client/helpers-header.mustache | 2 ++ samples/client/petstore/cpp-qt/client/PFXHelpers.cpp | 9 +++++++++ samples/client/petstore/cpp-qt/client/PFXHelpers.h | 2 ++ 6 files changed, 27 insertions(+) diff --git a/docs/generators/cpp-qt-client.md b/docs/generators/cpp-qt-client.md index 3e8027011ea3..c7da6c1da09b 100644 --- a/docs/generators/cpp-qt-client.md +++ b/docs/generators/cpp-qt-client.md @@ -38,6 +38,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl | Type/Alias | Imports | | ---------- | ------- | |OAIHttpFileElement|#include "OAIHttpFileElement.h"| +|QJsonValue|#include <QJsonValue>| ## INSTANTIATION TYPES diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppQtClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppQtClientCodegen.java index 5aa46278a9c1..6785239ef04c 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppQtClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppQtClientCodegen.java @@ -108,7 +108,9 @@ public CppQtClientCodegen() { supportingFiles.add(new SupportingFile("Project.mustache", sourceFolder, "client.pri")); } typeMapping.put("file", PREFIX + "HttpFileElement"); + typeMapping.put("AnyType", "QJsonValue"); importMapping.put(PREFIX + "HttpFileElement", "#include \"" + PREFIX + "HttpFileElement.h\""); + importMapping.put("QJsonValue", "#include "); } @Override @@ -140,7 +142,9 @@ public void processOpts() { typeMapping.put("file", modelNamePrefix + "HttpFileElement"); + typeMapping.put("AnyType", "QJsonValue"); importMapping.put(modelNamePrefix + "HttpFileElement", "#include \"" + modelNamePrefix + "HttpFileElement.h\""); + importMapping.put("QJsonValue", "#include "); if (optionalProjectFileFlag) { supportingFiles.add(new SupportingFile("Project.mustache", sourceFolder, modelNamePrefix + "client.pri")); } diff --git a/modules/openapi-generator/src/main/resources/cpp-qt-client/helpers-body.mustache b/modules/openapi-generator/src/main/resources/cpp-qt-client/helpers-body.mustache index 0661117b0abf..0e19b1771fb5 100644 --- a/modules/openapi-generator/src/main/resources/cpp-qt-client/helpers-body.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-qt-client/helpers-body.mustache @@ -186,6 +186,10 @@ QJsonValue toJsonValue(const {{prefix}}HttpFileElement &value) { return value.asJsonValue(); } +QJsonValue toJsonValue(const QJsonValue &value) { + return value; +} + bool fromStringValue(const QString &inStr, QString &value) { value.clear(); value.append(inStr); @@ -415,6 +419,11 @@ bool fromJsonValue({{prefix}}HttpFileElement &value, const QJsonValue &jval) { return value.fromJsonValue(jval); } +bool fromJsonValue(QJsonValue &value, const QJsonValue &jval) { + value = jval; + return true; +} + {{#cppNamespaceDeclarations}} } // namespace {{this}} {{/cppNamespaceDeclarations}} diff --git a/modules/openapi-generator/src/main/resources/cpp-qt-client/helpers-header.mustache b/modules/openapi-generator/src/main/resources/cpp-qt-client/helpers-header.mustache index 6b0ad489b1cb..75523b15ebff 100644 --- a/modules/openapi-generator/src/main/resources/cpp-qt-client/helpers-header.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-qt-client/helpers-header.mustache @@ -127,6 +127,7 @@ QJsonValue toJsonValue(const double &value); QJsonValue toJsonValue(const {{prefix}}Object &value); QJsonValue toJsonValue(const {{prefix}}Enum &value); QJsonValue toJsonValue(const {{prefix}}HttpFileElement &value); +QJsonValue toJsonValue(const QJsonValue &value); template QJsonValue toJsonValue(const QList &val) { @@ -213,6 +214,7 @@ bool fromJsonValue(double &value, const QJsonValue &jval); bool fromJsonValue({{prefix}}Object &value, const QJsonValue &jval); bool fromJsonValue({{prefix}}Enum &value, const QJsonValue &jval); bool fromJsonValue({{prefix}}HttpFileElement &value, const QJsonValue &jval); +bool fromJsonValue(QJsonValue &value, const QJsonValue &jval); template bool fromJsonValue(QList &val, const QJsonValue &jval) { diff --git a/samples/client/petstore/cpp-qt/client/PFXHelpers.cpp b/samples/client/petstore/cpp-qt/client/PFXHelpers.cpp index 7245de9007fe..aab9ed05f202 100644 --- a/samples/client/petstore/cpp-qt/client/PFXHelpers.cpp +++ b/samples/client/petstore/cpp-qt/client/PFXHelpers.cpp @@ -194,6 +194,10 @@ QJsonValue toJsonValue(const PFXHttpFileElement &value) { return value.asJsonValue(); } +QJsonValue toJsonValue(const QJsonValue &value) { + return value; +} + bool fromStringValue(const QString &inStr, QString &value) { value.clear(); value.append(inStr); @@ -423,4 +427,9 @@ bool fromJsonValue(PFXHttpFileElement &value, const QJsonValue &jval) { return value.fromJsonValue(jval); } +bool fromJsonValue(QJsonValue &value, const QJsonValue &jval) { + value = jval; + return true; +} + } // namespace test_namespace diff --git a/samples/client/petstore/cpp-qt/client/PFXHelpers.h b/samples/client/petstore/cpp-qt/client/PFXHelpers.h index 3980b8ac2f16..ad1c3bb0cdad 100644 --- a/samples/client/petstore/cpp-qt/client/PFXHelpers.h +++ b/samples/client/petstore/cpp-qt/client/PFXHelpers.h @@ -135,6 +135,7 @@ QJsonValue toJsonValue(const double &value); QJsonValue toJsonValue(const PFXObject &value); QJsonValue toJsonValue(const PFXEnum &value); QJsonValue toJsonValue(const PFXHttpFileElement &value); +QJsonValue toJsonValue(const QJsonValue &value); template QJsonValue toJsonValue(const QList &val) { @@ -221,6 +222,7 @@ bool fromJsonValue(double &value, const QJsonValue &jval); bool fromJsonValue(PFXObject &value, const QJsonValue &jval); bool fromJsonValue(PFXEnum &value, const QJsonValue &jval); bool fromJsonValue(PFXHttpFileElement &value, const QJsonValue &jval); +bool fromJsonValue(QJsonValue &value, const QJsonValue &jval); template bool fromJsonValue(QList &val, const QJsonValue &jval) {