Working dir used in openapi schema ref relative paths

Issue #24 new
Mikkel S created an issue

I'm trying to run a openapi-diff between the HEAD and latest tag in a repository. My api specs are split up in several files that are referenced using $ref. My tag is checked out in build/vorigeTag.

I've checked out the latest tag in build/vorigeTag and the HEAD is in the current directory. When I run openapi-diff build/vorigeTag/specs/stamgegevens.json specs/stamgegevens.json, I get this output:

D:\dev\projects\stamgegevens-spec>npm run openapi-diff -- build/vorigeTag/specs/stamgegevens.json specs/stamgegevens.json

> stamgegevens-spec@1.0.0 openapi-diff D:\dev\projects\stamgegevens-spec
> openapi-diff "build/vorigeTag/specs/stamgegevens.json" "specs/stamgegevens.json"

OpenApiDiffErrorImpl [VError]: Validation errors in "build/vorigeTag/specs/stamgegevens.json": Error opening file "D:\dev\projects\stamgegevens-spec\paths\activiteitsoorten.json"
ENOENT: no such file or directory, open 'D:\dev\projects\stamgegevens-spec\paths\activiteitsoorten.json'
    at D:\dev\projects\stamgegevens-spec\node_modules\openapi-diff\dist\openapi-diff\spec-parser\common\validate-and-dereference-spec.js:23:15
    at Generator.throw (<anonymous>)
    at rejected (D:\dev\projects\stamgegevens-spec\node_modules\openapi-diff\dist\openapi-diff\spec-parser\common\validate-and-dereference-spec.js:6:65) {
  jse_shortmsg: 'Validation errors in "build/vorigeTag/specs/stamgegevens.json"',
  jse_cause: {
    stack: 'ResolverError: Error opening file "D:\\dev\\projects\\stamgegevens-spec\\paths\\activiteitsoorten.json" \n' +
      "ENOENT: no such file or directory, open 'D:\\dev\\projects\\stamgegevens-spec\\paths\\activiteitsoorten.json'\n" +
      '    at ReadFileContext.callback (D:\\dev\\projects\\stamgegevens-spec\\node_modules\\@apidevtools\\json-schema-ref-parser\\lib\\resolvers\\file.js:52:20)\n' +
      '    at FSReqCallback.readFileAfterOpen [as oncomplete] (fs.js:261:13)',
    code: 'ERESOLVER',
    message: 'Error opening file "D:\\dev\\projects\\stamgegevens-spec\\paths\\activiteitsoorten.json" \n' +
      "ENOENT: no such file or directory, open 'D:\\dev\\projects\\stamgegevens-spec\\paths\\activiteitsoorten.json'",
    source: 'D:\\dev\\projects\\stamgegevens-spec\\paths\\activiteitsoorten.json',
    path: null,
    toJSON: [Function: toJSON],
    ioErrorCode: 'ENOENT',
    name: 'ResolverError',
    toString: [Function: toString]
  },
  jse_info: {},
  code: 'OPENAPI_DIFF_PARSE_ERROR'
}

So this leads to the conclusion that openapi-diff is using the relative paths in my openapi specs (like "$ref": "./paths/activiteitsoorten.json#/activiteitsoorten") relative to the current working directory instead of relative to the current file.

It should refer to D:\dev\projects\stamgegevens-spec\build\vorigeTag\specs\paths\activiteitsoorten.json instead of failing on the fact that D:\dev\projects\stamgegevens-spec\paths\activiteitsoorten.json cannot be found.

Is this something that can be fixed?

Comments (1)

  1. Mikkel S reporter

    Also it’s worth noting that I’ve tried several merge tools, that create a single openapi spec file from multiple ones, like swagger-combine, swagger-merger and speccy, which didn’t help me do a local compare of the specs.

    Running openapi-diff against deployed Spring Boot applications does work, but we’d like to catch breaking changes sooner…

  2. Log in to comment