oas icon indicating copy to clipboard operation
oas copied to clipboard

BUG: $ref relative paths are relative to CWD, should be relative to current document

Open BryanCrotazGivEnergy opened this issue 1 year ago • 1 comments

.
|- 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);
  });

BryanCrotazGivEnergy avatar Dec 29 '24 16:12 BryanCrotazGivEnergy

I notice the same behaviour using the verison "oas-normalize": "^14.1.0"

mscheerschmidt-mhp avatar Jul 01 '25 11:07 mscheerschmidt-mhp