diff --git a/packages/quicktype-core/src/language/CPlusPlus/CPlusPlusRenderer.ts b/packages/quicktype-core/src/language/CPlusPlus/CPlusPlusRenderer.ts index 4b70339f2..de41ae263 100644 --- a/packages/quicktype-core/src/language/CPlusPlus/CPlusPlusRenderer.ts +++ b/packages/quicktype-core/src/language/CPlusPlus/CPlusPlusRenderer.ts @@ -926,23 +926,27 @@ export class CPlusPlusRenderer extends ConvenienceRenderer { }, true, false, - property.isOptional + // Since we're only generating this to compare types, whether its optional doesn't matter - we just + // need cppType() to spit out the actual underlying type, without wrapping it in the optional<> + // container. + false ); + // Check the minMax values for truthiness or if they're equal to zero, as zero is a valid value too res.set(jsonName, [ this.constraintMember(jsonName), "(", - minMax?.[0] && cppType === "int64_t" ? String(minMax[0]) : this._nulloptType, + (minMax?.[0] || minMax?.[0] === 0) && cppType === "int64_t" ? String(minMax[0]) : this._nulloptType, ", ", - minMax?.[1] && cppType === "int64_t" ? String(minMax[1]) : this._nulloptType, + (minMax?.[1] || minMax?.[1] === 0) && cppType === "int64_t" ? String(minMax[1]) : this._nulloptType, ", ", - minMax?.[0] && cppType === "double" ? String(minMax[0]) : this._nulloptType, + (minMax?.[0] || minMax?.[0] === 0) && cppType === "double" ? String(minMax[0]) : this._nulloptType, ", ", - minMax?.[1] && cppType === "double" ? String(minMax[1]) : this._nulloptType, + (minMax?.[1] || minMax?.[1] === 0) && cppType === "double" ? String(minMax[1]) : this._nulloptType, ", ", - minMaxLength?.[0] ? String(minMaxLength[0]) : this._nulloptType, + minMaxLength?.[0] || minMaxLength?.[0] === 0 ? String(minMaxLength[0]) : this._nulloptType, ", ", - minMaxLength?.[1] ? String(minMaxLength[1]) : this._nulloptType, + minMaxLength?.[1] || minMaxLength?.[1] === 0 ? String(minMaxLength[1]) : this._nulloptType, ", ", pattern === undefined ? this._nulloptType