Skip to content

parser doesn't validates the $ref links #360

Closed

Description

@KhudaDad414

Bug Description

If there is a typo in $ref value the parser should throw an error instead of passing the actual $ref.

How to Reproduce

const parser = require('@asyncapi/parser');

parser.parse(`
asyncapi: 2.0.0
info:
  title: Streetlights API
  version: '1.0.0'
channels:
  smartylighting/event/lighting/measured:
    subscribe:
      message:
        $ref: "#components/messages/message1"
components:
  messages:
    message1:
      name: unusedMessage
      title: This is most definityly a message.
`).then((doc) => {
  console.log(doc.channel('smartylighting/event/lighting/measured').subscribe().message().json());
});

Actual Result

{
  '$ref': '#components/messages/message1',
  schemaFormat: 'application/vnd.aai.asyncapi;version=2.0.0',
  'x-parser-message-parsed': true,
  'x-parser-message-name': '<anonymous-message-1>'
}

Expected Result

It should give an error message saying that my $ref path is broken or does not exist.

Activity

  1. added
    bug
    on Sep 9, 2021
  2. jonaslagoni commented on Sep 9, 2021

    @jonaslagoni
    Member

    Since we don't want errors to be thrown but rather bundled together, to throw one big error in the end (I would assume so? git blame @derberg @fmvilas), this option is set to true:

    continueOnError: true,

    However, we never check that the dereference succedded, not sure if the dereference call actually returns any content, docs say nothing.

  3. fmvilas commented on Sep 14, 2021

    @fmvilas
    Contributor

    Yeah, the idea is that it continues to throw one big error at the end. I'm now wondering if continueOnError actually does that 🤔

  4. derberg commented on Sep 14, 2021

    @derberg
    Member

    I'm now wondering if continueOnError actually does that

    it does, it gives an array of all errors

    continueOnError: true

    it is just an option in refs parser library that we leverage. As you know, when I added custom validations, I did not follow this principle, as far as I remember, my bad. The same option to group errors is also used in Ajv.

    hard to say why there is no error, would require some debugging

  5. github-actions commented on Jan 13, 2022

    @github-actions

    This issue has been automatically marked as stale because it has not had recent activity 😴

    It will be closed in 120 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.

    There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.

    Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here.

    Thank you for your patience ❤️

  6. github-actions commented on May 14, 2022

    @github-actions

    This issue has been automatically marked as stale because it has not had recent activity 😴

    It will be closed in 120 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.

    There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.

    Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here.

    Thank you for your patience ❤️

  7. smoya commented on Jul 11, 2022

    @smoya
    Member

    Can we solve this with a pattern field on the JSON Schema Reference Object ?

  8. derberg commented on Jul 11, 2022

    @derberg
    Member

    dunno, maybe there is already some super bullet-proof regex created by the community that can validate $ref as it can represent, link to file, URL or location inside the existing document. It definitely exceeds my knowledge of regex 😄

  9. smoya commented on Jul 11, 2022

    @smoya
    Member

    Otherwise, AJV should throw an error (MissingRefError) anyway. See this example I built: https://onecompiler.com/nodejs/3y9pgk7py

  10. smoya commented on Oct 25, 2022

    @smoya
    Member

    Issue is resolved in v2 ParserJS - now in https://github.com/asyncapi/parser-js/tree/next-major branch thanks to Spectral. Pending to add a test.

    cc @magicmatatjahu

  11. magicmatatjahu commented on Nov 15, 2022

    @magicmatatjahu
    Member

    Resolved by #676

  12. asyncapi-bot commented on Dec 13, 2022

    @asyncapi-bot
    Contributor

    🎉 This issue has been resolved in version 2.0.0-next-major.11 🎉

    The release is available on:

    Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugreleased on @next-major

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions