Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
Add some safety checks in get-auth incase there's no auth
Browse files Browse the repository at this point in the history
  • Loading branch information
domharrington committed Jan 28, 2019
1 parent 7937b2a commit aea2002
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/api-explorer/__tests__/lib/get-auth.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ it('should fetch all auths from the OAS files', () => {
});
});

it('should not error if oas.components is not set', () => {
expect(() => {
getAuth({ oauthScheme: 'oauth', apiKeyScheme: 'apikey' }, { 'api-setting': {} })
}).not.toThrow();

expect(() => {
getAuth({ oauthScheme: 'oauth', apiKeyScheme: 'apikey' }, { 'api-setting': { components: {} } })
}).not.toThrow();
});

const { getSingle } = getAuth;

const topLevelUser = { apiKey: '123456', user: 'user', pass: 'pass' };
Expand Down
3 changes: 3 additions & 0 deletions packages/api-explorer/src/lib/get-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ function getAuth(user, oasFiles) {
return Object.keys(oasFiles)
.map(id => {
const oas = oasFiles[id];

if (Object.keys(oas.components || {}).length === 0) return {};

return Object.keys(oas.components.securitySchemes)
.map(scheme => {
return {
Expand Down

0 comments on commit aea2002

Please sign in to comment.