Skip to content

Commit 8848430

Browse files
author
Alban Bailly
committed
format missing data
1 parent 1212e4f commit 8848430

File tree

1 file changed

+30
-32
lines changed

1 file changed

+30
-32
lines changed

src/components/2_molecules/ResponseSampleBody.js

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const ResponseSampleBody = props => {
2222
// console.log(l);
2323
return (
2424
l &&
25-
(l.type !== "array" && l.type !== "object" && p !== "errors"
25+
(l.type !== "array" && p !== "errors" && l.type !== "object"
2626
? `"${p}": ${
2727
p === "id"
2828
? "1234"
@@ -34,41 +34,37 @@ export const ResponseSampleBody = props => {
3434
}`
3535
: `${JSON.stringify(l.example ? l.example : "")}`
3636
}`
37-
: `"${p}" : [`) +
37+
: l.type === "object" && !l.properties
38+
? `"${p}" : {`
39+
: l.type === "array"
40+
? `"${p}" : [`
41+
: `"${p}" :`) +
3842
(l.example && l.type === "array" && !l.items
3943
? Object.keys(l.example).map(v => {
4044
const va = l.example[v];
4145
return `"${va}"`;
4246
})
4347
: "") +
4448
(l.oneOf &&
45-
l.oneOf.map(oo =>
46-
oo.properties
47-
? Object.keys(oo.properties).map(oop => {
48-
const data = oo.properties[oop];
49-
return `
50-
"${oop}": ${
51-
data.example
52-
? JSON.stringify(data.example)
53-
: data.type === "array" && data.items
54-
? "[" +
55-
Object.keys(data.items.properties).map(di => {
56-
const dis = data.items.properties[di];
57-
console.log(data.items);
58-
return `
59-
"${di}": ${
60-
dis.example
61-
? JSON.stringify(dis.example)
62-
: '""'
63-
}
64-
`;
65-
}) +
66-
"]"
67-
: '""'
68-
}`;
69-
})
70-
: ""
71-
)) +
49+
Object.keys(l.oneOf[0].properties).map(oop => {
50+
const data = l.oneOf[0].properties[oop];
51+
return `
52+
"${oop}": ${
53+
data.example
54+
? JSON.stringify(data.example)
55+
: data.type === "array" && data.items.type === "object"
56+
? "[{" +
57+
Object.keys(data.items.properties).map(di => {
58+
const dis = data.items.properties[di];
59+
return `
60+
"${di}": ${JSON.stringify(
61+
dis.example ? dis.example : ""
62+
)}`;
63+
}) +
64+
"}]"
65+
: '""'
66+
}`;
67+
})) +
7268
(l.properties &&
7369
`{` +
7470
Object.keys(l.properties)
@@ -198,8 +194,10 @@ export const ResponseSampleBody = props => {
198194
l.items.allOf[1].properties
199195
)
200196
: "") +
201-
(l.type === "array" || l.type === "object" || p === "errors"
197+
(l.type === "array" || p === "errors"
202198
? `]`
199+
: l.type === "object" && !l.properties
200+
? `}`
203201
: "")
204202
);
205203
})}
@@ -216,8 +214,8 @@ export const ResponseSampleBody = props => {
216214
console.log(e);
217215
}
218216

219-
// const finalSource = JSON.stringify(parsed, null, 2);
220-
const finalSource = sanitized;
217+
const finalSource = JSON.stringify(parsed, null, 2);
218+
// const finalSource = sanitized;
221219

222220
return (
223221
context &&

0 commit comments

Comments
 (0)