@@ -22,7 +22,7 @@ export const ResponseSampleBody = props => {
22
22
// console.log(l);
23
23
return (
24
24
l &&
25
- ( l . type !== "array" && l . type !== "object " && p !== "errors "
25
+ ( l . type !== "array" && p !== "errors " && l . type !== "object "
26
26
? `"${ p } ": ${
27
27
p === "id"
28
28
? "1234"
@@ -34,41 +34,37 @@ export const ResponseSampleBody = props => {
34
34
} `
35
35
: `${ JSON . stringify ( l . example ? l . example : "" ) } `
36
36
} `
37
- : `"${ p } " : [` ) +
37
+ : l . type === "object" && ! l . properties
38
+ ? `"${ p } " : {`
39
+ : l . type === "array"
40
+ ? `"${ p } " : [`
41
+ : `"${ p } " :` ) +
38
42
( l . example && l . type === "array" && ! l . items
39
43
? Object . keys ( l . example ) . map ( v => {
40
44
const va = l . example [ v ] ;
41
45
return `"${ va } "` ;
42
46
} )
43
47
: "" ) +
44
48
( 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
+ } ) ) +
72
68
( l . properties &&
73
69
`{` +
74
70
Object . keys ( l . properties )
@@ -198,8 +194,10 @@ export const ResponseSampleBody = props => {
198
194
l . items . allOf [ 1 ] . properties
199
195
)
200
196
: "" ) +
201
- ( l . type === "array" || l . type === "object" || p === "errors"
197
+ ( l . type === "array" || p === "errors"
202
198
? `]`
199
+ : l . type === "object" && ! l . properties
200
+ ? `}`
203
201
: "" )
204
202
) ;
205
203
} ) }
@@ -216,8 +214,8 @@ export const ResponseSampleBody = props => {
216
214
console . log ( e ) ;
217
215
}
218
216
219
- // const finalSource = JSON.stringify(parsed, null, 2);
220
- const finalSource = sanitized ;
217
+ const finalSource = JSON . stringify ( parsed , null , 2 ) ;
218
+ // const finalSource = sanitized;
221
219
222
220
return (
223
221
context &&
0 commit comments