From 95d94d3ced337d2b014d972177b943b9ebdf8b5c Mon Sep 17 00:00:00 2001 From: Kenneth Aasan Date: Fri, 6 Sep 2024 14:00:15 +0200 Subject: [PATCH] fix!: dont render override when the setter doesnt exist in the interface (#2098) fix: dont render override when the setter doesnt exist in the interface --- .../java/renderers/ClassRenderer.ts | 24 ++++++++++++++++++- .../__snapshots__/JavaGenerator.spec.ts.snap | 2 -- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/generators/java/renderers/ClassRenderer.ts b/src/generators/java/renderers/ClassRenderer.ts index ab345fcd58..a619ab8fce 100644 --- a/src/generators/java/renderers/ClassRenderer.ts +++ b/src/generators/java/renderers/ClassRenderer.ts @@ -188,6 +188,28 @@ const isEnumImplementedByConstValue = ( }); }; +const isEnumOrEnumInExtended = ( + model: ConstrainedObjectModel, + property: ConstrainedObjectPropertyModel +): boolean => { + if (!isEnum(property)) { + return false; + } + + if (!model.options.extend) { + return false; + } + + return model.options.extend.some((extend) => { + return ( + extend instanceof ConstrainedReferenceModel && + extend.ref instanceof ConstrainedObjectModel && + extend.ref.properties[property.propertyName] && + isEnum(extend.ref.properties[property.propertyName]) + ); + }); +}; + export const JAVA_DEFAULT_CLASS_PRESET: ClassPresetType = { self({ renderer }) { return renderer.defaultSelf(); @@ -240,7 +262,7 @@ export const JAVA_DEFAULT_CLASS_PRESET: ClassPresetType = { } // don't render override for enums that are set with a const value - const override = !isEnumImplementedByConstValue(model, property) + const override = !isEnumOrEnumInExtended(model, property) ? getOverride(model, property) : ''; diff --git a/test/generators/java/__snapshots__/JavaGenerator.spec.ts.snap b/test/generators/java/__snapshots__/JavaGenerator.spec.ts.snap index d0c04f0606..f71c1d124b 100644 --- a/test/generators/java/__snapshots__/JavaGenerator.spec.ts.snap +++ b/test/generators/java/__snapshots__/JavaGenerator.spec.ts.snap @@ -41,7 +41,6 @@ public interface Pet { @Override public CloudEventDotSequenceType getSequenceType() { return this.sequenceType; } - @Override public void setSequenceType(CloudEventDotSequenceType sequenceType) { this.sequenceType = sequenceType; } public String getData() { return this.data; } @@ -277,7 +276,6 @@ public interface Pet { @Override public CloudEventDotSequenceType getSequenceType() { return this.sequenceType; } - @Override public void setSequenceType(CloudEventDotSequenceType sequenceType) { this.sequenceType = sequenceType; } public Map getAdditionalProperties() { return this.additionalProperties; }