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

Commit 1d3844b

Browse files
committed
1 parent 09d3433 commit 1d3844b

File tree

3 files changed

+45
-103
lines changed

3 files changed

+45
-103
lines changed

packages/api-explorer-ui/__tests__/SecurityInput.test.jsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,29 @@ describe('oauth2', () => {
3434
});
3535
});
3636

37+
describe('apiKey', () => {
38+
const props = {
39+
scheme: { type: 'apiKey', name: 'api_key', _key: 'api_key' },
40+
onChange: () => {},
41+
};
42+
43+
test('should send auth apiKey into onChange()', () => {
44+
const onChange = jest.fn();
45+
const securityInput = mount(<SecurityInput {...props} onChange={onChange} />);
46+
47+
securityInput.find('input').node.value = 'user';
48+
securityInput.find('input').simulate('change');
49+
50+
expect(onChange.mock.calls[0]).toEqual([
51+
{
52+
auth: {
53+
api_key: 'user',
54+
},
55+
},
56+
]);
57+
});
58+
});
59+
3760
describe('basic', () => {
3861
const props = { scheme: { type: 'basic', _key: 'test-basic' }, onChange: () => {} };
3962

packages/api-explorer-ui/lib/create-docs.js

Lines changed: 1 addition & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -29,109 +29,7 @@ module.exports = (oas, apiSetting) => {
2929
category: { apiSetting },
3030
api: { method },
3131
swagger: { path },
32-
body: `
33-
[block:textarea]
34-
{
35-
"text": "# This is text area"
36-
}
37-
[/block]
38-
[block:html]
39-
{
40-
"html": "<p>This is an html</p>"
41-
42-
}
43-
[/block]
44-
[block:api-header]
45-
{
46-
"title": "This is cool header",
47-
"sidebar": true
48-
}
49-
[/block]
50-
51-
[block:callout]
52-
{
53-
"type": "info",
54-
"title": "Callout"
55-
}
56-
[/block]
57-
58-
[block:image]
59-
{
60-
"images": [
61-
{
62-
"image": [
63-
"https://files.readme.io/924824e-fullsizeoutput_314.jpeg",
64-
"fullsizeoutput_314.jpeg",
65-
640,
66-
1136,
67-
"#c8b396"
68-
]
69-
}
70-
]
71-
}
72-
[/block]
73-
74-
[block:image]
75-
{
76-
"images": [
77-
{
78-
"image": [
79-
"https://files.readme.io/dce21f0-IMG_0418.JPG",
80-
"IMG_0418.JPG",
81-
640,
82-
1136,
83-
"#9e918d"
84-
],
85-
"caption": "*doggo*"
86-
}
87-
]
88-
}
89-
[/block]
90-
91-
[block:code]
92-
{
93-
"codes": [
94-
{
95-
"code": "whjdwhjwejhkwhjk",
96-
"language": "text",
97-
"status": 400,
98-
"name": " "
99-
},
100-
{
101-
"code": "var a = 1;",
102-
"language": "javascript"
103-
}
104-
]
105-
}
106-
[/block]
107-
108-
[block:parameters]
109-
{
110-
"data": {
111-
"0-0": "*arbitrary*",
112-
"0-1": "info",
113-
"0-2": "test",
114-
"h-0": "test",
115-
"h-1": "1",
116-
"h-2": "2"
117-
},
118-
"cols": 3,
119-
"rows": 1
120-
}
121-
[/block]
122-
123-
[block:embed]
124-
{
125-
"html": "<iframe class=\\"embedly-embed\\" src=\\"//cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FjYjDqzZ4gjY%3Ffeature%3Doembed&url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DjYjDqzZ4gjY&image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FjYjDqzZ4gjY%2Fhqdefault.jpg&key=f2aa6fc3595946d0afc3d76cbbd25dc3&type=text%2Fhtml&schema=youtube\\" width=\\"640\\" height=\\"480\\" scrolling=\\"no\\" frameborder=\\"0\\" allowfullscreen></iframe>",
126-
"url": "https://www.youtube.com/watch?v=jYjDqzZ4gjY",
127-
"title": "White kids Watch me whip school Chorus - chorus white kids singing Watch me whip",
128-
"favicon": "https://s.ytimg.com/yts/img/ringo/img/favicon-vfl8qSV2F.ico",
129-
"image": "https://i.ytimg.com/vi/jYjDqzZ4gjY/hqdefault.jpg",
130-
"sidebar": true
131-
}
132-
[/block]
133-
134-
`,
32+
body: '',
13533
});
13634
}
13735
});

packages/api-explorer-ui/src/SecurityInput.jsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,25 @@ Oauth2.defaultProps = {
5656
oauthUrl: '',
5757
};
5858

59+
function ApiKey(apiKey) {
60+
return (
61+
<div className="row">
62+
<div className="col-xs-5">
63+
<label htmlFor="apiKey">{apiKey.scheme.name}</label>
64+
</div>
65+
<div className="col-xs-7">
66+
<input type="text" onChange={e => apiKey.change(e.currentTarget.value)} />
67+
</div>
68+
</div>
69+
);
70+
}
71+
72+
ApiKey.propTypes = {
73+
scheme: PropTypes.shape({
74+
name: PropTypes.string.isRequired,
75+
}).isRequired,
76+
};
77+
5978
class Basic extends React.Component {
6079
constructor(props) {
6180
super(props);
@@ -109,6 +128,8 @@ function SecurityInput(props) {
109128
return <Oauth2 {...props} change={change} />;
110129
case 'basic':
111130
return <Basic {...props} change={change} />;
131+
case 'apiKey':
132+
return <ApiKey {...props} change={change} />;
112133
default:
113134
return <span />;
114135
}

0 commit comments

Comments
 (0)