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

🐛 manual endpoints may not have a URL specified in the OAS spec #233

Merged
merged 3 commits into from
Jul 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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