Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly report OAS validation errors #67

Merged
merged 5 commits into from
Aug 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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