Skip to content

Commit

Permalink
feat: add discriminator function to schema model (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
derberg authored Jun 16, 2020
1 parent 580df7e commit 5055241
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/models/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,13 @@ class Schema extends Base {
return this._json.deprecated;
}

/**
* @returns {string}
*/
discriminator() {
return this._json.discriminator;
}

/**
* @returns {boolean}
*/
Expand Down
9 changes: 9 additions & 0 deletions test/models/schema_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down

0 comments on commit 5055241

Please sign in to comment.