java-spring-template icon indicating copy to clipboard operation
java-spring-template copied to clipboard

AsyncAPI Gernerator skips to generate java code for spec part containing "allOf"-element

Open taotao100 opened this issue 2 years ago • 5 comments

Describe the bug

AsyncAPI Gernerator skips to generate java code for spec part containing "allOf"-element

How to Reproduce

using the following sample spec to generate java classes

asyncapi: 2.6.0
info:
  title: Hello world application
  version: "0.1.0"
channels:
  hello:
    publish:
      message:
        payload:
          $ref: "#/components/schemas/type1"

components:
  messages:
    myMessage:
      name: myTestMessage
      payload:
        $ref: "#/components/schemas/type1"
      headers:
        allOf:
          - $ref: "#/components/schemas/type1"
          - $ref: "#/components/schemas/type2"
  schemas:
    type1:
      type: string
    type2:
      type: string

code generation through cli asyncapi generate fromTemplate ./test-sample.yaml @asyncapi/java-spring-template -p javaPackage=Exporter.models --output allofTest The java class does not contain expected 'Headers'-element see java code below

package Exporter.models.model;

import javax.validation.Valid;

import java.util.Objects;
import java.util.List;


public class MyTestMessage {
    private @Valid Type1 payload;

    public Type1 getPayload() {
        return payload;
    }

    public void setPayload(Type1 payload) {
        this.payload = payload;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        MyTestMessage event = (MyTestMessage) o;
        return Objects.equals(this.payload, event.payload);
    }

    @Override
    public int hashCode() {
        return Objects.hash(payload);
    }

    @Override
    public String toString() {
        return "class MyTestMessage {\n" +
                "    payload: " + toIndentedString(payload) + "\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    ");
    }
}

Expected behavior

Java Class contains the headers-part in spec above

taotao100 avatar Aug 18 '23 11:08 taotao100

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.

github-actions[bot] avatar Aug 18 '23 11:08 github-actions[bot]

moving to java template repo. Generator do not influence the generation result, it only provides a set of tools and API to enable java template to define what should be generated

derberg avatar Sep 04 '23 14:09 derberg

Hello @taotao100 You are right, the problem is with header section, current template doesn't support them. I'm sorry, that i didn't mentioned it in readme. The problem that headers is a bit protocol-broker specific and so template still doesn't have a proper implementation for them. If you could share your case, e.g. which protocol, broker and headers you are interested in, I would be glad to discuss details and update template.

Tenischev avatar Sep 04 '23 19:09 Tenischev

Hi @Tenischev,

thanks for the response, we are working on use AsyncApi to specify the messages (payload & headers) in Kafka.

taotao100 avatar Oct 05 '23 13:10 taotao100

This issue has been automatically marked as stale because it has not had recent activity :sleeping:

It will be closed in 120 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.

There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.

Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here.

Thank you for your patience :heart:

github-actions[bot] avatar Feb 03 '24 00:02 github-actions[bot]