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

fix: bug where responses with multiple examples weren't rendered properly #599

Merged
merged 1 commit into from
Apr 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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