@@ -249,8 +249,6 @@ export function schemaToSampleObj(schema, config = { }) {
249
249
250
250
if ( schema . example ) {
251
251
obj [ key ] = schema . example ;
252
- } else if ( schema . examples && schema . example . length > 0 ) {
253
- obj [ key ] = schema . examples [ 0 ] ;
254
252
} else {
255
253
obj [ key ] = schemaToSampleObj ( schema . properties [ key ] , config ) ;
256
254
}
@@ -268,7 +266,7 @@ export function schemaToSampleObj(schema, config = { }) {
268
266
if ( schema . properties [ key ] . readOnly && ! config . includeReadOnly ) { continue ; }
269
267
if ( schema . properties [ key ] . writeOnly && ! config . includeWriteOnly ) { continue ; }
270
268
if ( schema . properties [ key ] . type === 'array' || schema . properties [ key ] . items ) {
271
- if ( schema . properties [ key ] . items . example ) {
269
+ if ( schema . properties [ key ] ? .items ? .example ) { // schemas and properties support single example but not multiple examples.
272
270
obj [ key ] = [ schema . properties [ key ] . items . example ] ;
273
271
} else {
274
272
obj [ key ] = [ schemaToSampleObj ( schema . properties [ key ] . items , config ) ] ;
@@ -278,18 +276,15 @@ export function schemaToSampleObj(schema, config = { }) {
278
276
if ( schema . example ) {
279
277
obj [ key ] = schema . example ;
280
278
break ;
281
- } else if ( schema . examples && schema . example . length > 0 ) {
282
- obj [ key ] = schema . examples [ 0 ] ;
283
- break ;
284
279
} else {
285
280
obj [ key ] = schemaToSampleObj ( schema . properties [ key ] , config ) ;
286
281
}
287
282
}
288
283
} else if ( schema . type === 'array' || schema . items ) {
289
284
if ( schema . example ) {
290
285
obj = schema . example ;
291
- } else if ( schema . examples && schema . example . length > 0 ) {
292
- obj = schema . examples [ 0 ] ;
286
+ } else if ( schema . items ?. example ) { // schemas and properties support single example but not multiple examples.
287
+ obj = [ schema . items . example ] ;
293
288
} else {
294
289
obj = [ schemaToSampleObj ( schema . items , config ) ] ;
295
290
}
0 commit comments