Giter VIP home page Giter VIP logo

Comments (8)

jonaslagoni avatar jonaslagoni commented on August 15, 2024

However, if we use the parser under next-major-spec branch so we parse v3 docs, it does not happen:

That example is technically an invalid v3 document as the channel does not contain the messages being references in the operation. If you add the messages to the v3 doc, does that re-create the problem as in v2?

from parser-js.

smoya avatar smoya commented on August 15, 2024

However, if we use the parser under next-major-spec branch so we parse v3 docs, it does not happen:

That example is technically an invalid v3 document as the channel does not contain the messages being references in the operation. If you add the messages to the v3 doc, does that re-create the problem as in v2?

Yes, I was about to write it right now. Same issue happens with v3 as well. And it's about the pointer.

asyncapi: '3.0.0'
info:
  title: Account Service
  version: 1.0.0
  description: This service is in charge of processing user signups
channels:
  UserSignedUp: 
    messages:
      UserSignedUp:
        $ref: '#/components/messages/UserSignedUp'
operations:
  user/signedup:
    action: send
    channel: 
      $ref: '#/channels/UserSignedUp'
    messages:
      - $ref: '#/components/messages/UserSignedUp'
components:
  messages:
    UserSignedUp:
      payload:
        type: object
        properties:
          displayName:
            type: string
            description: Name of the user
          email:
            type: string
            format: email
            description: Email of the user

from parser-js.

smoya avatar smoya commented on August 15, 2024

Updated description according to previous comment

from parser-js.

derberg avatar derberg commented on August 15, 2024

but your v3 example is not valid either, right?

valid is:

asyncapi: '3.0.0'
info:
  title: Account Service
  version: 1.0.0
  description: This service is in charge of processing user signups
channels:
  UserSignedUp: 
    messages:
      UserSignedUp:
        $ref: '#/components/messages/UserSignedUp'
operations:
  user/signedup:
    action: send
    channel: 
      $ref: '#/channels/UserSignedUp'
    messages:
      - $ref: '#/channels/UserSignedUp/messages/UserSignedUp'
components:
  messages:
    UserSignedUp:
      payload:
        type: object
        properties:
          displayName:
            type: string
            description: Name of the user
          email:
            type: string
            format: email
            description: Email of the user

so you should reference message from a channel, not components. How else will you validate if message referenced from the operation it the same as in the channel? especially that you need to validate the messageId as well, right?

from parser-js.

derberg avatar derberg commented on August 15, 2024

let's take

asyncapi: '2.6.0'
info:
  title: Account Service
  version: 1.0.0
  description: This service is in charge of processing user signups
channels:
  user/signedup:
    subscribe:
      message:
        $ref: '#/components/messages/UserSignedUp'
components:
  messages:
    UserSignedUp:
      payload:
        type: object
        properties:
          displayName:
            type: string
            description: Name of the user
          email:
            type: string
            format: email
            description: Email of the user

and converter creates

asyncapi: 3.0.0
info:
  title: Account Service
  version: 1.0.0
  description: This service is in charge of processing user signups
channels:
  user/signedup:
    address: user/signedup
    messages:
      subscribe.message:
        $ref: '#/components/messages/UserSignedUp'
operations:
  user/signedup.subscribe:
    action: send
    channel:
      $ref: '#/channels/user~1signedup'
    messages:
      - $ref: '#/components/messages/UserSignedUp'
components:
  messages:
    UserSignedUp:
      payload:
        type: object
        properties:
          displayName:
            type: string
            description: Name of the user
          email:
            type: string
            format: email
            description: Email of the user

it is invalid document

    messages:
      - $ref: '#/components/messages/UserSignedUp'

is not the same as

messages:
      subscribe.message:
        $ref: '#/components/messages/UserSignedUp'

the id do not match

from parser-js.

smoya avatar smoya commented on August 15, 2024

Whatever you use, it doesn't really matter. The issue keeps happening because the ID of those objects are not used for comparing but the .json() object of those.

BTW, I just found the bug. This is the callback we use for comparing:

const schemas: Set<SchemaInterface> = new Set();
    function callback(schema: SchemaInterface) {
      if (!schemas.has(schema.json())) {
        schemas.add(schema);
      }
    }

Source: https://github.com/asyncapi/parser-js/blob/next-major-spec/src/models/v3/asyncapi.ts#L149-L154 (same for v2 model as well)

Note that we check if the schema.json() is already present in the set, however we never store the output of .json() on it but the Schema. Meaning if (!schemas.has(schema.json())) { is always true.

from parser-js.

smoya avatar smoya commented on August 15, 2024

Here is the fix #897

cc @derberg @jonaslagoni

from parser-js.

smoya avatar smoya commented on August 15, 2024

Fixed by #897

from parser-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.