Skip to content

Commit 4b65ccf

Browse files
committed
fix potential np3
1 parent 5c75519 commit 4b65ccf

3 files changed

Lines changed: 15 additions & 5 deletions

File tree

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppQtAbstractCodegen.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,9 @@ public String getTypeDeclaration(Schema p) {
209209
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
210210
} else if (ModelUtils.isMapSchema(resolved)) {
211211
Schema inner = ModelUtils.getAdditionalProperties(resolved);
212-
return getSchemaType(p) + "<QString, " + getTypeDeclaration(inner) + ">";
212+
// inner can be null if additionalProperties is a boolean or not present
213+
String innerType = inner != null ? getTypeDeclaration(inner) : PREFIX + "Object";
214+
return getSchemaType(p) + "<QString, " + innerType + ">";
213215
}
214216

215217
// For non-containers, use the original schema to preserve model names
@@ -250,7 +252,9 @@ public String toDefaultValue(Schema p) {
250252
return "0";
251253
} else if (ModelUtils.isMapSchema(schema)) {
252254
Schema inner = ModelUtils.getAdditionalProperties(schema);
253-
return "QMap<QString, " + getTypeDeclaration(inner) + ">()";
255+
// inner can be null if additionalProperties is a boolean or not present
256+
String innerType = inner != null ? getTypeDeclaration(inner) : PREFIX + "Object";
257+
return "QMap<QString, " + innerType + ">()";
254258
} else if (ModelUtils.isArraySchema(schema)) {
255259
Schema inner = ModelUtils.getSchemaItems(schema);
256260
return "QList<" + getTypeDeclaration(inner) + ">()";

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppRestSdkClientCodegen.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,9 @@ public String getTypeDeclaration(Schema p) {
418418
} else if (isPureMapSchema(resolved)) {
419419
// Only treat as map if it has additionalProperties but NO defined properties
420420
Schema inner = ModelUtils.getAdditionalProperties(resolved);
421-
return getSchemaType(p) + "<utility::string_t, " + getTypeDeclaration(inner) + ">";
421+
// inner can be null if additionalProperties is a boolean or not present
422+
String innerType = inner != null ? getTypeDeclaration(inner) : "std::shared_ptr<Object>";
423+
return getSchemaType(p) + "<utility::string_t, " + innerType + ">";
422424
}
423425

424426
// For non-containers, use the original schema to preserve model names
@@ -458,7 +460,9 @@ public String toDefaultValue(Schema p) {
458460
}
459461
return "0";
460462
} else if (isPureMapSchema(p)) {
461-
String inner = getSchemaType(ModelUtils.getAdditionalProperties(p));
463+
Schema innerSchema = ModelUtils.getAdditionalProperties(p);
464+
// innerSchema can be null if additionalProperties is a boolean or not present
465+
String inner = innerSchema != null ? getSchemaType(innerSchema) : "std::shared_ptr<Object>";
462466
return "std::map<utility::string_t, " + inner + ">()";
463467
} else if (ModelUtils.isArraySchema(p)) {
464468
String inner = getSchemaType(ModelUtils.getSchemaItems(p));

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppTinyClientCodegen.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,9 @@ public String getTypeDeclaration(Schema p) {
279279
// Handle nested maps: if a $ref resolves to a map schema, build the nested type
280280
if (ModelUtils.isMapSchema(resolved)) {
281281
Schema inner = ModelUtils.getAdditionalProperties(resolved);
282-
return getSchemaType(p) + "<std::string, " + getTypeDeclaration(inner) + ">";
282+
// inner can be null if additionalProperties is a boolean or not present
283+
String innerType = inner != null ? getTypeDeclaration(inner) : "std::string";
284+
return getSchemaType(p) + "<std::string, " + innerType + ">";
283285
}
284286

285287
// For everything else (including arrays), use the original behavior

0 commit comments

Comments
 (0)