Skip to content

Commit c1b8780

Browse files
[cpp-qt-client] Replace AnyType with QJsonValue (#12642)
1 parent 22ea4a6 commit c1b8780

6 files changed

Lines changed: 27 additions & 0 deletions

File tree

docs/generators/cpp-qt-client.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
3838
| Type/Alias | Imports |
3939
| ---------- | ------- |
4040
|OAIHttpFileElement|#include "OAIHttpFileElement.h"|
41+
|QJsonValue|#include <QJsonValue>|
4142

4243

4344
## INSTANTIATION TYPES

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppQtClientCodegen.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ public CppQtClientCodegen() {
108108
supportingFiles.add(new SupportingFile("Project.mustache", sourceFolder, "client.pri"));
109109
}
110110
typeMapping.put("file", PREFIX + "HttpFileElement");
111+
typeMapping.put("AnyType", "QJsonValue");
111112
importMapping.put(PREFIX + "HttpFileElement", "#include \"" + PREFIX + "HttpFileElement.h\"");
113+
importMapping.put("QJsonValue", "#include <QJsonValue>");
112114
}
113115

114116
@Override
@@ -140,7 +142,9 @@ public void processOpts() {
140142

141143

142144
typeMapping.put("file", modelNamePrefix + "HttpFileElement");
145+
typeMapping.put("AnyType", "QJsonValue");
143146
importMapping.put(modelNamePrefix + "HttpFileElement", "#include \"" + modelNamePrefix + "HttpFileElement.h\"");
147+
importMapping.put("QJsonValue", "#include <QJsonValue>");
144148
if (optionalProjectFileFlag) {
145149
supportingFiles.add(new SupportingFile("Project.mustache", sourceFolder, modelNamePrefix + "client.pri"));
146150
}

modules/openapi-generator/src/main/resources/cpp-qt-client/helpers-body.mustache

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,10 @@ QJsonValue toJsonValue(const {{prefix}}HttpFileElement &value) {
186186
return value.asJsonValue();
187187
}
188188

189+
QJsonValue toJsonValue(const QJsonValue &value) {
190+
return value;
191+
}
192+
189193
bool fromStringValue(const QString &inStr, QString &value) {
190194
value.clear();
191195
value.append(inStr);
@@ -415,6 +419,11 @@ bool fromJsonValue({{prefix}}HttpFileElement &value, const QJsonValue &jval) {
415419
return value.fromJsonValue(jval);
416420
}
417421

422+
bool fromJsonValue(QJsonValue &value, const QJsonValue &jval) {
423+
value = jval;
424+
return true;
425+
}
426+
418427
{{#cppNamespaceDeclarations}}
419428
} // namespace {{this}}
420429
{{/cppNamespaceDeclarations}}

modules/openapi-generator/src/main/resources/cpp-qt-client/helpers-header.mustache

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ QJsonValue toJsonValue(const double &value);
127127
QJsonValue toJsonValue(const {{prefix}}Object &value);
128128
QJsonValue toJsonValue(const {{prefix}}Enum &value);
129129
QJsonValue toJsonValue(const {{prefix}}HttpFileElement &value);
130+
QJsonValue toJsonValue(const QJsonValue &value);
130131

131132
template <typename T>
132133
QJsonValue toJsonValue(const QList<T> &val) {
@@ -213,6 +214,7 @@ bool fromJsonValue(double &value, const QJsonValue &jval);
213214
bool fromJsonValue({{prefix}}Object &value, const QJsonValue &jval);
214215
bool fromJsonValue({{prefix}}Enum &value, const QJsonValue &jval);
215216
bool fromJsonValue({{prefix}}HttpFileElement &value, const QJsonValue &jval);
217+
bool fromJsonValue(QJsonValue &value, const QJsonValue &jval);
216218

217219
template <typename T>
218220
bool fromJsonValue(QList<T> &val, const QJsonValue &jval) {

samples/client/petstore/cpp-qt/client/PFXHelpers.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,10 @@ QJsonValue toJsonValue(const PFXHttpFileElement &value) {
194194
return value.asJsonValue();
195195
}
196196

197+
QJsonValue toJsonValue(const QJsonValue &value) {
198+
return value;
199+
}
200+
197201
bool fromStringValue(const QString &inStr, QString &value) {
198202
value.clear();
199203
value.append(inStr);
@@ -423,4 +427,9 @@ bool fromJsonValue(PFXHttpFileElement &value, const QJsonValue &jval) {
423427
return value.fromJsonValue(jval);
424428
}
425429

430+
bool fromJsonValue(QJsonValue &value, const QJsonValue &jval) {
431+
value = jval;
432+
return true;
433+
}
434+
426435
} // namespace test_namespace

samples/client/petstore/cpp-qt/client/PFXHelpers.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ QJsonValue toJsonValue(const double &value);
135135
QJsonValue toJsonValue(const PFXObject &value);
136136
QJsonValue toJsonValue(const PFXEnum &value);
137137
QJsonValue toJsonValue(const PFXHttpFileElement &value);
138+
QJsonValue toJsonValue(const QJsonValue &value);
138139

139140
template <typename T>
140141
QJsonValue toJsonValue(const QList<T> &val) {
@@ -221,6 +222,7 @@ bool fromJsonValue(double &value, const QJsonValue &jval);
221222
bool fromJsonValue(PFXObject &value, const QJsonValue &jval);
222223
bool fromJsonValue(PFXEnum &value, const QJsonValue &jval);
223224
bool fromJsonValue(PFXHttpFileElement &value, const QJsonValue &jval);
225+
bool fromJsonValue(QJsonValue &value, const QJsonValue &jval);
224226

225227
template <typename T>
226228
bool fromJsonValue(QList<T> &val, const QJsonValue &jval) {

0 commit comments

Comments
 (0)