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

Commit fb80743

Browse files
dokerunion
authored andcommitted
πŸ› manual endpoints may not have a URL specified in the OAS spec (#233)
* πŸ› manual endpoints may not have a URL specified in the OAS spec * βœ… add a test case * ♻️ call getPath only once
1 parent 3f8b8eb commit fb80743

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

β€Žpackages/api-explorer/__tests__/Doc.test.jsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,37 @@ test('should render straight away if `appearance.splitReferenceDocs` is true', (
6565
expect(doc.find('Waypoint').length).toBe(0);
6666
});
6767

68+
test('should render a manual endpoint', () => {
69+
const myProps = JSON.parse(JSON.stringify(props));
70+
myProps.doc.swagger.path = '/nonexistant';
71+
myProps.doc.api.examples = {
72+
codes: [],
73+
};
74+
myProps.doc.api.params = [
75+
{
76+
default: 'test',
77+
desc: 'test',
78+
in: 'path',
79+
name: 'test',
80+
ref: '',
81+
required: false,
82+
type: 'string',
83+
},
84+
];
85+
86+
const doc = mount(
87+
<Doc
88+
{...myProps}
89+
appearance={{
90+
splitReferenceDocs: true,
91+
}}
92+
/>,
93+
);
94+
95+
assertDocElements(doc, props.doc);
96+
expect(doc.find('Params').length).toBe(1);
97+
});
98+
6899
test('should work without a doc.swagger/doc.path/oas', () => {
69100
const doc = { title: 'title', slug: 'slug', type: 'basic' };
70101
const docComponent = shallow(

β€Žpackages/api-explorer/src/Doc.jsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ const EndpointErrorBoundary = require('./EndpointErrorBoundary');
1717
const markdown = require('@readme/markdown');
1818

1919
const Oas = require('./lib/Oas');
20+
const { Operation } = require('./lib/Oas');
21+
const getPath = require('./lib/get-path');
2022
// const showCode = require('./lib/show-code');
2123
const parseResponse = require('./lib/parse-response');
2224
const Content = require('./block-types/Content');
@@ -82,7 +84,12 @@ class Doc extends React.Component {
8284
if (this.operation) return this.operation;
8385

8486
const { doc } = this.props;
85-
const operation = doc.swagger ? this.oas.operation(doc.swagger.path, doc.api.method) : null;
87+
let operation = doc.swagger ? this.oas.operation(doc.swagger.path, doc.api.method) : null;
88+
if (!getPath(this.oas, doc)) {
89+
operation = new Operation(this.oas, doc.swagger.path, doc.api.method, {
90+
parameters: doc.api.params,
91+
});
92+
}
8693
this.operation = operation;
8794
return operation;
8895
}

β€Žpackages/api-explorer/src/lib/get-path-operation.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ const getPath = require('./get-path');
22

33
module.exports = function getPathOperation(swagger, doc) {
44
if (swagger.paths && doc.swagger) {
5-
return getPath(swagger, doc)[doc.api.method];
5+
const path = getPath(swagger, doc);
6+
if (path) return path[doc.api.method];
67
}
78

89
return { parameters: [] };

0 commit comments

Comments
Β (0)