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

Commit ddee73f

Browse files
author
Dom Harrington
committed
Make getSchema return not just json
1 parent 47d6192 commit ddee73f

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const getSchema = require('../../src/lib/get-schema');
2+
3+
const schema = { type: 'string' };
4+
5+
test('should return the first type if there is content', () => {
6+
expect(
7+
getSchema({
8+
requestBody: {
9+
content: {
10+
'application/json': {
11+
schema,
12+
},
13+
'text/xml': {
14+
schema: { type: 'number' },
15+
},
16+
},
17+
},
18+
}),
19+
).toBe(schema);
20+
21+
expect(
22+
getSchema({
23+
requestBody: {
24+
content: {
25+
'text/xml': {
26+
schema,
27+
},
28+
'application/json': {
29+
schema: { type: 'number' },
30+
},
31+
},
32+
},
33+
}),
34+
).toBe(schema);
35+
});
36+
37+
test('should return the requestBody', () => {
38+
expect(getSchema({ requestBody: schema })).toBe(schema);
39+
});

packages/api-explorer-ui/src/lib/get-schema.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ module.exports = pathOperation => {
33

44
try {
55
if (pathOperation.requestBody.content) {
6-
schema = pathOperation.requestBody.content['application/json'].schema;
6+
const firstType = Object.keys(pathOperation.requestBody.content)[0]
7+
schema = pathOperation.requestBody.content[firstType].schema;
78
} else {
89
schema = pathOperation.requestBody;
910
}

0 commit comments

Comments
 (0)