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

Commit

Permalink
Make getSchema return not just json
Browse files Browse the repository at this point in the history
  • Loading branch information
Dom Harrington committed Oct 28, 2017
1 parent 47d6192 commit ddee73f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
39 changes: 39 additions & 0 deletions packages/api-explorer-ui/__tests__/lib/get-schema.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const getSchema = require('../../src/lib/get-schema');

const schema = { type: 'string' };

test('should return the first type if there is content', () => {
expect(
getSchema({
requestBody: {
content: {
'application/json': {
schema,
},
'text/xml': {
schema: { type: 'number' },
},
},
},
}),
).toBe(schema);

expect(
getSchema({
requestBody: {
content: {
'text/xml': {
schema,
},
'application/json': {
schema: { type: 'number' },
},
},
},
}),
).toBe(schema);
});

test('should return the requestBody', () => {
expect(getSchema({ requestBody: schema })).toBe(schema);
});
3 changes: 2 additions & 1 deletion packages/api-explorer-ui/src/lib/get-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ module.exports = pathOperation => {

try {
if (pathOperation.requestBody.content) {
schema = pathOperation.requestBody.content['application/json'].schema;
const firstType = Object.keys(pathOperation.requestBody.content)[0]
schema = pathOperation.requestBody.content[firstType].schema;
} else {
schema = pathOperation.requestBody;
}
Expand Down

0 comments on commit ddee73f

Please sign in to comment.