Skip to content

Commit ac7c15e

Browse files
martonmikloskota65535
authored andcommitted
[cpp-qt-client]Allow nullable parameters (OpenAPITools#17805)
* [cpp-qt-client]Allow nullable parameters Fixes OpenAPITools#17756 * Update samples
1 parent 809647f commit ac7c15e

File tree

4 files changed

+65
-45
lines changed

4 files changed

+65
-45
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ void {{classname}}::{{nickname}}({{#allParams}}{{#required}}const {{{dataType}}}
397397
}
398398
fullPath.append(paramString);
399399
{{/isPrimitiveType}}{{#isPrimitiveType}}
400-
fullPath.append(QUrl::toPercentEncoding("{{baseName}}")).append(querySuffix).append(QUrl::toPercentEncoding(::{{cppNamespace}}::toStringValue({{paramName}}{{^required}}.value(){{/required}})));
400+
fullPath.append(QUrl::toPercentEncoding("{{baseName}}")).append(querySuffix).append(QUrl::toPercentEncoding({{paramName}}{{^required}}.stringValue(){{/required}}));
401401
{{/isPrimitiveType}}
402402
{{/collectionFormat}}
403403
{{#collectionFormat}}

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

+31-21
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,6 @@
2121
namespace {{this}} {
2222
{{/cppNamespaceDeclarations}}
2323

24-
template <typename T>
25-
class OptionalParam {
26-
public:
27-
T m_Value;
28-
bool m_hasValue;
29-
public:
30-
OptionalParam(){
31-
m_hasValue = false;
32-
}
33-
OptionalParam(const T &val){
34-
m_hasValue = true;
35-
m_Value = val;
36-
}
37-
bool hasValue() const {
38-
return m_hasValue;
39-
}
40-
T value() const{
41-
return m_Value;
42-
}
43-
};
44-
4524
bool setDateTimeFormat(const QString &format);
4625
bool setDateTimeFormat(const Qt::DateFormat &format);
4726

@@ -264,6 +243,37 @@ bool fromJsonValue(QMap<QString, T> &val, const QJsonValue &jval) {
264243
return ok;
265244
}
266245

246+
template <typename T>
247+
class OptionalParam {
248+
public:
249+
T m_Value;
250+
bool m_isNull = false;
251+
bool m_hasValue;
252+
public:
253+
OptionalParam(){
254+
m_hasValue = false;
255+
}
256+
OptionalParam(const T &val, bool isNull = false){
257+
m_hasValue = true;
258+
m_Value = val;
259+
m_isNull = isNull;
260+
}
261+
bool hasValue() const {
262+
return m_hasValue;
263+
}
264+
T value() const{
265+
return m_Value;
266+
}
267+
268+
QString stringValue() const {
269+
if (m_isNull) {
270+
return QStringLiteral("");
271+
} else {
272+
return toStringValue(value());
273+
}
274+
}
275+
};
276+
267277
{{#cppNamespaceDeclarations}}
268278
} // namespace {{this}}
269279
{{/cppNamespaceDeclarations}}

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

+31-21
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,6 @@
2929

3030
namespace test_namespace {
3131

32-
template <typename T>
33-
class OptionalParam {
34-
public:
35-
T m_Value;
36-
bool m_hasValue;
37-
public:
38-
OptionalParam(){
39-
m_hasValue = false;
40-
}
41-
OptionalParam(const T &val){
42-
m_hasValue = true;
43-
m_Value = val;
44-
}
45-
bool hasValue() const {
46-
return m_hasValue;
47-
}
48-
T value() const{
49-
return m_Value;
50-
}
51-
};
52-
5332
bool setDateTimeFormat(const QString &format);
5433
bool setDateTimeFormat(const Qt::DateFormat &format);
5534

@@ -272,6 +251,37 @@ bool fromJsonValue(QMap<QString, T> &val, const QJsonValue &jval) {
272251
return ok;
273252
}
274253

254+
template <typename T>
255+
class OptionalParam {
256+
public:
257+
T m_Value;
258+
bool m_isNull = false;
259+
bool m_hasValue;
260+
public:
261+
OptionalParam(){
262+
m_hasValue = false;
263+
}
264+
OptionalParam(const T &val, bool isNull = false){
265+
m_hasValue = true;
266+
m_Value = val;
267+
m_isNull = isNull;
268+
}
269+
bool hasValue() const {
270+
return m_hasValue;
271+
}
272+
T value() const{
273+
return m_Value;
274+
}
275+
276+
QString stringValue() const {
277+
if (m_isNull) {
278+
return QStringLiteral("");
279+
} else {
280+
return toStringValue(value());
281+
}
282+
}
283+
};
284+
275285
} // namespace test_namespace
276286

277287
#endif // PFX_HELPERS_H

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ void PFXUserApi::loginUser(const QString &username, const QString &password) {
655655
else
656656
fullPath.append("?");
657657

658-
fullPath.append(QUrl::toPercentEncoding("username")).append(querySuffix).append(QUrl::toPercentEncoding(::test_namespace::toStringValue(username)));
658+
fullPath.append(QUrl::toPercentEncoding("username")).append(querySuffix).append(QUrl::toPercentEncoding(username));
659659
}
660660

661661
{
@@ -670,7 +670,7 @@ void PFXUserApi::loginUser(const QString &username, const QString &password) {
670670
else
671671
fullPath.append("?");
672672

673-
fullPath.append(QUrl::toPercentEncoding("password")).append(querySuffix).append(QUrl::toPercentEncoding(::test_namespace::toStringValue(password)));
673+
fullPath.append(QUrl::toPercentEncoding("password")).append(querySuffix).append(QUrl::toPercentEncoding(password));
674674
}
675675
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager);
676676
worker->setTimeOut(_timeOut);

0 commit comments

Comments
 (0)