Skip to content

Commit

Permalink
feat: Add externalDocs function to Schema model (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcmellado authored Jun 29, 2020
1 parent 54e811c commit 8489043
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/models/schema.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { addExtensions } = require('../utils');
const Base = require('./base');
const ExternalDocs = require('./external-docs');

/**
* Implements functions to deal with a Schema object.
Expand Down Expand Up @@ -351,6 +352,14 @@ class Schema extends Base {
return this._json.discriminator;
}

/**
* @returns {ExternalDocs}
*/
externalDocs() {
if (!this._json.externalDocs) return null;
return new ExternalDocs(this._json.externalDocs);
}

/**
* @returns {boolean}
*/
Expand Down
14 changes: 14 additions & 0 deletions test/models/schema_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,20 @@ describe('Schema', function() {
});
});

describe('#externalDocs()', function() {
it('should return null', function() {
const doc = { type: 'string' };
const d = new Schema(doc);
expect(d.externalDocs()).to.be.equal(null);
});
it('should return a ExternalDocs object', function() {
const doc = { type: 'string', externalDocs: { description: 'someDescription', url: 'someUrl' } };
const d = new Schema(doc);
expect(d.externalDocs().constructor.name).to.be.equal('ExternalDocs');
expect(d.externalDocs().json()).to.be.equal(doc.externalDocs);
});
});

describe('#readOnly()', function() {
it('should return a boolean', function() {
const doc = { type: 'string', readOnly: true };
Expand Down

0 comments on commit 8489043

Please sign in to comment.