Asyncapi 生成抛出 不支持版本“3.0.0”。请使用“2.6.0”

问题描述 投票:0回答:1

我正在编写自定义模板以根据 AsyncAPI 规范生成代码。

我正在使用react-render-engine https://www.asyncapi.com/docs/tools/generator/react-render-engine并且我正在遵循本教程https://www.asyncapi.com/docs /工具/生成器/生成器模板.

如果我使用asyncapi版本2.6.0,它可以工作

asyncapi: 2.6.0
info: 
  ...

命令

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

如何让 asyncapi-parser 使用 3.0.0 版本?支持吗?
切换到版本 3.0.0 后,我收到以下错误:

诊断错误:不支持版本“3.0.0”。请使用“2.6.0”(最新)版本的规范。在路径 [] 中,从 L1 C0 开始,到 L77 C59 结束

诊断错误:未知架构格式:“application/vnd.aai.asyncapi;version=3.0.0”位于路径 [“components”、“messages”、“commandFeed”] 中,从 L46 C16 开始,到 L51 C48 结束

诊断错误:由于模式格式未知,无法验证和解析给定模式:路径 [“components”、“messages”、“commandFeed”、“payload”] 中的“application/vnd.aai.asyncapi;version=3.0.0”起始 L50 C14,结束 L51 C48

诊断错误:未知架构格式:“application/vnd.aai.asyncapi;version=3.0.0”位于路径 [“components”、“messages”、“eventFeedingOrdered”] 中,起始 L52 C24,结束 L56 C51

诊断错误:由于模式格式未知,无法验证和解析给定模式:路径 [“components”、“messages”、“eventFeedingOrdered”、“payload”] 中的“application/vnd.aai.asyncapi;version=3.0.0”起始 L55 C14,结束 L56 C51

生成器错误:输入不是正确的 AsyncAPI 文档,因此无法处理。

asyncapi 规范文件

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
      }
    }
  }
}

如有任何帮助,我们将不胜感激!

asyncapi
1个回答
0
投票

只需将生成器模板配置的

apiVersion
设置为
v3
。这使得生成器能够传递最新的解析器版本,如https://github.com/asyncapi/parser-js/

即将您的包文件更改为:

{
  "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
      }
    }
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.