缺少使用 AsyncAPI 生成的示例有效负载

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

我开始使用 AsyncAPI 为我的异步 Websocket 协议生成文档。我使用 AsyncAPI Studio 快速迭代我的文档,并使用 asyncapi/cli 和 docker 在我的本地计算机上实际生成 html。

但是,我遇到了一个问题,即未生成示例有效负载(无论是在 Studio 上还是在本地使用基于 docker 的 CLI)。我在模式中尝试了

example
examples
default
等的不同变体,但无论发生什么,我都只得到一个空白的有效负载示例。

blank payload example generated by AsyncAPI Studio

任何帮助将不胜感激!

asyncapi: 3.0.0
info:
  title: Promotion-API
  version: 1.0.0
  description: >-
    WebSocket API for Client interactions with the Server.
  
  contact:
    name: Example Company
    url: https://www.example.com
    email: [email protected]
  license:
    name: TBD
    url: https://www.example.com/LICENSE.txt
  
defaultContentType: application/json

servers:
  local:
    host: '<server-ip>:5111'
    protocol: ws
    title: Server
    summary: erver
    description: >-
      This API exists on a local server and can be accessed by others on the same local network.
    protocolVersion: "1.0"
    tags:
      - name: local
        description: local server
    bindings:
      ws:
        pingPongInterval: 20 seconds

channels:
  client:
    address: "client/{clientId}"
    parameters:
      clientId:
        $ref: '#/components/parameters/clientId'
    messages:
      BeginAction:
        $ref: '#/components/messages/BeginAction'

operations:
  begin:
    action: send
    title: Begin Action
    summary: Begin Transaction Action
    description: Notify the system that a new transaction begins.
    channel: 
      $ref: '#/channels/client'
    messages:
      - $ref: '#/channels/client/messages/BeginAction'
    tags:
      - name: transaction-action

components:
  schemas:
    transactionNumber:
      type: integer
      description: a 4 digit transaction number. Generally unique to the client at that date.
      example: 50
    userId:
      type: integer
      description: unique identifier of the user.
      example: 100
    BeginSchema:
      type: object
      properties:
        transactionNumber:
          $ref: '#/components/schemas/transactionNumber'
        "action":
          type: string
          description: the action string
          enum:
            - "begin"
          example: "begin"
        userId:
          $ref: '#/components/schemas/userId'
      required:
        - transactionNumber
        - action

  messages:
    BeginAction:
      name: BeginAction
      title: Begin Action Message
      summary: >-
        Message informing the server that a new transaction begins
      contentType: application/json
      payload:
        schema: 
          $ref: '#/components/schemas/BeginSchema'

  parameters:
    clientId:
      description: the unique id of the client.
      examples: ["1", "2", "100"]
asynchronous yaml documentation documentation-generation asyncapi
1个回答
0
投票

发布到 AsyncAPI GitHub:https://github.com/orgs/asyncapi/discussions/1535

但最终我自己找到了答案:

有一个额外的

schema
字段:

坏:

components:
  messages:
    BeginAction:
      name: BeginAction
      title: Begin Action Message
      summary: >-
        Message informing the server that a new transaction begins
      contentType: application/json
      payload:
        schema:
          $ref: '#/components/schemas/BeginSchema'

好:

components:
  messages:
    BeginAction:
      name: BeginAction
      title: Begin Action Message
      summary: >-
        Message informing the server that a new transaction begins
      contentType: application/json
      payload:
        $ref: '#/components/schemas/BeginSchema'
© www.soinside.com 2019 - 2024. All rights reserved.