Anonymous class with syntax error
Closed this issue ยท 4 comments
It generates an annonimous class with syntax error, if the payload is defined as such;
payload:
description: bla bla
type: object
the created annonimous class is;
import jakarta.validation.constraints.*;
import jakarta.validation.Valid;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonValue;
import javax.annotation.processing.Generated;
import java.util.List;
import java.util.Objects;
@Generated(value="com.asyncapi.generator.template.spring", date="2023-10-11T07:43:58.414Z")
public class AnonymousSchema9 {
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
AnonymousSchema9 anonymousSchema9 = (AnonymousSchema9) o;
return
}
@Override
public int hashCode() {
return Objects.hash();
}
@Override
public String toString() {
return "class AnonymousSchema9 {\n" +
"}";
}
/**
* Convert the given object to string with each line indented by 4 spaces (except the first line).
*/
private String toIndentedString(Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}
}
AnonymousSchema9 anonymousSchema9 = (AnonymousSchema9) o;
return
Welcome to AsyncAPI. Thanks a lot for reporting your first issue. Please check out our contributors guide and the instructions about a basic recommended setup useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.
Hello @khalender
This looks a bit odd.
According to template code this line is hardcoded as follows:
Could you please try to repeat generation?
The issue is;
If you define an object in the component which does not refer to a model definition such as;
ObjectX:
type: object
properties:
propY:
type: object
In this case, the generator generates an AnonymousSchemaZ for propY which is not defined as a seperate model.This is the exact model class that is generated for propY.
@Generated(value="com.asyncapi.generator.template.spring", date="2023-10-23T07:22:27.496Z")
public class AnonymousSchema24 {
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
AnonymousSchema24 anonymousSchema24 = (AnonymousSchema24) o;
return
}
@Override
public int hashCode() {
return Objects.hash();
}
@Override
public String toString() {
return "class AnonymousSchema24 {\n" +
"}";
}
/**
* Convert the given object to string with each line indented by 4 spaces (except the first line).
*/
private String toIndentedString(Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}
}
AnonymousSchema24 anonymousSchema24 = (AnonymousSchema24) o; return
The issue here is there is no props in this class. That s why this fails..
return Objects.equals(this.payload, event.payload);
As a solution.. if there is no prop defined for an object, maybe just do not create a class instead assign Object type to that prop.
public class ObjectX {
private @Valid AnonymousSchema24 propY;
...
instead
public class ObjectX {
private @Valid Object propY;
๐ This issue has been resolved in version 1.5.1 ๐
The release is available on:
Your semantic-release bot ๐ฆ๐