Skip to content

Commit 0e693cd

Browse files
authored
Fix NPE with cpp-restsdk client generator (#1477)
* fix_cpprest_npe * fix_code_format
1 parent 7f8ff35 commit 0e693cd

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,8 @@ public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> o
285285
Map<String, Object> operations = (Map<String, Object>) objs.get("operations");
286286
List<CodegenOperation> operationList = (List<CodegenOperation>) operations.get("operation");
287287
for (CodegenOperation op : operationList) {
288-
for(String hdr : op.imports) {
289-
if(importMapping.containsKey(hdr)) {
288+
for (String hdr : op.imports) {
289+
if (importMapping.containsKey(hdr)) {
290290
continue;
291291
}
292292
operations.put("hasModelImport", true);
@@ -295,7 +295,7 @@ public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> o
295295
}
296296
return objs;
297297
}
298-
298+
299299
protected boolean isFileSchema(CodegenProperty property) {
300300
return property.baseType.equals("HttpContent");
301301
}
@@ -411,7 +411,6 @@ public String getSchemaType(Schema p) {
411411

412412
@Override
413413
public Map<String, Object> postProcessAllModels(final Map<String, Object> models) {
414-
415414
final Map<String, Object> processed = super.postProcessAllModels(models);
416415
postProcessParentModels(models);
417416
return processed;
@@ -432,13 +431,18 @@ private void postProcessParentModels(final Map<String, Object> models) {
432431
*/
433432
private void processParentPropertiesInChildModel(final CodegenModel parent, final CodegenModel child) {
434433
final Map<String, CodegenProperty> childPropertiesByName = new HashMap<>(child.vars.size());
435-
for (final CodegenProperty childSchema : child.vars) {
436-
childPropertiesByName.put(childSchema.name, childSchema);
434+
if (child != null && child.vars != null && !child.vars.isEmpty()) {
435+
for (final CodegenProperty childSchema : child.vars) {
436+
childPropertiesByName.put(childSchema.name, childSchema);
437+
}
437438
}
438-
for (final CodegenProperty parentSchema : parent.vars) {
439-
final CodegenProperty duplicatedByParent = childPropertiesByName.get(parentSchema.name);
440-
if (duplicatedByParent != null) {
441-
duplicatedByParent.isInherited = true;
439+
440+
if (parent != null && parent.vars != null && !parent.vars.isEmpty()) {
441+
for (final CodegenProperty parentSchema : parent.vars) {
442+
final CodegenProperty duplicatedByParent = childPropertiesByName.get(parentSchema.name);
443+
if (duplicatedByParent != null) {
444+
duplicatedByParent.isInherited = true;
445+
}
442446
}
443447
}
444448
}

0 commit comments

Comments
 (0)