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

Commit

Permalink
Allow apiSetting to come in as a string
Browse files Browse the repository at this point in the history
  • Loading branch information
Dom Harrington committed Aug 23, 2018
1 parent c534b0a commit 25647b0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
18 changes: 18 additions & 0 deletions packages/api-explorer/__tests__/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,24 @@ describe('oas', () => {
expect(explorer.find('Doc').get(0).props.oas).toBe(oas);
});

it('should fetch it from `doc.api.apiSetting` if it is a string', () => {
const explorer = shallow(
<ApiExplorer
{...props}
oasFiles={{
'api-setting': oas,
}}
docs={[
Object.assign({}, baseDoc, {
api: { method: 'get', apiSetting: 'api-setting' },
}),
]}
/>,
);

expect(explorer.find('Doc').get(0).props.oas).toBe(oas);
});

it('should set it to empty object', () => {
const explorer = shallow(
<ApiExplorer
Expand Down
10 changes: 8 additions & 2 deletions packages/api-explorer/src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,15 @@ class ApiExplorer extends React.Component {
}
}
getOas(doc) {
// Get the apiSetting id either from the category, or the api if api is set
// Get the apiSetting id from the following places:
// - category.apiSetting if set and populated
// - api.apiSetting if that's a string
// - api.apiSetting._id if that's set
// This will return undefined if apiSetting is not set
const apiSetting = doc.category.apiSetting || (doc.api.apiSetting && doc.api.apiSetting._id);
const apiSetting =
doc.category.apiSetting ||
(typeof doc.api.apiSetting === 'string' && doc.api.apiSetting) ||
(typeof doc.api.apiSetting === 'object' && doc.api.apiSetting._id);

return this.props.oasFiles[apiSetting];
}
Expand Down

0 comments on commit 25647b0

Please sign in to comment.