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

Commit fc4d37f

Browse files
author
Dom Harrington
committed
Make oas.prepareSecurity() just return an empty object instead of null
1 parent ac576e8 commit fc4d37f

File tree

3 files changed

+7
-14
lines changed

3 files changed

+7
-14
lines changed

packages/api-explorer-ui/__tests__/lib/Oas.test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,18 +171,18 @@ describe('operation.prepareSecurity()', () => {
171171

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

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

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

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

packages/api-explorer-ui/src/AuthBox.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class AuthBox extends React.Component {
6262
render() {
6363
const { authInputRef, operation, onSubmit, open, needsAuth, toggle } = this.props;
6464

65-
if (!operation.prepareSecurity()) return null;
65+
if (Object.keys(operation.prepareSecurity()).length === 0) return null;
6666

6767
return (
6868
<div className={classNames('hub-auth-dropdown', 'simple-dropdown', { open })}>

packages/api-explorer-ui/src/lib/Oas.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ class Operation {
1515
prepareSecurity() {
1616
const securityRequirements = this.getSecurity();
1717

18-
if (!securityRequirements.length) {
19-
return null;
20-
}
21-
2218
return securityRequirements
2319
.map(requirement => {
2420
let keys;
@@ -62,9 +58,6 @@ class Operation {
6258
if (!prev[security.type]) prev[security.type] = [];
6359
prev[security.type].push(security.security);
6460
});
65-
if (Object.keys(prev).length === 0) {
66-
return null;
67-
}
6861
return prev;
6962
}, {});
7063
}

0 commit comments

Comments
 (0)