Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ QString {{classname}}::asJson() const {

QJson{{^isEnum}}Object{{/isEnum}}{{#isEnum}}Value{{/isEnum}} {{classname}}::asJson{{^isEnum}}Object{{/isEnum}}{{#isEnum}}Value{{/isEnum}}() const {
{{^isEnum}}QJsonObject obj;{{#vars}}{{^isContainer}}{{#complexType}}
if (m_{{name}}.isSet()){{/complexType}}{{^complexType}}
if (m_{{name}}_isSet){{/complexType}} {
if (true{{^required}} && m_{{name}}.isSet(){{/required}}){{/complexType}}{{^complexType}}
if (true{{^required}} && m_{{name}}_isSet{{/required}}){{/complexType}} {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: Required primitive fields may serialize uninitialized/indeterminate values after this change

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/main/resources/cpp-qt-client/model-body.mustache, line 104:

<comment>Required primitive fields may serialize uninitialized/indeterminate values after this change</comment>

<file context>
@@ -100,11 +100,11 @@ QString {{classname}}::asJson() const {
-    if (m_{{name}}.isSet()){{/complexType}}{{^complexType}}
-    if (m_{{name}}_isSet){{/complexType}} {
+    if (true{{^required}} && m_{{name}}.isSet(){{/required}}){{/complexType}}{{^complexType}}
+    if (true{{^required}} && m_{{name}}_isSet{{/required}}){{/complexType}} {
         obj.insert(QString("{{baseName}}"), ::{{cppNamespace}}::toJsonValue(m_{{name}}));
     }{{/isContainer}}{{#isContainer}}
</file context>

obj.insert(QString("{{baseName}}"), ::{{cppNamespace}}::toJsonValue(m_{{name}}));
}{{/isContainer}}{{#isContainer}}
if (m_{{name}}.size() > 0) {
if (true{{^required}} && m_{{name}}.size() > 0{{/required}}) {
{{^items.isContainer}}obj.insert(QString("{{baseName}}"), ::{{cppNamespace}}::toJsonValue(m_{{name}}));{{/items.isContainer}}{{#items.isContainer}}
obj.insert(QString("{{baseName}}"), toJsonValue(m_{{name}}));{{/items.isContainer}}
}{{/isContainer}}{{/vars}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ QString PFXApiResponse::asJson() const {

QJsonObject PFXApiResponse::asJsonObject() const {
QJsonObject obj;
if (m_code_isSet) {
if (true && m_code_isSet) {
obj.insert(QString("code"), ::test_namespace::toJsonValue(m_code));
}
if (m_type_isSet) {
if (true && m_type_isSet) {
obj.insert(QString("type"), ::test_namespace::toJsonValue(m_type));
}
if (m_message_isSet) {
if (true && m_message_isSet) {
obj.insert(QString("message"), ::test_namespace::toJsonValue(m_message));
}
return obj;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ QString PFXCategory::asJson() const {

QJsonObject PFXCategory::asJsonObject() const {
QJsonObject obj;
if (m_id_isSet) {
if (true && m_id_isSet) {
obj.insert(QString("id"), ::test_namespace::toJsonValue(m_id));
}
if (m_name_isSet) {
if (true && m_name_isSet) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: Required name is still guarded by m_name_isSet, so toJsonObject() can omit a schema-required field; true && is a no-op and does not implement the required-member serialization fix.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXCategory.cpp, line 71:

<comment>Required `name` is still guarded by `m_name_isSet`, so `toJsonObject()` can omit a schema-required field; `true &&` is a no-op and does not implement the required-member serialization fix.</comment>

<file context>
@@ -65,10 +65,10 @@ QString PFXCategory::asJson() const {
         obj.insert(QString("id"), ::test_namespace::toJsonValue(m_id));
     }
-    if (m_name_isSet) {
+    if (true && m_name_isSet) {
         obj.insert(QString("name"), ::test_namespace::toJsonValue(m_name));
     }
</file context>

Copy link
Copy Markdown
Author

@TheZlodziej TheZlodziej May 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true && ... convention is just to simplify the mustache template. The compiler will omit this check anyway since it always evaluates to true. In the Category yaml, 'name' is not a required member

 Category:
      title: Pet category
      description: A category for a pet
      type: object
      properties:
        id:
          type: integer
          format: int64
        name:
          type: string
      xml:
        name: Category

and this the check true && m_name_isSet is correct (you can safely omit this variable according to the schema)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TheZlodziej can we avoid the true && with the following instead?

``
{{#required}}
...
{{/required}}
{{^required}}
...
{{/required}}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback! I've saved this as a new learning to improve future reviews.

obj.insert(QString("name"), ::test_namespace::toJsonValue(m_name));
}
return obj;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,22 +89,22 @@ QString PFXOrder::asJson() const {

QJsonObject PFXOrder::asJsonObject() const {
QJsonObject obj;
if (m_id_isSet) {
if (true && m_id_isSet) {
obj.insert(QString("id"), ::test_namespace::toJsonValue(m_id));
}
if (m_pet_id_isSet) {
if (true && m_pet_id_isSet) {
obj.insert(QString("petId"), ::test_namespace::toJsonValue(m_pet_id));
}
if (m_quantity_isSet) {
if (true && m_quantity_isSet) {
obj.insert(QString("quantity"), ::test_namespace::toJsonValue(m_quantity));
}
if (m_ship_date_isSet) {
if (true && m_ship_date_isSet) {
obj.insert(QString("shipDate"), ::test_namespace::toJsonValue(m_ship_date));
}
if (m_status_isSet) {
if (true && m_status_isSet) {
obj.insert(QString("status"), ::test_namespace::toJsonValue(m_status));
}
if (m_complete_isSet) {
if (true && m_complete_isSet) {
obj.insert(QString("complete"), ::test_namespace::toJsonValue(m_complete));
}
return obj;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,22 +89,22 @@ QString PFXPet::asJson() const {

QJsonObject PFXPet::asJsonObject() const {
QJsonObject obj;
if (m_id_isSet) {
if (true && m_id_isSet) {
obj.insert(QString("id"), ::test_namespace::toJsonValue(m_id));
}
if (m_category.isSet()) {
if (true && m_category.isSet()) {
obj.insert(QString("category"), ::test_namespace::toJsonValue(m_category));
}
if (m_name_isSet) {
if (true) {
obj.insert(QString("name"), ::test_namespace::toJsonValue(m_name));
}
if (m_photo_urls.size() > 0) {
if (true) {
obj.insert(QString("photoUrls"), ::test_namespace::toJsonValue(m_photo_urls));
}
if (m_tags.size() > 0) {
if (true && m_tags.size() > 0) {
obj.insert(QString("tags"), ::test_namespace::toJsonValue(m_tags));
}
if (m_status_isSet) {
if (true && m_status_isSet) {
obj.insert(QString("status"), ::test_namespace::toJsonValue(m_status));
}
return obj;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ QString PFXTag::asJson() const {

QJsonObject PFXTag::asJsonObject() const {
QJsonObject obj;
if (m_id_isSet) {
if (true && m_id_isSet) {
obj.insert(QString("id"), ::test_namespace::toJsonValue(m_id));
}
if (m_name_isSet) {
if (true && m_name_isSet) {
obj.insert(QString("name"), ::test_namespace::toJsonValue(m_name));
}
return obj;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ QString PFXTestAnyType::asJson() const {

QJsonObject PFXTestAnyType::asJsonObject() const {
QJsonObject obj;
if (m_code_isSet) {
if (true && m_code_isSet) {
obj.insert(QString("code"), ::test_namespace::toJsonValue(m_code));
}
if (m_message_isSet) {
if (true && m_message_isSet) {
obj.insert(QString("message"), ::test_namespace::toJsonValue(m_message));
}
return obj;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,28 +101,28 @@ QString PFXUser::asJson() const {

QJsonObject PFXUser::asJsonObject() const {
QJsonObject obj;
if (m_id_isSet) {
if (true && m_id_isSet) {
obj.insert(QString("id"), ::test_namespace::toJsonValue(m_id));
}
if (m_username_isSet) {
if (true && m_username_isSet) {
obj.insert(QString("username"), ::test_namespace::toJsonValue(m_username));
}
if (m_first_name_isSet) {
if (true && m_first_name_isSet) {
obj.insert(QString("firstName"), ::test_namespace::toJsonValue(m_first_name));
}
if (m_last_name_isSet) {
if (true && m_last_name_isSet) {
obj.insert(QString("lastName"), ::test_namespace::toJsonValue(m_last_name));
}
if (m_email_isSet) {
if (true && m_email_isSet) {
obj.insert(QString("email"), ::test_namespace::toJsonValue(m_email));
}
if (m_password_isSet) {
if (true && m_password_isSet) {
obj.insert(QString("password"), ::test_namespace::toJsonValue(m_password));
}
if (m_phone_isSet) {
if (true && m_phone_isSet) {
obj.insert(QString("phone"), ::test_namespace::toJsonValue(m_phone));
}
if (m_user_status_isSet) {
if (true && m_user_status_isSet) {
obj.insert(QString("userStatus"), ::test_namespace::toJsonValue(m_user_status));
}
return obj;
Expand Down
6 changes: 3 additions & 3 deletions samples/client/petstore/cpp-qt/client/PFXApiResponse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ QString PFXApiResponse::asJson() const {

QJsonObject PFXApiResponse::asJsonObject() const {
QJsonObject obj;
if (m_code_isSet) {
if (true && m_code_isSet) {
obj.insert(QString("code"), ::test_namespace::toJsonValue(m_code));
}
if (m_type_isSet) {
if (true && m_type_isSet) {
obj.insert(QString("type"), ::test_namespace::toJsonValue(m_type));
}
if (m_message_isSet) {
if (true && m_message_isSet) {
obj.insert(QString("message"), ::test_namespace::toJsonValue(m_message));
}
return obj;
Expand Down
4 changes: 2 additions & 2 deletions samples/client/petstore/cpp-qt/client/PFXCategory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ QString PFXCategory::asJson() const {

QJsonObject PFXCategory::asJsonObject() const {
QJsonObject obj;
if (m_id_isSet) {
if (true && m_id_isSet) {
obj.insert(QString("id"), ::test_namespace::toJsonValue(m_id));
}
if (m_name_isSet) {
if (true && m_name_isSet) {
obj.insert(QString("name"), ::test_namespace::toJsonValue(m_name));
}
return obj;
Expand Down
12 changes: 6 additions & 6 deletions samples/client/petstore/cpp-qt/client/PFXOrder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,22 +89,22 @@ QString PFXOrder::asJson() const {

QJsonObject PFXOrder::asJsonObject() const {
QJsonObject obj;
if (m_id_isSet) {
if (true && m_id_isSet) {
obj.insert(QString("id"), ::test_namespace::toJsonValue(m_id));
}
if (m_pet_id_isSet) {
if (true && m_pet_id_isSet) {
obj.insert(QString("petId"), ::test_namespace::toJsonValue(m_pet_id));
}
if (m_quantity_isSet) {
if (true && m_quantity_isSet) {
obj.insert(QString("quantity"), ::test_namespace::toJsonValue(m_quantity));
}
if (m_ship_date_isSet) {
if (true && m_ship_date_isSet) {
obj.insert(QString("shipDate"), ::test_namespace::toJsonValue(m_ship_date));
}
if (m_status_isSet) {
if (true && m_status_isSet) {
obj.insert(QString("status"), ::test_namespace::toJsonValue(m_status));
}
if (m_complete_isSet) {
if (true && m_complete_isSet) {
obj.insert(QString("complete"), ::test_namespace::toJsonValue(m_complete));
}
return obj;
Expand Down
12 changes: 6 additions & 6 deletions samples/client/petstore/cpp-qt/client/PFXPet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,22 +89,22 @@ QString PFXPet::asJson() const {

QJsonObject PFXPet::asJsonObject() const {
QJsonObject obj;
if (m_id_isSet) {
if (true && m_id_isSet) {
obj.insert(QString("id"), ::test_namespace::toJsonValue(m_id));
}
if (m_category.isSet()) {
if (true && m_category.isSet()) {
obj.insert(QString("category"), ::test_namespace::toJsonValue(m_category));
}
if (m_name_isSet) {
if (true) {
obj.insert(QString("name"), ::test_namespace::toJsonValue(m_name));
}
if (m_photo_urls.size() > 0) {
if (true) {
obj.insert(QString("photoUrls"), ::test_namespace::toJsonValue(m_photo_urls));
}
if (m_tags.size() > 0) {
if (true && m_tags.size() > 0) {
obj.insert(QString("tags"), ::test_namespace::toJsonValue(m_tags));
}
if (m_status_isSet) {
if (true && m_status_isSet) {
obj.insert(QString("status"), ::test_namespace::toJsonValue(m_status));
}
return obj;
Expand Down
4 changes: 2 additions & 2 deletions samples/client/petstore/cpp-qt/client/PFXTag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ QString PFXTag::asJson() const {

QJsonObject PFXTag::asJsonObject() const {
QJsonObject obj;
if (m_id_isSet) {
if (true && m_id_isSet) {
obj.insert(QString("id"), ::test_namespace::toJsonValue(m_id));
}
if (m_name_isSet) {
if (true && m_name_isSet) {
obj.insert(QString("name"), ::test_namespace::toJsonValue(m_name));
}
return obj;
Expand Down
4 changes: 2 additions & 2 deletions samples/client/petstore/cpp-qt/client/PFXTestAnyType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ QString PFXTestAnyType::asJson() const {

QJsonObject PFXTestAnyType::asJsonObject() const {
QJsonObject obj;
if (m_code_isSet) {
if (true && m_code_isSet) {
obj.insert(QString("code"), ::test_namespace::toJsonValue(m_code));
}
if (m_message_isSet) {
if (true && m_message_isSet) {
obj.insert(QString("message"), ::test_namespace::toJsonValue(m_message));
}
return obj;
Expand Down
16 changes: 8 additions & 8 deletions samples/client/petstore/cpp-qt/client/PFXUser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,28 +101,28 @@ QString PFXUser::asJson() const {

QJsonObject PFXUser::asJsonObject() const {
QJsonObject obj;
if (m_id_isSet) {
if (true && m_id_isSet) {
obj.insert(QString("id"), ::test_namespace::toJsonValue(m_id));
}
if (m_username_isSet) {
if (true && m_username_isSet) {
obj.insert(QString("username"), ::test_namespace::toJsonValue(m_username));
}
if (m_first_name_isSet) {
if (true && m_first_name_isSet) {
obj.insert(QString("firstName"), ::test_namespace::toJsonValue(m_first_name));
}
if (m_last_name_isSet) {
if (true && m_last_name_isSet) {
obj.insert(QString("lastName"), ::test_namespace::toJsonValue(m_last_name));
}
if (m_email_isSet) {
if (true && m_email_isSet) {
obj.insert(QString("email"), ::test_namespace::toJsonValue(m_email));
}
if (m_password_isSet) {
if (true && m_password_isSet) {
obj.insert(QString("password"), ::test_namespace::toJsonValue(m_password));
}
if (m_phone_isSet) {
if (true && m_phone_isSet) {
obj.insert(QString("phone"), ::test_namespace::toJsonValue(m_phone));
}
if (m_user_status_isSet) {
if (true && m_user_status_isSet) {
obj.insert(QString("userStatus"), ::test_namespace::toJsonValue(m_user_status));
}
return obj;
Expand Down