Skip to content

Commit

Permalink
[cpp-qt-client]Allow nullable parameters (OpenAPITools#17805)
Browse files Browse the repository at this point in the history
* [cpp-qt-client]Allow nullable parameters

Fixes OpenAPITools#17756

* Update samples
  • Loading branch information
martonmiklos authored and kota65535 committed Feb 23, 2024
1 parent 809647f commit ac7c15e
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ void {{classname}}::{{nickname}}({{#allParams}}{{#required}}const {{{dataType}}}
}
fullPath.append(paramString);
{{/isPrimitiveType}}{{#isPrimitiveType}}
fullPath.append(QUrl::toPercentEncoding("{{baseName}}")).append(querySuffix).append(QUrl::toPercentEncoding(::{{cppNamespace}}::toStringValue({{paramName}}{{^required}}.value(){{/required}})));
fullPath.append(QUrl::toPercentEncoding("{{baseName}}")).append(querySuffix).append(QUrl::toPercentEncoding({{paramName}}{{^required}}.stringValue(){{/required}}));
{{/isPrimitiveType}}
{{/collectionFormat}}
{{#collectionFormat}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,6 @@
namespace {{this}} {
{{/cppNamespaceDeclarations}}

template <typename T>
class OptionalParam {
public:
T m_Value;
bool m_hasValue;
public:
OptionalParam(){
m_hasValue = false;
}
OptionalParam(const T &val){
m_hasValue = true;
m_Value = val;
}
bool hasValue() const {
return m_hasValue;
}
T value() const{
return m_Value;
}
};

bool setDateTimeFormat(const QString &format);
bool setDateTimeFormat(const Qt::DateFormat &format);

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

template <typename T>
class OptionalParam {
public:
T m_Value;
bool m_isNull = false;
bool m_hasValue;
public:
OptionalParam(){
m_hasValue = false;
}
OptionalParam(const T &val, bool isNull = false){
m_hasValue = true;
m_Value = val;
m_isNull = isNull;
}
bool hasValue() const {
return m_hasValue;
}
T value() const{
return m_Value;
}

QString stringValue() const {
if (m_isNull) {
return QStringLiteral("");
} else {
return toStringValue(value());
}
}
};

{{#cppNamespaceDeclarations}}
} // namespace {{this}}
{{/cppNamespaceDeclarations}}
Expand Down
52 changes: 31 additions & 21 deletions samples/client/petstore/cpp-qt/client/PFXHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,6 @@

namespace test_namespace {

template <typename T>
class OptionalParam {
public:
T m_Value;
bool m_hasValue;
public:
OptionalParam(){
m_hasValue = false;
}
OptionalParam(const T &val){
m_hasValue = true;
m_Value = val;
}
bool hasValue() const {
return m_hasValue;
}
T value() const{
return m_Value;
}
};

bool setDateTimeFormat(const QString &format);
bool setDateTimeFormat(const Qt::DateFormat &format);

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

template <typename T>
class OptionalParam {
public:
T m_Value;
bool m_isNull = false;
bool m_hasValue;
public:
OptionalParam(){
m_hasValue = false;
}
OptionalParam(const T &val, bool isNull = false){
m_hasValue = true;
m_Value = val;
m_isNull = isNull;
}
bool hasValue() const {
return m_hasValue;
}
T value() const{
return m_Value;
}

QString stringValue() const {
if (m_isNull) {
return QStringLiteral("");
} else {
return toStringValue(value());
}
}
};

} // namespace test_namespace

#endif // PFX_HELPERS_H
4 changes: 2 additions & 2 deletions samples/client/petstore/cpp-qt/client/PFXUserApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ void PFXUserApi::loginUser(const QString &username, const QString &password) {
else
fullPath.append("?");

fullPath.append(QUrl::toPercentEncoding("username")).append(querySuffix).append(QUrl::toPercentEncoding(::test_namespace::toStringValue(username)));
fullPath.append(QUrl::toPercentEncoding("username")).append(querySuffix).append(QUrl::toPercentEncoding(username));
}

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

fullPath.append(QUrl::toPercentEncoding("password")).append(querySuffix).append(QUrl::toPercentEncoding(::test_namespace::toStringValue(password)));
fullPath.append(QUrl::toPercentEncoding("password")).append(querySuffix).append(QUrl::toPercentEncoding(password));
}
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut);
Expand Down

0 comments on commit ac7c15e

Please sign in to comment.