Skip to content

Commit

Permalink
fix: dont render override when the setter doesnt exist in the interface
Browse files Browse the repository at this point in the history
  • Loading branch information
kennethaasan committed Sep 6, 2024
1 parent 0f3fb58 commit 0b929af
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
24 changes: 23 additions & 1 deletion src/generators/java/renderers/ClassRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<JavaOptions> = {
self({ renderer }) {
return renderer.defaultSelf();
Expand Down Expand Up @@ -240,7 +262,7 @@ export const JAVA_DEFAULT_CLASS_PRESET: ClassPresetType<JavaOptions> = {
}

// 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)
: '';

Expand Down
2 changes: 0 additions & 2 deletions test/generators/java/__snapshots__/JavaGenerator.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -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<String, Object> getAdditionalProperties() { return this.additionalProperties; }
Expand Down

0 comments on commit 0b929af

Please sign in to comment.