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

Anonymous class with syntax error #336

Closed
khalender opened this issue Oct 11, 2023 · 4 comments · Fixed by #347
Closed

Anonymous class with syntax error #336

khalender opened this issue Oct 11, 2023 · 4 comments · Fixed by #347
Labels
bug Something isn't working released

Comments

@khalender
Copy link

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

@khalender khalender added the bug Something isn't working label Oct 11, 2023
@github-actions
Copy link

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.

@Tenischev
Copy link
Member

Tenischev commented Oct 11, 2023

Hello @khalender
This looks a bit odd.
According to template code this line is hardcoded as follows:

return Objects.equals(this.payload, event.payload);

Could you please try to repeat generation?

@khalender
Copy link
Author

khalender commented Oct 23, 2023

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;

@asyncapi-bot
Copy link
Contributor

🎉 This issue has been resolved in version 1.5.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants