maxdome / swagger-combine

Combines multiple Swagger schemas into one dereferenced schema.
MIT License
132 stars 36 forks source link

continueOnError causes failure during addBasePath #43

Closed maritz closed 6 years ago

maritz commented 6 years ago

When continueOnError is set to true and the api option that is failing includes a paths option, an error is thrown and no json produced.

This is not covered by the test here because it only tests a failing api that has no further options set. Thus none of the later steps try to access the undefined schema.

I didn't go through the entire code, but I'd suspect that the same happens with other things, not just basePath.

My proposal would be to discard all failed apis when continueOnError is true.

Something like this here:

if (this.opts.continueOnError) {
  apis = apis.filter((api) => api !== undefined);
}

Alternatively checking in each further step whether schema is undefined in the schema.map() is also an option.

Here's a failing integration test:

  it('catches errors if `continueOnError` option is set to true and a swagger config is unreachable for extended api config', () => {
    nock('https://api.apis.guru')
      .get('/v2/specs/deutschebahn.com/betriebsstellen/v1/swagger.json')
      .reply(500);

    return swaggerCombine(basicConfig, { continueOnError: true });
  });
fabsrc commented 6 years ago

Thank you for finding and reporting this bug 🙂 I hope it's ok that I borrowed your code for the fix.

maritz commented 6 years ago

I hope it's ok that I borrowed your code for the fix.

That's what it was for. ;-)