Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ function sampleFromProp(

// TODO: handle discriminators

if (prop.oneOf) {
if (prop.example !== undefined) {
obj[name] = prop.example;
} else if (prop.examples !== undefined && prop.examples.length > 0) {
obj[name] = prop.examples[0];
} else if (prop.oneOf) {
obj[name] = sampleFromSchema(prop.oneOf[0], context);
} else if (prop.anyOf) {
obj[name] = sampleFromSchema(prop.anyOf[0], context);
Expand All @@ -111,11 +115,15 @@ export const sampleFromSchema = (
try {
// deep copy schema before processing
let schemaCopy = JSON.parse(JSON.stringify(schema));
let { type, example, allOf, properties, items, oneOf, anyOf } = schemaCopy;
let { type, example, examples, allOf, properties, items, oneOf, anyOf } =
schemaCopy;

if (example !== undefined) {
return example;
}
if (examples !== undefined && examples.length > 0) {
return examples[0];
}

if (oneOf) {
if (properties) {
Expand Down