Skip to content

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

@BryanCrotazGivEnergy

Description

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions