Search code examples
asyncapi

Asyncapi generate throws Version "3.0.0" is not supported. Please use "2.6.0"


I am writing custom template to generate code from AsyncAPI specs.

I am using react-render-engine https://www.asyncapi.com/docs/tools/generator/react-render-engine and I am following this tutorial https://www.asyncapi.com/docs/tools/generator/generator-template.

If I use asyncapi version 2.6.0, it works

asyncapi: 2.6.0
info: 
  ...

Command:

asyncapi generate fromTemplate test-fixtures/test-asyncapi.yaml ./dist/ -p server=localhost -o gen.out --force-write --param server=local

How can I make asyncapi-parser to use version 3.0.0? Is it supported?
After switching to version 3.0.0 i am getting following error:

Diagnostic err: Version "3.0.0" is not supported. Please use "2.6.0" (latest) version of the specification. in path [] starting L1 C0, ending L77 C59

Diagnostic err: Unknown schema format: "application/vnd.aai.asyncapi;version=3.0.0" in path ["components","messages","commandFeed"] starting L46 C16, ending L51 C48

Diagnostic err: Cannot validate and parse given schema due to unknown schema format: "application/vnd.aai.asyncapi;version=3.0.0" in path ["components","messages","commandFeed","payload"] starting L50 C14, ending L51 C48

Diagnostic err: Unknown schema format: "application/vnd.aai.asyncapi;version=3.0.0" in path ["components","messages","eventFeedingOrdered"] starting L52 C24, ending L56 C51

Diagnostic err: Cannot validate and parse given schema due to unknown schema format: "application/vnd.aai.asyncapi;version=3.0.0" in path ["components","messages","eventFeedingOrdered","payload"] starting L55 C14, ending L56 C51

Generator Error: Input is not a correct AsyncAPI document so it cannot be processed.

asyncapi specs file

asyncapi: 3.0.0
info:
  title: Pets Domain
  version: 1.0.0
  description: Example API for Pets
  license:
    name: Apache 2.0
    url: 'https://www.apache.org/licenses/LICENSE-2.0'
  tags:
    - name: pets
defaultContentType: application/json
servers:
  local:
    host: 'localhost:8000'
    protocol: websocket
    description: Local broker
channels:
  pets.command.feed:
    address: pets.command.feed
    messages:
      receiveLightMeasurement.message:
        $ref: '#/components/messages/commandFeed'
  pets.event.feedingOrdered:
    address: pets.event.feedingOrdered
    messages:
      turnOn.message:
        $ref: '#/components/messages/eventFeedingOrdered'
operations:
  receiveLightMeasurement:
    action: receive
    channel:
      $ref: '#/channels/pets.command.feed'
    summary: >-
      Inform about environmental lighting conditions of a particular
      streetlight.
    messages:
      - $ref: '#/channels/pets.command.feed/messages/receiveLightMeasurement.message'
  turnOn:
    action: send
    channel:
      $ref: '#/channels/pets.event.feedingOrdered'
    messages:
      - $ref: '#/channels/pets.event.feedingOrdered/messages/turnOn.message'
components:
  messages:
    commandFeed:
      name: command/feed
      title: Feed pet
      contentType: application/json
      payload:
        $ref: '#/components/schemas/commandFeed'
    eventFeedingOrdered:
      name: event/feedingOrdered
      title: Turn on/off
      payload:
        $ref: '#/components/schemas/feedingOrdered'
  schemas:
    commandFeed:
      type: object
      properties:
        petId:
          type: string
          format: uuid
        sentAt:
          $ref: '#/components/schemas/sentAt'
    feedingOrdered:
      type: object
      properties:
        petId:
          type: string
          format: uuid
        sentAt:
          $ref: '#/components/schemas/sentAt'
    sentAt:
      type: string
      format: date-time
      description: Date and time when the message was sent.

package.json

{
  "name": "asyncapi-test",
  "version": "0.0.1",
  "type": "commonjs",
  "main": "./template/index.js",
  "dependencies": {
    "@asyncapi/cli": "^1.5.2",
    "@asyncapi/generator-react-sdk": "^1.0.9",
    "@asyncapi/parser": "^3.0.5"
  },
  "generator": {
    "renderer": "react",
    "parameters": {
      "server": {
        "description": "The server you want to use in the code.",
        "required": true
      }
    }
  }
}

Any help is appreciated!


Solution

  • Simply set the apiVersion of the generator template configuration to v3. That enables the generator to pass along the newest parser version as seen in https://github.com/asyncapi/parser-js/.

    I.e. change your package file to:

    {
      "name": "asyncapi-test",
      "version": "0.0.1",
      "type": "commonjs",
      "main": "./template/index.js",
      "dependencies": {
        "@asyncapi/cli": "^1.5.2",
        "@asyncapi/generator-react-sdk": "^1.0.9",
        "@asyncapi/parser": "^3.0.5"
      },
      "generator": {
        "renderer": "react",
        "apiVersion": "v3",
        "parameters": {
          "server": {
            "description": "The server you want to use in the code.",
            "required": true
          }
        }
      }
    }