Skip to content

Commit

Permalink
Properly report OAS validation errors (#67)
Browse files Browse the repository at this point in the history
* Properly report OAS validation errors

* Add stringified error object

* Update test/cmds/swagger.test.js

Co-Authored-By: Jon Ursenbach <[email protected]>

* Prettier

* Whoops
  • Loading branch information
kanadgupta authored and erunion committed Aug 28, 2019
1 parent 067eefb commit c59f038
Show file tree
Hide file tree
Showing 3 changed files with 1,055 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cmds/swagger.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ exports.run = async function(opts) {

function error(err) {
try {
return Promise.reject(new Error(JSON.parse(err.error).description));
const parsedError = JSON.parse(err.error);
return Promise.reject(new Error(parsedError.description || parsedError.error));
} catch (e) {
return Promise.reject(new Error('There was an error uploading!'));
}
Expand Down
17 changes: 17 additions & 0 deletions test/cmds/swagger.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,23 @@ describe('rdme swagger', () => {
.then(() => mock.done());
});

it('should properly bubble up validation error if invalid swagger is uploaded', () => {
const mock = nock(config.host)
.get(`/api/v1/version/${version}`)
.basicAuth({ user: key })
.reply(200, { version: '1.0.0' })
.post('/api/v1/api-specification', body => body.match('form-data; name="spec"'))
.delayConnection(1000)
.basicAuth({ user: key })
.reply(500, {
error: 'README VALIDATION ERROR "x-samples-languages" must be of type "Array"',
});

return expect(swagger.run({ spec: './test/fixtures/invalid-swagger.json', key, version }))
.rejects.toThrow('README VALIDATION ERROR "x-samples-languages" must be of type "Array"')
.then(() => mock.done());
});

it('should return a 404 if version flag not found', () => {});

it('should request a version list if version is not found', () => {
Expand Down
Loading

0 comments on commit c59f038

Please sign in to comment.