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] Generate commands only run in context of the CWD, not the directory of the asyncapi.yaml file #1482

Open
2 tasks done
adammfrank opened this issue Jul 15, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@adammfrank
Copy link

adammfrank commented Jul 15, 2024

Describe the bug.

When I run a generate command from one directory up from the asyncapi.yml, it is looking for relative refs in the directory the command was run from (cwd) not the directory containing asyncapi.yml

This is the asyncapi.yaml

asyncapi: 3.0.0
info:
  title: My App
  version: 1.0.0
  description: Where the real work gets done.
servers:
  rabbitmq:
    host: localhost:15672
    protocol: amqp
channels:
  runs:
    address: runs
    title: Runs
    servers:
      - $ref: '#/servers/rabbitmq'
    bindings:
      amqp:
        is: routingKey
        exchange:
          name: runs
          type: headers
          ack: true
          durable: true
    messages:
      runCompleted:
        payload:
          $ref: './schemas/runCompleted.json'
operations:
  publishPlaybookRun:
    channel:
      $ref: '#/channels/runs'
    action: send

./schemas/runCompleted does exist and is next to asyncapi.yaml. The generate command can't find it because it is running one directory up from asyncapi.yaml and is looking for ./schemas from there.

If I run the command from the same directory as asyncapi.yaml then it works

asyncapi generate fromTemplate asyncapi.yaml @asyncapi/html-template@2.3.9 -o ./docs
┌  AsyncAPI Generator
│
◓  Generation in progress. Keep calm and wait a bit...[BABEL] Note: The code generator has deoptimised the styling of /Users/adam.frank/.volta/tools/image/packages/@asyncapi/cli/lib/node_modules/@asyncapi/cli/node_modules/@asyncapi/generator/node_modules/@asyncapi/html-template/template/js/asyncapi-ui.min.js as it exceeds the max of 500KB.
◇  Check out your shiny new generated files at ./docs.

Please let me know if I'm doing something wrong, or if you think this should be fixed. It sounds like the type of thing I could help with.

Expected behavior

I expect generate to work from any directory as long as it is supplied a path to a valid asyncapi.yaml. Or it would also work if it needed a context argument like docker build uses.

Screenshots

asyncapi generate fromTemplate asyncapi/asyncapi.yaml @asyncapi/html-template@2.3.9 -o ./docs
┌  AsyncAPI Generator
│
◐  Generation in progress. Keep calm and wait a bitDiagnostic err: ENOENT: no such file or directory, open './schemas/RunCompleted.json' in path ["channels","runs","messages","runCompleted","payload","$ref"] starting L37 C20, ending L37 C57
◇  Generation failed
Generator Error: Input is not a correct AsyncAPI document so it cannot be processed.

How to Reproduce

Create an asyncapi.yaml with relative path refs.
Run a generate command from a directory above the asyncapi.yaml file

asyncapi generate fromTemplate asyncapi/asyncapi.yaml @asyncapi/html-template@2.3.9 -o ./docs
┌  AsyncAPI Generator
│
◐  Generation in progress. Keep calm and wait a bitDiagnostic err: ENOENT: no such file or directory, open './schemas/RunCompleted.json' in path ["channels","runs","messages","runCompleted","payload","$ref"] starting L37 C20, ending L37 C57
◇  Generation failed
Generator Error: Input is not a correct AsyncAPI document so it cannot be processed.

🥦 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 ?

Yes I am willing to submit a PR!

@adammfrank adammfrank added the bug Something isn't working label Jul 15, 2024
@github-project-automation github-project-automation bot moved this to To Triage in CLI - Kanban Jul 15, 2024
Copy link
Contributor

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.

@Laupetin
Copy link
Contributor

Hey, have you tried again with v2.1.1 maybe? It sounds a lot like this could be the same problem that was fixed in that release.

@Souvikns
Copy link
Member

@adammfrank can you confirm if you still have this error, we will close the issue if it is solved.

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
Status: To Triage
Development

No branches or pull requests

3 participants