diff --git a/src/core/plugins/json-schema-5-samples/fn/index.js b/src/core/plugins/json-schema-5-samples/fn/index.js index e1fcf8623fe..3a51628a8ca 100644 --- a/src/core/plugins/json-schema-5-samples/fn/index.js +++ b/src/core/plugins/json-schema-5-samples/fn/index.js @@ -351,13 +351,24 @@ export const sampleFromSchemaGeneric = (schema, config={}, exampleOverride = und schema.discriminator && Object.prototype.hasOwnProperty.call(schema.discriminator, "mapping") && schema.discriminator.mapping && - Object.prototype.hasOwnProperty.call(schema, "$$ref") && - schema.$$ref && + Object.prototype.hasOwnProperty.call(schema, "oneOf") && + schema.oneOf && schema.discriminator.propertyName === propName) { - for (let pair in schema.discriminator.mapping){ - if (schema.$$ref.search(schema.discriminator.mapping[pair]) !== -1) { - res[propName] = pair - break + + for (let option of schema.oneOf) { + if (Object.prototype.hasOwnProperty.call(option, "$$ref")) { + let found = false + for (let pair in schema.discriminator.mapping){ + if (option.$$ref.search(schema.discriminator.mapping[pair]) !== -1) { + res[propName] = pair + found = true + break + } + } + + if (found) { + break + } } } } else {