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

Commit

Permalink
fix: bug where responses with multiple examples weren't rendered prop…
Browse files Browse the repository at this point in the history
…erly (#599)
  • Loading branch information
erunion authored Apr 13, 2020
1 parent c40a910 commit ef18f54
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
14 changes: 4 additions & 10 deletions packages/api-explorer/__tests__/lib/create-code-shower.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,21 +103,15 @@ describe('createCodeShower', () => {
{
label: 'cat',
code: encodeJsonExample({
summary: 'An example of a cat',
value: {
name: 'Fluffy',
petType: 'Cat',
},
name: 'Fluffy',
petType: 'Cat',
}),
},
{
label: 'dog',
code: encodeJsonExample({
summary: "An example of a dog with a cat's name",
value: {
name: 'Puma',
petType: 'Dog',
},
name: 'Puma',
petType: 'Dog',
}),
},
],
Expand Down
11 changes: 10 additions & 1 deletion packages/api-explorer/src/lib/create-code-shower.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,18 @@ function getMultipleExamples(response, lang) {

const { examples } = response.content[lang];
return Object.keys(examples).map(key => {
let example = examples[key];
if (typeof example === 'object') {
if ('value' in example) {
example = example.value;
}

example = JSON.stringify(example, undefined, 2);
}

return {
label: key,
code: typeof examples[key] === 'object' ? JSON.stringify(examples[key], undefined, 2) : examples[key],
code: example,
};
});
}
Expand Down

0 comments on commit ef18f54

Please sign in to comment.