Skip to content

fix(cpp-qt-client): #23702 - required members are always present in output of toJsonObject#23703

Open
TheZlodziej wants to merge 1 commit intoOpenAPITools:masterfrom
TheZlodziej:master
Open

fix(cpp-qt-client): #23702 - required members are always present in output of toJsonObject#23703
TheZlodziej wants to merge 1 commit intoOpenAPITools:masterfrom
TheZlodziej:master

Conversation

@TheZlodziej
Copy link
Copy Markdown

@TheZlodziej TheZlodziej commented May 6, 2026

fixes issue mentioned in #23702
the toJsonObject should always contain required variables (even if they are not set)


Summary by cubic

Ensure the cpp-qt-client generator always includes required model fields in JSON output, even when unset. Fixes #23702 to prevent missing required keys in serialized payloads.

  • Bug Fixes
    • Updated model-body.mustache to always insert required fields in asJsonObject (removes isSet/size()>0 guards for required properties).
    • Optional fields keep existing guards to avoid emitting unset optionals.

Written for commit 9b2a954. Summary will update on new commits.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 1 file

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="modules/openapi-generator/src/main/resources/cpp-qt-client/model-body.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/cpp-qt-client/model-body.mustache:104">
P1: Required primitive fields may serialize uninitialized/indeterminate values after this change</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

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>

@wing328
Copy link
Copy Markdown
Member

wing328 commented May 6, 2026

please follow step 3 to update the samples so as to fix https://github.com/OpenAPITools/openapi-generator/actions/runs/25431058267/job/74599299188?pr=23703

cc @ravinikam (2017/07) @stkrwork (2017/07) @etherealjoy (2018/02) @MartinDelille (2018/03) @muttleyxd (2019/08) @aminya (2025/05)

@wing328 wing328 added this to the 7.23.0 milestone May 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG][cpp-qt-client] Required array member is not outputted to JSON

2 participants