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

Commit

Permalink
Make oas.prepareSecurity() just return an empty object instead of null
Browse files Browse the repository at this point in the history
  • Loading branch information
Dom Harrington committed Nov 2, 2017
1 parent ac576e8 commit fc4d37f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 14 deletions.
12 changes: 6 additions & 6 deletions packages/api-explorer-ui/__tests__/lib/Oas.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,18 +171,18 @@ describe('operation.prepareSecurity()', () => {

test('should throw if attempting to use a non-existent scheme');

test('should return null if no security', () => {
test('should return empty object if no security', () => {
const operation = new Oas(multipleSecurities).operation('/no-auth', 'post');
expect(operation.prepareSecurity()).toBe(null);
expect(Object.keys(operation.prepareSecurity()).length).toBe(0);
});

test('should return null if security scheme doesnt exist', () => {
test('should return empty object if security scheme doesnt exist', () => {
const operation = new Oas(multipleSecurities).operation('/unknown-scheme', 'post');
expect(operation.prepareSecurity()).toBe(null);
expect(Object.keys(operation.prepareSecurity()).length).toBe(0);
});

test('should return null if security scheme type doesnt exist', () => {
test('should return empty if security scheme type doesnt exist', () => {
const operation = new Oas(multipleSecurities).operation('/unknown-auth-type', 'post');
expect(operation.prepareSecurity()).toBe(null);
expect(Object.keys(operation.prepareSecurity()).length).toBe(0);
});
});
2 changes: 1 addition & 1 deletion packages/api-explorer-ui/src/AuthBox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class AuthBox extends React.Component {
render() {
const { authInputRef, operation, onSubmit, open, needsAuth, toggle } = this.props;

if (!operation.prepareSecurity()) return null;
if (Object.keys(operation.prepareSecurity()).length === 0) return null;

return (
<div className={classNames('hub-auth-dropdown', 'simple-dropdown', { open })}>
Expand Down
7 changes: 0 additions & 7 deletions packages/api-explorer-ui/src/lib/Oas.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ class Operation {
prepareSecurity() {
const securityRequirements = this.getSecurity();

if (!securityRequirements.length) {
return null;
}

return securityRequirements
.map(requirement => {
let keys;
Expand Down Expand Up @@ -62,9 +58,6 @@ class Operation {
if (!prev[security.type]) prev[security.type] = [];
prev[security.type].push(security.security);
});
if (Object.keys(prev).length === 0) {
return null;
}
return prev;
}, {});
}
Expand Down

0 comments on commit fc4d37f

Please sign in to comment.