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

[BUG] generator gives Generation failed with diffferent templatesinstalled ` #1361

Open
2 tasks done
hartmanjan1970 opened this issue Feb 12, 2025 · 2 comments
Open
2 tasks done
Labels
bug Something isn't working

Comments

@hartmanjan1970
Copy link

hartmanjan1970 commented Feb 12, 2025

Describe the bug.

I am trying to generate some code from the example asyncapi contract.
When generating is get constantly the same error Generator Error

Expected behavior

I would expect some java or html code to be generated depending on the template used.

Screenshots

Results when i do the generation with 3 different templates

Code generation for java-template

$ asyncapi generate fromTemplate ./src/main/contracts/kafka-example.yml @asyncapi/java-template -o ./target

[v2l1-jhartman micro-service]$ asyncapi generate fromTemplate ./src/main/contracts/kafka-example.yml @asyncapi/java-template -o ./target
(node:2366988) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
Skipping submitting anonymous metrics due to the following error: AbortError: This operation was aborted
┌  AsyncAPI Generator
│
◇  Generation failed
Generator Error: Installation failed
Skipping submitting anonymous metrics due to the following error: AbortError: This operation was aborted

Code generation for java-spring-template

$ asyncapi generate fromTemplate ./src/main/contracts/kafka-example.yml @asyncapi/java-spring-template -o ./target

[v2l1-jhartman micro-service]$ asyncapi generate fromTemplate ./src/main/contracts/kafka-example.yml @asyncapi/java-spring-template -o ./target
(node:2367054) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
Skipping submitting anonymous metrics due to the following error: AbortError: This operation was aborted
┌  AsyncAPI Generator
│
◇  Generation failed
Generator Error: Installation failed
Skipping submitting anonymous metrics due to the following error: AbortError: This operation was aborted

Code generation for html-template

$ asyncapi generate fromTemplate ./src/main/contracts/kafka-example.yml @asyncapi/html-template -o ./target

[v2l1-jhartman micro-service]$ asyncapi generate fromTemplate ./src/main/contracts/kafka-example.yml @asyncapi/html-template -o ./target
(node:2367110) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
Skipping submitting anonymous metrics due to the following error: AbortError: This operation was aborted
┌  AsyncAPI Generator
│
◇  Generation failed
Generator Error: This template is not compatible with the current version of the generator (1.17.25). This template is compatible with the following version range: >=2.0.0 <3.0.0.
Skipping submitting anonymous metrics due to the following error: AbortError: This operation was aborted
[v2l1-jhartman micro-service]$ 

How to Reproduce

Using latest version according the installation guide: https://www.asyncapi.com/docs/tools/generator/installation-guide

$ npm install -g @asyncapi/cli

$ npm --version
10.9.0

I am using the example kafka file from: https://raw.githubusercontent.com/asyncapi/java-spring-template/master/tests/mocks/kafka.yml

asyncapi: '2.0.0'
info:
  title: Streetlights API
  version: '1.0.0'
  description: |
    The Smartylighting Streetlights API allows you
    to remotely manage the city lights.
  license:
    name: Apache 2.0
    url: 'https://www.apache.org/licenses/LICENSE-2.0'

servers:
  production:
    url: kafka.bootstrap:{port}
    protocol: kafka
    variables:
      port:
        default: '9092'
        enum:
          - '9092'
          - '9093'

channels:
  event.lighting.measured:
    publish:
      bindings:
        kafka:
          groupId: my-group
      operationId: readLightMeasurement
      message:
        $ref: '#/components/messages/lightMeasured'
    subscribe:
      operationId: updateLightMeasurement
      message:
        $ref: '#/components/messages/lightMeasured'
components:
  messages:
    lightMeasured:
      summary: Inform about environmental lighting conditions for a particular streetlight.
      payload:
        $ref: "#/components/schemas/lightMeasuredPayload"
  schemas:
    lightMeasuredPayload:
      type: object
      properties:
        lumens:
          type: integer
          minimum: 0
          description: Light intensity measured in lumens.
        sentAt:
          $ref: "#/components/schemas/sentAt"
    sentAt:
      type: string
      format: date-time
      description: Date and time when the message was sent.

🥦 Browser

None

👀 Have you checked for similar open issues?

  • I checked and didn't find similar issue

🏢 Have you read the Contributing Guidelines?

Are you willing to work on this issue ?

None

@hartmanjan1970 hartmanjan1970 added the bug Something isn't working label Feb 12, 2025
Copy link
Contributor

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.

@ItshMoh
Copy link

ItshMoh commented Feb 14, 2025

hey @hartmanjan1970 The @asyncapi/java-spring-template is working fine. Here is the code snippet for the asyncapi spec that you are using.

package com.asyncapi.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.kafka.support.KafkaHeaders;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Service;

import com.asyncapi.model.LightMeasuredPayload;
import javax.annotation.processing.Generated;
import java.util.HashMap;
import java.util.Map;

@Generated(value="com.asyncapi.generator.template.spring", date="2025-02-14T04:41:53.922Z")
@Service
public class PublisherServiceImpl implements PublisherService {

    @Autowired
    private KafkaTemplate<Integer, Object> kafkaTemplate;

    
    public void updateLightMeasurement(Integer key, LightMeasuredPayload lightMeasuredPayload) {
        Message<LightMeasuredPayload> message = MessageBuilder.withPayload(lightMeasuredPayload)
                .setHeader(KafkaHeaders.TOPIC, getUpdateLightMeasurementTopic())
                .setHeader(KafkaHeaders.KEY, key)
                .build();
        kafkaTemplate.send(message);
    }

    private String getUpdateLightMeasurementTopic() {
        Map<String, String> parameters = null;
        return replaceParameters("event.lighting.measured", parameters);
    }
    private String replaceParameters(String topic, Map<String, String> parameters) {
        if (parameters != null) {
            String compiledTopic = topic;
            for (String key : parameters.keySet()) {
                compiledTopic = compiledTopic.replace("{" + key + "}", parameters.get(key));
            }
            return compiledTopic;
        }
        return topic;
    }
}

now you can try updating your generator version and node version. May be it will solve your issue.

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

No branches or pull requests

2 participants