From 665c466bbc4633d5b13dbe872faf7adef6f1a320 Mon Sep 17 00:00:00 2001 From: MicRyc Date: Tue, 30 Apr 2024 10:43:57 +0200 Subject: [PATCH] Handle NPE error message --- .../codegen/v3/generators/SchemaHandler.java | 44 +++++++++++-------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/src/main/java/io/swagger/codegen/v3/generators/SchemaHandler.java b/src/main/java/io/swagger/codegen/v3/generators/SchemaHandler.java index 315f8151cd..629237fdf3 100644 --- a/src/main/java/io/swagger/codegen/v3/generators/SchemaHandler.java +++ b/src/main/java/io/swagger/codegen/v3/generators/SchemaHandler.java @@ -189,25 +189,31 @@ protected void addInterfaces(List 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 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 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); } } }