File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -369,6 +369,18 @@ paths:
369
369
amount: 700,
370
370
currency: INR
371
371
}
372
+ /object-containg-array-property-with-example :
373
+ get :
374
+ summary : Object schema with array type property containing example
375
+ tags :
376
+ - Providing Examples
377
+ responses :
378
+ 200 :
379
+ description : Object with array type property containing example
380
+ content :
381
+ application/json :
382
+ schema :
383
+ $ref : " #/components/schemas/ObjectWithArrayPropExample"
372
384
components :
373
385
schemas :
374
386
cost :
@@ -417,3 +429,17 @@ components:
417
429
example :
418
430
name : name-1
419
431
age : 1
432
+ ObjectWithArrayPropExample :
433
+ type : object
434
+ properties :
435
+ numberProp :
436
+ type : number
437
+ example : 1000
438
+ stringProp :
439
+ type : string
440
+ enum : [value0, value1]
441
+ arrayProp :
442
+ type : array
443
+ items :
444
+ type : number
445
+ example : [0, 1, 2]
Original file line number Diff line number Diff line change @@ -266,7 +266,9 @@ export function schemaToSampleObj(schema, config = { }) {
266
266
if ( schema . properties [ key ] . readOnly && ! config . includeReadOnly ) { continue ; }
267
267
if ( schema . properties [ key ] . writeOnly && ! config . includeWriteOnly ) { continue ; }
268
268
if ( schema . properties [ key ] . type === 'array' || schema . properties [ key ] . items ) {
269
- if ( schema . properties [ key ] ?. items ?. example ) { // schemas and properties support single example but not multiple examples.
269
+ if ( schema . properties [ key ] . example ) {
270
+ obj [ key ] = schema . properties [ key ] . example ;
271
+ } else if ( schema . properties [ key ] ?. items ?. example ) { // schemas and properties support single example but not multiple examples.
270
272
obj [ key ] = [ schema . properties [ key ] . items . example ] ;
271
273
} else {
272
274
obj [ key ] = [ schemaToSampleObj ( schema . properties [ key ] . items , config ) ] ;
You can’t perform that action at this time.
0 commit comments