From d11a25ae76f128fc1ceedfef91d390cb23944936 Mon Sep 17 00:00:00 2001 From: Brian Le Date: Sun, 10 May 2020 14:32:51 +0100 Subject: [PATCH 1/4] [tests] Add test --- test/mixed.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test/mixed.js b/test/mixed.js index 5a30e2528..1b8e5bf90 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', }, + whitelist: ['a', 'b'], + blacklist: [{ + type: 'ref', + key: 'foo' + }] }, }, }); From ef5d6dd9fd00e0369a3973078caa790dd1277080 Mon Sep 17 00:00:00 2001 From: Brian Le Date: Sun, 10 May 2020 14:37:47 +0100 Subject: [PATCH 2/4] Expose blacklist and whitelist values --- src/mixed.js | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/mixed.js b/src/mixed.js index 64e3061f2..0bc8f32be 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.whitelist = next._whitelist.describe(); + if (next._blacklist.size) description.blacklist = next._blacklist.describe(); + + return description; }, defined(message = locale.defined) { From 0d378bcbe4f542cd18d8fd291775443f17d39b48 Mon Sep 17 00:00:00 2001 From: Brian Le Date: Mon, 11 May 2020 14:46:49 +0100 Subject: [PATCH 3/4] Add tests --- test/mixed.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/mixed.js b/test/mixed.js index 1b8e5bf90..af6af09c4 100644 --- a/test/mixed.js +++ b/test/mixed.js @@ -928,8 +928,8 @@ describe('Mixed Types ', () => { meta: { input: 'foo', }, - whitelist: ['a', 'b'], - blacklist: [{ + oneOf: ['a', 'b'], + notOneOf: [{ type: 'ref', key: 'foo' }] From 37e743d7241743705a46ba7d2c40e44a81cdfa82 Mon Sep 17 00:00:00 2001 From: Brian Le Date: Mon, 11 May 2020 14:47:43 +0100 Subject: [PATCH 4/4] whitelist -> oneOf, blacklist -> notOneOf --- src/mixed.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mixed.js b/src/mixed.js index 0bc8f32be..e81d98c9e 100644 --- a/src/mixed.js +++ b/src/mixed.js @@ -550,8 +550,8 @@ const proto = (SchemaType.prototype = { ), } - if (next._whitelist.size) description.whitelist = next._whitelist.describe(); - if (next._blacklist.size) description.blacklist = next._blacklist.describe(); + if (next._whitelist.size) description.oneOf = next._whitelist.describe(); + if (next._blacklist.size) description.notOneOf = next._blacklist.describe(); return description; },