From 5055241e7858cac00e4c791e306ddd7bb65562fa Mon Sep 17 00:00:00 2001 From: Lukasz Gornicki Date: Tue, 16 Jun 2020 16:44:40 +0200 Subject: [PATCH] feat: add discriminator function to schema model (#89) --- lib/models/schema.js | 7 +++++++ test/models/schema_test.js | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/models/schema.js b/lib/models/schema.js index 7704e0245..e90e4c20f 100644 --- a/lib/models/schema.js +++ b/lib/models/schema.js @@ -344,6 +344,13 @@ class Schema extends Base { return this._json.deprecated; } + /** + * @returns {string} + */ + discriminator() { + return this._json.discriminator; + } + /** * @returns {boolean} */ diff --git a/test/models/schema_test.js b/test/models/schema_test.js index b430b72dd..23cbcf961 100644 --- a/test/models/schema_test.js +++ b/test/models/schema_test.js @@ -492,6 +492,15 @@ describe('Schema', function() { }); }); + describe('#discriminator()', function() { + it('should return a string', function() { + const doc = { type: 'string', discriminator: 'someType' }; + const d = new Schema(doc); + expect(typeof d.discriminator()).to.be.equal('string'); + expect(d.discriminator()).to.be.equal(doc.discriminator); + }); + }); + describe('#readOnly()', function() { it('should return a boolean', function() { const doc = { type: 'string', readOnly: true };