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: $ref relative paths are relative to CWD, should be relative to current document #921

Open
BryanCrotazGivEnergy opened this issue Dec 29, 2024 · 0 comments

Comments

@BryanCrotazGivEnergy
Copy link

BryanCrotazGivEnergy commented Dec 29, 2024

.
|- tools
|    |- bundler.js // contains use of oasNormalize
|- api
     |- my-api.yaml
     |- paths
          |- path.yaml

If my-api.yaml contains a $ref: "./paths/path.yaml" it will fail with

node ./tools/bundler.js ./api/my-api.yaml

But will succeed with

cd ./api
node ../tools/bundler.js ./my-api.yaml

A $ref should be evaluated relative to the currently open file.

My bundler.js code:

import OASNormalize from "oas-normalize";

// if I make next line load ./api/my-openapi.yaml then it will fail to load references
const oas = new OASNormalize("./my-openapi.yaml", {
  enablePaths: true,
});

oas
  .validate()
  .then(() => oas.convert())
  .then((definition) => {
    console.log(definition);
  })
  .catch((err) => {
    console.error(err);
  });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant