asyncapi / parser-js

AsyncAPI parser for Javascript (browser-compatible too).
Apache License 2.0
116 stars 91 forks source link

[BUG] message payload schema object cannot be called by parser api #982

Closed ttnicoleau closed 4 months ago

ttnicoleau commented 4 months ago

Describe the bug.

The parser api can show the Schema object via channel.messages().get("{messageId}").payload() but unable to get the schema value from the Schema object where the payload is in $ref

asyncapi document:

asyncapi: 2.6.0

info:
  title: Kafka Service
  version: 1.0.0
  description: This service is in charge of processing all events related to the Kafka topic.

servers:
  local-broker:
    url: 127.0.0.2:9092
    protocol: kafka
    protocolVersion: 2.6.0
    description: local kafka cluster for development
    bindings:
      kafka:
        schemaRegistryVendor: "confluent"
        schemaRegistryUrl: "http://127.0.0.2:8081"
        bindingVersion: "0.5.0"

channels:
  TEST_CHANNEL_A:
    description: Test Kafka channel created by AsyncAPI.
    parameters:
      action:
        description: action of the topic
        schema:
          type: string
          value: create
    publish:
      message:
        messageId: userSignedUp
        payload:
          $ref: "#/components/schemas/ArvoSchema"

      bindings:
        kafka:
          partitions: 2
          replicas: 1
          topicConfiguration:
            min.insync.replicas: 1
            retention.ms: 60480000
            retention.bytes: -1
            delete.retention.ms: 86400000
            max.message.bytes: 1048588

components:
  schemas:
    ArvoSchema:
      type: object
      schemaFormat: "application/vnd.apache.avro+json"
      schema:
        $ref: https://raw.githubusercontent.com/ept/avrodoc/master/schemata/example.avsc

node parser

asyncapi.allSchemas().get("ArvoSchema")
channel.messages().get("userSignedUp").payload()

console.log the above both show the same result of a schema object but not able to access the schema object

Schema {
  _json: {
    type: 'object',
    schemaFormat: 'application/vnd.apache.avro+json',
    schema: {
      type: 'record',
      name: 'User',
      namespace: 'com.example.avro',
      doc: 'This is a user record in a fictitious to-do-list management app. It supports arbitrary grouping and nesting of items, and allows you to add items by email or by tweeting.\n' +
        '\n' +
        "Note this app doesn't actually exist. The schema is just a demo for [Avrodoc](https://github.com/ept/avrodoc)!",
      fields: [Array]
    },
    'x-parser-schema-id': 'ArvoSchema'
  },

Expected behavior

return schema properties inside schema object

Screenshots

channel.messages().get("userSignedUp").payload().schemaFormat() return the below: Generator Error: asyncapi.allSchemas(...).get(...).schemaFormat is not a function

channel.messages().get("userSignedUp").payload().schemaFormat / channel.messages().get("userSignedUp").payload()['schemaFormat'] return undefined

How to Reproduce

"@asyncapi/cli": "^0.60.1",
"@asyncapi/generator": "^1.14.1",
"@asyncapi/generator-react-sdk": "^0.2.25",
"@asyncapi/parser": "^3.0.12",

🥦 Browser

None

👀 Have you checked for similar open issues?

🏢 Have you read the Contributing Guidelines?

Are you willing to work on this issue ?

None

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

ttnicoleau commented 4 months ago

I finally get the schema by using channel.messages().get("userSignedUp").payload()["_json"]["schema"]

I know it may not be the best practice, but it is the only way I can do at this moment