asyncapi / studio

Visually design your AsyncAPI files and event-driven architecture.
https://studio.asyncapi.com
Apache License 2.0
171 stars 98 forks source link

Buggy Auto Schema Update on Studio UI #1117

Closed prasu-05 closed 2 months ago

prasu-05 commented 5 months ago

Buggy Auto Schema Update on Studio UI

Describe the bug The Schema auto update conversion shown on Studio UI is buggy and produces wrong schema(pub and sub messages are interchanged). I faced the issue for converting my asyncschema from version 2.6.0 to version 3.0.0

How to Reproduce Try to convert the below schema to latest version using studio UI image

asyncapi: '2.6.0'
info:
  title: DameChess Game WebSocket API
  version: '1.0.0'
  description: This API allows users to play chess games, chat, and broadcast the game moves in real-time.

servers:
  production:
    url: wss://your-api-domain.com/ws
    protocol: wss

channels:
  game/{gameId}:
    description: WebSocket channel for game events including moves, chats, and watching the game.
    parameters:
      gameId:
        description: The unique identifier of the game.
        schema:
          type: string
          format: uuid
    subscribe:
      operationId: receiveGameUpdates
      summary: Receive game updates including moves and chat messages.
      message:
        oneOf:
          - $ref: '#/components/messages/moveUpdate'
          - $ref: '#/components/messages/chatMessage'
    publish:
      operationId: sendGameActions
      summary: Send game actions like moves or chat messages.
      message:
        oneOf:
          - $ref: '#/components/messages/makeMove'
          - $ref: '#/components/messages/sendChat'

  live/{gameId}:
    description: WebSocket channel for watching live game updates.
    parameters:
      gameId:
        description: The unique identifier of the game.
        schema:
          type: string
          format: uuid
    subscribe:
      operationId: watchGameLive
      summary: Subscribe to receive real-time updates of game moves.
      message:
        $ref: '#/components/messages/moveUpdate'

components:
  messages:
    moveUpdate:
      name: Move Update
      title: Move Update
      summary: Contains the details of a chess move.
      contentType: application/json
      payload:
        type: object
        properties:
          jwtToken:
            type: string
            description: JWT token for user authentication.
          type:
            type: string
            enum: [ MOVE, PROMOTION, RESIGN, OFFER_DRAW ]
          from:
            type: string
            description: The starting square of the move.
          to:
            type: string
            description: The ending square of the move.
          promotionPiece:
            type: string
            enum: [ QUEEN, ROOK, BISHOP, KNIGHT ]
            description: Piece to promote to, required if type is PROMOTION.
          remainingTime:
            type: integer
            description: Remaining time for the player in milliseconds.
        required:
          - jwtToken
          - type
          - from
          - to

    chatMessage:
      name: Chat Message
      title: Chat Message
      summary: A chat message between players or broadcast to watchers.
      contentType: application/json
      payload:
        type: object
        properties:
          jwtToken:
            type: string
            description: JWT token for user authentication.
          message:
            type: string
            description: Chat message content.
        required:
          - jwtToken
          - message

    makeMove:
      name: Make Move
      title: Make a Move
      summary: Make a move in the chess game.
      contentType: application/json
      payload:
        type: object
        properties:
          jwtToken:
            type: string
            description: JWT token for user authentication.
          type:
            type: string
            enum: [ MOVE, PROMOTION, RESIGN, OFFER_DRAW ]
          from:
            type: string
            description: The starting square of the move.
          to:
            type: string
            description: The ending square of the move.
          promotionPiece:
            type: string
            enum: [ QUEEN, ROOK, BISHOP, KNIGHT ]
            description: Piece to promote to, required if type is PROMOTION.
        required:
          - jwtToken
          - type
          - from
          - to

    sendChat:
      name: Send Chat Message
      title: Send Chat Message
      summary: Send a chat message during a game.
      contentType: application/json
      payload:
        type: object
        properties:
          jwtToken:
            type: string
            description: JWT token for user authentication.
          message:
            type: string
            description: Chat message content.
        required:
          - jwtToken
          - message

Expected behavior The Conversion should be correct

github-actions[bot] commented 5 months 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.

github-actions[bot] commented 5 months 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.

prasu-05 commented 2 months ago

@derberg this issue should be labled a bug right?

fmvilas commented 2 months ago

hmmm πŸ€” I'm 99.999% sure this is not a bug. It looks like you're not using the publish and subscribe verbs correctly:

    subscribe:
      operationId: receiveGameUpdates

A subscribe operation means that others can subscribe to this channel to receive this message. Therefore, your app should send it:

    subscribe:
      operationId: sendGameUpdates

I know it's counterintuitive and that's why we removed publish and subscribe in v3 and changed the "point of view". So now, in v3, send actually means what you expected, that your app is sending the message. Therefore, send maps to subscribe and receive to publish.

We have written a lot about this in the past trying to minimize the impact of this confusing design in v2.x. I recommend you read this one: https://www.asyncapi.com/blog/publish-subscribe-semantics. Hopefully, you won't have to deal with this problem anymore once you migrate to v3 πŸ™

I'm closing but feel free to reopen if you think I'm missing something πŸ™