Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
2 tasks done
ttnicoleau opened this issue Apr 9, 2024 · 2 comments
Closed
2 tasks done
Labels
bug Something isn't working

Comments

@ttnicoleau
Copy link

ttnicoleau commented Apr 9, 2024

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?

  • I checked and didn't find similar issue

🏢 Have you read the Contributing Guidelines?

Are you willing to work on this issue ?

None

@ttnicoleau ttnicoleau added the bug Something isn't working label Apr 9, 2024
Copy link

github-actions bot commented Apr 9, 2024

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant