From 1319da391ba7c63a8e9985a5d3f08c32c32222f6 Mon Sep 17 00:00:00 2001 From: Dom Harrington Date: Thu, 11 Jan 2018 15:32:17 -0800 Subject: [PATCH] Fix for box. Their apiSetting id isnt stored on the category it's stored on the api.apiSetting --- .../api-explorer/__tests__/index.test.jsx | 59 +++++++++++++++++++ packages/api-explorer/src/index.jsx | 9 ++- 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/packages/api-explorer/__tests__/index.test.jsx b/packages/api-explorer/__tests__/index.test.jsx index ab1c9fdc4..10af38a6d 100644 --- a/packages/api-explorer/__tests__/index.test.jsx +++ b/packages/api-explorer/__tests__/index.test.jsx @@ -88,3 +88,62 @@ describe('selected language', () => { expect(explorer.state('language')).toBe('curl'); }); }); + +describe('oas', () => { + const baseDoc = { + _id: 1, + title: 'title', + slug: 'slug', + type: 'endpoint', + category: {}, + api: { method: 'get' }, + }; + + // Swagger apis and some legacies + it('should fetch it from `doc.category.apiSetting`', () => { + const explorer = shallow( + , + ); + + expect(explorer.find('Doc').get(0).props.oas).toBe(oas); + }); + + // Some other legacy APIs where Endpoints are created in arbitrary categories + it('should fetch it from `doc.api.apiSetting._id`', () => { + const explorer = shallow( + , + ); + + expect(explorer.find('Doc').get(0).props.oas).toBe(oas); + }); + + it('should set it to empty object', () => { + const explorer = shallow( + , + ); + + expect(explorer.find('Doc').get(0).props.oas).toEqual({}); + }); +}); diff --git a/packages/api-explorer/src/index.jsx b/packages/api-explorer/src/index.jsx index b948c9c46..69d2bf53a 100644 --- a/packages/api-explorer/src/index.jsx +++ b/packages/api-explorer/src/index.jsx @@ -26,6 +26,13 @@ class ApiExplorer extends React.Component { return 'curl'; } } + getOas(doc) { + // Get the apiSetting id either from the category, or the api if api is set + // This will return undefined if apiSetting is not set + const apiSetting = doc.category.apiSetting || (doc.api.apiSetting && doc.api.apiSetting._id); + + return this.props.oasFiles[apiSetting]; + } render() { const theme = this.props.flags.stripe ? 'stripe' : ''; return ( @@ -38,7 +45,7 @@ class ApiExplorer extends React.Component {