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

Commit 5384bd3

Browse files
authored
fix: stop rendering array keys in json content (#1177)
1 parent 4b86ada commit 5384bd3

File tree

6 files changed

+208
-1
lines changed

6 files changed

+208
-1
lines changed

packages/api-explorer/__tests__/ResponseBody.test.jsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,25 @@ describe('Response body', () => {
5656
expect(responseBody.find('.react-json-view')).toHaveLength(1);
5757
});
5858

59+
it('should not display array keys on json responses', async () => {
60+
props.result = await parseResponse(
61+
{
62+
log: {
63+
entries: [{ request: { url: 'http://petstore.swagger.io/v2/pet', method: 'POST', headers: [] } }],
64+
},
65+
},
66+
new FetchResponse(JSON.stringify([{ user: { email: 'test@example.com' } }]), {
67+
headers: {
68+
'content-type': 'application/json; charset=utf-8',
69+
},
70+
})
71+
);
72+
73+
const responseBody = mount(<ResponseBody {...props} oas={oas} />);
74+
75+
expect(responseBody.find('.react-json-view').text()).toBe('[{...}]');
76+
});
77+
5978
it('should not display json viewer if invalid json', async () => {
6079
props.result = await parseResponse(
6180
{

packages/api-explorer/__tests__/ResponseExample.test.jsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,35 @@ describe('has examples', () => {
8787
expect(comp.find('pre').at(0).render().find('.react-json-view')).toHaveLength(1);
8888
});
8989

90+
it('should not render array keys in json', () => {
91+
const exampleOas = new Oas(exampleResults);
92+
const operation = exampleOas.operation('/results', 'get');
93+
94+
const examples = [
95+
{
96+
status: '200',
97+
languages: [
98+
{
99+
language: 'application/json',
100+
code: JSON.stringify([
101+
{
102+
user: {
103+
email: 'test@example.com',
104+
name: 'Test user name',
105+
},
106+
},
107+
]),
108+
multipleExamples: false,
109+
},
110+
],
111+
},
112+
];
113+
114+
const comp = shallow(<ResponseExample {...props} examples={examples} oas={exampleOas} operation={operation} />);
115+
116+
expect(comp.find('pre').at(0).render().find('.react-json-view').text()).toBe('[{"user":{...}}]');
117+
});
118+
90119
it('should not fail to parse invalid json and instead show the standard syntax highlighter', () => {
91120
const exampleOas = new Oas(string);
92121
const operation = exampleOas.operation('/format-uuid', 'get');

packages/api-explorer/package-lock.json

Lines changed: 157 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/api-explorer/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"prop-types": "^15.7.2",
3636
"react-copy-to-clipboard": "^5.0.1",
3737
"react-debounce-input": "^3.2.0",
38-
"react-json-view": "^1.19.1",
38+
"react-json-view": "^1.21.1",
3939
"react-waypoint": "^9.0.2",
4040
"whatwg-fetch": "^3.0.0"
4141
},

packages/api-explorer/src/ResponseBody.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ function Authorized({ result }) {
1818
<ReactJson
1919
collapsed={1}
2020
collapseStringsAfterLength={100}
21+
displayArrayKey={false}
2122
displayDataTypes={false}
2223
displayObjectSize={false}
2324
enableClipboard={false}

packages/api-explorer/src/ResponseExample.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ function getReactJson(example, current) {
2222
key={example.code}
2323
collapsed={2}
2424
collapseStringsAfterLength={100}
25+
displayArrayKey={false}
2526
displayDataTypes={false}
2627
displayObjectSize={false}
2728
enableClipboard={false}

0 commit comments

Comments
 (0)