Skip to content

Commit

Permalink
Handle NPE error message
Browse files Browse the repository at this point in the history
  • Loading branch information
micryc committed Apr 30, 2024
1 parent c7df705 commit 665c466
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions src/main/java/io/swagger/codegen/v3/generators/SchemaHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,25 +189,31 @@ protected void addInterfaces(List<Schema> schemas, CodegenModel codegenModel, Ma
final String schemaName = ref.substring(ref.lastIndexOf("/") + 1);

final CodegenModel model = allModels.get(codegenConfig.toModelName(schemaName));
this.addInterfaceModel(model, codegenModel);

boolean subTypeAdded = false;
if (codegenModel.getSubTypes() != null) {
subTypeAdded = codegenModel.getSubTypes().stream().anyMatch(existingSubType -> existingSubType.classname.equalsIgnoreCase(model.classname));
}
if (!subTypeAdded) {
codegenModel.addSubType(model);
}


if (codegenModel.getDiscriminator() != null && StringUtils.isNotBlank(codegenModel.getDiscriminator().getPropertyName())) {
Optional<CodegenProperty> optionalProperty = model.vars.stream()
.filter(codegenProperty -> codegenProperty.baseName.equals(codegenModel.getDiscriminator().getPropertyName())).findFirst();

optionalProperty.ifPresent(codegenProperty -> {
codegenModel.getVendorExtensions().put("x-discriminator-type", codegenProperty.datatypeWithEnum);
codegenModel.getVendorExtensions().put("x-discriminator-type-getter", codegenConfig.toGetter(codegenModel.getDiscriminator().getPropertyName()));
});
if (model != null) {
{
this.addInterfaceModel(model, codegenModel);

boolean subTypeAdded = false;
if (codegenModel.getSubTypes() != null) {
subTypeAdded = codegenModel.getSubTypes().stream().anyMatch(existingSubType -> existingSubType.classname.equalsIgnoreCase(model.classname));
}
if (!subTypeAdded) {
codegenModel.addSubType(model);
}


if (codegenModel.getDiscriminator() != null && StringUtils.isNotBlank(codegenModel.getDiscriminator().getPropertyName())) {
Optional<CodegenProperty> optionalProperty = model.vars.stream()
.filter(codegenProperty -> codegenProperty.baseName.equals(codegenModel.getDiscriminator().getPropertyName())).findFirst();

optionalProperty.ifPresent(codegenProperty -> {
codegenModel.getVendorExtensions().put("x-discriminator-type", codegenProperty.datatypeWithEnum);
codegenModel.getVendorExtensions().put("x-discriminator-type-getter", codegenConfig.toGetter(codegenModel.getDiscriminator().getPropertyName()));
});
}
}
}else {
throw new NullPointerException("Could not find model for reference: " + ref);
}
}
}
Expand Down

0 comments on commit 665c466

Please sign in to comment.