Skip to content

Commit fcb9f15

Browse files
committed
Merge branch 'master' of https://github.com/mrin9/RapiDoc
2 parents 6c67645 + d82ab93 commit fcb9f15

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

docs/specs/examples.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,18 @@ paths:
369369
amount: 700,
370370
currency: INR
371371
}
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"
372384
components:
373385
schemas:
374386
cost:
@@ -417,3 +429,17 @@ components:
417429
example:
418430
name: name-1
419431
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]

src/utils/schema-utils.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,9 @@ export function schemaToSampleObj(schema, config = { }) {
266266
if (schema.properties[key].readOnly && !config.includeReadOnly) { continue; }
267267
if (schema.properties[key].writeOnly && !config.includeWriteOnly) { continue; }
268268
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.
270272
obj[key] = [schema.properties[key].items.example];
271273
} else {
272274
obj[key] = [schemaToSampleObj(schema.properties[key].items, config)];

0 commit comments

Comments
 (0)