Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: dont render override when the setter doesnt exist in the interface #2098

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading