Skip to content

Commit

Permalink
Correctly match oneOf mappings when generating example values for one…
Browse files Browse the repository at this point in the history
…Of's with discriminators
  • Loading branch information
Brad Sullivan committed Nov 22, 2024
1 parent 0f5c0b3 commit 58a4a2e
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/core/plugins/json-schema-5-samples/fn/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 58a4a2e

Please sign in to comment.