Skip to content
Merged
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,12 @@ function sampleFromProp(

// TODO: handle discriminators

if (prop.oneOf) {
// Check for explicit example/examples first (OAS 3.1 support)
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 @@ -114,6 +119,7 @@ export const sampleFromSchema = (
let {
type,
example,
examples,
allOf,
properties,
items,
Expand All @@ -126,6 +132,11 @@ export const sampleFromSchema = (
return example;
}

// OAS 3.1 / JSON Schema: examples is an array
if (examples !== undefined && examples.length > 0) {
return examples[0];
}

if (oneOf) {
if (properties) {
const combinedSchemas = merge(schemaCopy, oneOf[0]);
Expand Down