diff --git a/src/mixed.js b/src/mixed.js index 64e3061f2..e81d98c9e 100644 --- a/src/mixed.js +++ b/src/mixed.js @@ -17,6 +17,17 @@ class RefSet { this.list = new Set(); this.refs = new Map(); } + get size() { + return this.list.size + this.refs.size; + } + describe() { + const description = []; + + for (const item of this.list) description.push(item); + for (const [, ref] of this.refs) description.push(ref.describe()); + + return description; + } toArray() { return toArray(this.list).concat(toArray(this.refs.values())); } @@ -528,8 +539,7 @@ const proto = (SchemaType.prototype = { describe() { const next = this.clone(); - - return { + const description = { type: next._type, meta: next._meta, label: next._label, @@ -538,7 +548,12 @@ const proto = (SchemaType.prototype = { .filter( (n, idx, list) => list.findIndex(c => c.name === n.name) === idx, ), - }; + } + + if (next._whitelist.size) description.oneOf = next._whitelist.describe(); + if (next._blacklist.size) description.notOneOf = next._blacklist.describe(); + + return description; }, defined(message = locale.defined) { diff --git a/test/mixed.js b/test/mixed.js index 5a30e2528..af6af09c4 100644 --- a/test/mixed.js +++ b/test/mixed.js @@ -888,7 +888,9 @@ describe('Mixed Types ', () => { bar: string() .max(2) .meta({ input: 'foo' }) - .label('str!'), + .label('str!') + .oneOf(['a', 'b']) + .notOneOf([ref('foo')]), }).describe(); desc.should.eql({ @@ -926,6 +928,11 @@ describe('Mixed Types ', () => { meta: { input: 'foo', }, + oneOf: ['a', 'b'], + notOneOf: [{ + type: 'ref', + key: 'foo' + }] }, }, });