asyncapi / parser-js

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

v1.10.6 does not support absolute path in $ref #797

Closed dvemnt closed 3 weeks ago

dvemnt commented 1 year ago

Describe the bug

The latest version of the parser does not support referencing by absolute path. It works in version 1.9.18.

How to Reproduce

  1. Create Async API doc file with absolute path $ref and file on this path in same folder.
  2. Try to build using HTML template.
asyncapi: "2.4.0"
defaultContentType: application/json

info:
  title: Test Absolute Path
  version: "1.0.0"

channels:
  TestOperation:
    publish:
      message:
        $ref: "/absolute-path/File.yaml"

Expected behavior

Done! ✨ Check out your shiny new generated files at ...

Actual behavior

Something went wrong:
Error: Input is not a corrent AsyncAPI document so it cannot be processed.
    at Generator.generateFromString (/usr/local/lib/node_modules/@asyncapi/generator/lib/generator.js:264:19)
    at async /usr/local/lib/node_modules/@asyncapi/generator/cli.js:157:9
Errors:
[
  {
    "code": "invalid-ref",
    "path": [
      "channels",
      "TestOperation",
      "publish",
      "message",
      "$ref"
    ],
    "message": "ENOENT: no such file or directory, open '/absolute-path/absolute-path/File.yaml'",
    "severity": 0,
    "range": {
      "start": {
        "line": 11,
        "character": 14
      },
      "end": {
        "line": 11,
        "character": 40
      }
    },
    "source": "/absolute-path/asyncapi.yaml"
  }
]
github-actions[bot] commented 1 year 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.

amelluk commented 1 year ago

duplicate of asyncapi/generator#963 - I have the same problem :/

dvemnt commented 1 year ago

duplicate of asyncapi/generator#963 - I have the same problem :/

I don't think that's duplicate. asyncapi/generator#963 is about the spec and unsupported place for reference, here is about paths handling.

eivindga commented 1 year ago

As far as I understand, the spec does no longer allow absolute paths in references?

See also: https://github.com/asyncapi/parser-js/issues/405

dvemnt commented 1 year ago

As far as I understand, the spec does no longer allow absolute paths in references?

Looks like, the spec still allow absolute paths in references, but generator (or parser) handles such paths in wrong way, as local paths, I think.

derberg commented 1 year ago

sorry but I'm unable to replicate your issue. I created a file that you shared and all was good.

I also opened a PR to show tests with different local references work https://github.com/asyncapi/generator/pull/1003

on message level references should and were always possible.

As far as I understand, the spec does no longer allow absolute paths in references?

not sure where you got this message from, but spec is definitely still supporting $ref in message object

dvemnt commented 1 year ago

Hi, @derberg. I don't see absolute references in your PR, only relative references (here and here). And my issue still reproduces.

Screenshot from 2023-07-03 16-53-22

derberg commented 1 year ago

you're right, sorry, I misunderstood your initial example.

yes, I can replicate this problem. It is for sure something that should work, and worked before

As a workaround, add file: to the reference. And I'm moving this issue to parser repo, as it is bug in the repo, and not even the repo but the fact there was a move to another reference parser tool that do not work as expected: https://github.com/stoplightio/json-ref-resolver. So apparently some regression was introduced in functionality

github-actions[bot] commented 1 year 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 10 months ago

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

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 :heart:

derberg commented 8 months ago

I think the issue is still there

github-actions[bot] commented 4 months ago

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

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 :heart: