asyncapi / java-spring-template

Java Spring template for the AsyncAPI Generator
Apache License 2.0
68 stars 55 forks source link

[BUG] Payload don't generated with avro schema #419

Open leonardotorresaltez opened 3 weeks ago

leonardotorresaltez commented 3 weeks ago

Describe the bug.

Hello, I tried to generate avro mapping java classes with spring template but in any way the generator is making json mapping java classes ( with @JsonProperty property ) .

asyncapi: '2.6.0'
info:
  title: Mercadona Kafka API
  version: 1.0.0
  description: |-
    Api acerca de las entidades en Mercadona.
  license:
    name: Apache 2.0
    url: https://www.apache.org/licenses/LICENSE-2.0

defaultContentType: 'application/vnd.apache.avro+json;version=1.9.0'

servers:
  production:
    url: broker:9092
    description: Kafka PRODUCTION cluster
    protocol: kafka

channels:
  mytopic:
    description: The topic.
    publish:
      summary: publish message.
      operationId: publishStoreassortmentvisibility
      message:
        schemaFormat: 'application/vnd.apache.avro;version=1.9.0'
        $ref: '#/components/messages/storeassortmentvisibility'
    subscribe:
      summary: receive message.
      operationId: receiveStoreassortmentvisibility
      message:
        schemaFormat: 'application/vnd.apache.avro;version=1.9.0'
        $ref: '#/components/messages/storeassortmentvisibility'
components:
  messages:
    storeassortmentvisibility:
      name: storeassortmentvisibility
      title: storeassortmentvisibility measured     
      schemaFormat: 'application/vnd.apache.avro;version=1.9.0'
      payload:
        type: record
        name: User
        namespace: com.company
        doc: User information
        fields:
          - name: displayName
            type: string
          - name: email
            type: string
          - name: age
            type: int

the command is :

 asyncapi generate fromTemplate asyncapi_demo_contract262.yml @asyncapi/java-spring-template@1.5.1 --output ./output_folder --force-write

the generated file is:

package com.asyncapi.model;

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.Map;
import java.util.Objects;

/**
 * User information
 */
@Generated(value="com.asyncapi.generator.template.spring", date="2024-10-27T11:32:20.876Z")
public class ComCompanyUser {

    private @Valid String displayName;

    private @Valid String email;

    private @Valid int age;

    @JsonProperty("displayName")@NotNull
    public String getDisplayName() {
        return displayName;
    }

    public void setDisplayName(String displayName) {
        this.displayName = displayName;
    }

    @JsonProperty("email")@NotNull
    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

 . . .

Expected behavior

Expected to see generated java avro mapping files , example :

@org.apache.avro.specific.AvroGenerated
public class User extends org.apache.avro.specific.SpecificRecordBase implements org.apache.avro.specific.SpecificRecord
. . .

Screenshots

none

How to Reproduce

  1. I first did this
  2. I then did this
  3. And so on . . .
    asyncapi generate fromTemplate asyncapi_demo_contract262.yml @asyncapi/java-spring-template@1.5.1 --output ./output_folder --force-write

🥦 Browser

Microsoft Edge

👀 Have you checked for similar open issues?

🏢 Have you read the Contributing Guidelines?

Are you willing to work on this issue ?

None

github-actions[bot] commented 3 weeks ago

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.

leonardotorresaltez commented 3 weeks ago

I already check the similar issue: https://github.com/asyncapi/java-spring-template/issues/78

From i can see the avro parser exist: https://github.com/asyncapi/avro-schema-parser?tab=readme-ov-file#usage-with-remote-references