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

Commit

Permalink
πŸ› manual endpoints may not have a URL specified in the OAS spec (#233)
Browse files Browse the repository at this point in the history
* πŸ› manual endpoints may not have a URL specified in the OAS spec

* βœ… add a test case

* ♻️ call getPath only once
  • Loading branch information
dok authored and erunion committed Jul 31, 2019
1 parent 3f8b8eb commit fb80743
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
31 changes: 31 additions & 0 deletions packages/api-explorer/__tests__/Doc.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,37 @@ test('should render straight away if `appearance.splitReferenceDocs` is true', (
expect(doc.find('Waypoint').length).toBe(0);
});

test('should render a manual endpoint', () => {
const myProps = JSON.parse(JSON.stringify(props));
myProps.doc.swagger.path = '/nonexistant';
myProps.doc.api.examples = {
codes: [],
};
myProps.doc.api.params = [
{
default: 'test',
desc: 'test',
in: 'path',
name: 'test',
ref: '',
required: false,
type: 'string',
},
];

const doc = mount(
<Doc
{...myProps}
appearance={{
splitReferenceDocs: true,
}}
/>,
);

assertDocElements(doc, props.doc);
expect(doc.find('Params').length).toBe(1);
});

test('should work without a doc.swagger/doc.path/oas', () => {
const doc = { title: 'title', slug: 'slug', type: 'basic' };
const docComponent = shallow(
Expand Down
9 changes: 8 additions & 1 deletion packages/api-explorer/src/Doc.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const EndpointErrorBoundary = require('./EndpointErrorBoundary');
const markdown = require('@readme/markdown');

const Oas = require('./lib/Oas');
const { Operation } = require('./lib/Oas');
const getPath = require('./lib/get-path');
// const showCode = require('./lib/show-code');
const parseResponse = require('./lib/parse-response');
const Content = require('./block-types/Content');
Expand Down Expand Up @@ -82,7 +84,12 @@ class Doc extends React.Component {
if (this.operation) return this.operation;

const { doc } = this.props;
const operation = doc.swagger ? this.oas.operation(doc.swagger.path, doc.api.method) : null;
let operation = doc.swagger ? this.oas.operation(doc.swagger.path, doc.api.method) : null;
if (!getPath(this.oas, doc)) {
operation = new Operation(this.oas, doc.swagger.path, doc.api.method, {
parameters: doc.api.params,
});
}
this.operation = operation;
return operation;
}
Expand Down
3 changes: 2 additions & 1 deletion packages/api-explorer/src/lib/get-path-operation.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ const getPath = require('./get-path');

module.exports = function getPathOperation(swagger, doc) {
if (swagger.paths && doc.swagger) {
return getPath(swagger, doc)[doc.api.method];
const path = getPath(swagger, doc);
if (path) return path[doc.api.method];
}

return { parameters: [] };
Expand Down

0 comments on commit fb80743

Please sign in to comment.