Skip to content

Commit

Permalink
docs: add schema options to API docs
Browse files Browse the repository at this point in the history
Fix #8012
  • Loading branch information
vkarpov15 committed Oct 12, 2019
1 parent cdfb507 commit 973b1e0
Show file tree
Hide file tree
Showing 12 changed files with 140 additions and 25 deletions.
19 changes: 10 additions & 9 deletions docs/api.pug
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@ block content
div.api-nav
div.api-nav-content
each item in docs
div.nav-item(id='nav-' + item.name)
div.nav-item-title
a(href='./api/' + item.name.toLowerCase() + '.html')
| #{item.name}
ul.nav-item-sub
each prop in item.props
li
a(href='./api/' + item.name.toLowerCase() + '.html#' + prop.anchorId)
| #{prop.string}
- if (!item.hideFromNav)
div.nav-item(id='nav-' + item.name)
div.nav-item-title
a(href='./api/' + item.name.toLowerCase() + '.html')
| #{item.name}
ul.nav-item-sub
each prop in item.props
li
a(href='./api/' + item.name.toLowerCase() + '.html#' + prop.anchorId)
| #{prop.string}

each item in docs
hr.separate-api
Expand Down
29 changes: 15 additions & 14 deletions docs/api_split.pug
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,21 @@ block content
div.api-nav
div.api-nav-content
each item in docs
div.nav-item(id='nav-' + item.name)
- if (item.name === name)
div.nav-item-title(style="font-weight: bold")
a(href=item.name.toLowerCase() + '.html')
| #{item.name}
ul.nav-item-sub
each prop in item.props
li
a(href='#' + prop.anchorId)
| #{prop.string}
- else
div.nav-item-title
a(href=item.name.toLowerCase() + '.html')
| #{item.name}
- if (!item.hideFromNav || item.name === name)
div.nav-item(id='nav-' + item.name)
- if (item.name === name)
div.nav-item-title(style="font-weight: bold")
a(href=item.name.toLowerCase() + '.html')
| #{item.name}
ul.nav-item-sub
each prop in item.props
li
a(href='#' + prop.anchorId)
| #{prop.string}
- else
div.nav-item-title
a(href=item.name.toLowerCase() + '.html')
| #{item.name}

div.api-content
ul
Expand Down
16 changes: 15 additions & 1 deletion docs/source/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ const files = [
'lib/virtualtype.js',
'lib/error/index.js',
'lib/types/core_array.js',
'lib/schema/SingleNestedPath.js'
'lib/schema/SingleNestedPath.js',
'lib/options/SchemaTypeOptions.js',
'lib/options/SchemaArrayOptions.js',
'lib/options/SchemaBufferOptions.js',
'lib/options/SchemaDateOptions.js',
'lib/options/SchemaNumberOptions.js',
'lib/options/SchemaObjectIdOptions.js',
'lib/options/SchemaStringOptions.js'
];

module.exports = {
Expand Down Expand Up @@ -83,6 +90,9 @@ function parse() {
ctx.name = str;
ctx.string = `${ctx.constructor}.prototype.${ctx.name}`;
break;
case 'type':
ctx.type = Array.isArray(tag.types) ? tag.types.join('|') : tag.types;
break;
case 'static':
ctx.type = 'property';
ctx.static = true;
Expand Down Expand Up @@ -164,6 +174,10 @@ function parse() {
}
});

if (props.file.startsWith('lib/options')) {
data.hideFromNav = true;
}

out.push(data);
}
}
Expand Down
9 changes: 9 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,15 @@ Mongoose.prototype.now = function now() { return new Date(); };

Mongoose.prototype.CastError = require('./error/cast');

/**
* The constructor used for schematype options
*
* @method SchemaTypeOptions
* @api public
*/

Mongoose.prototype.SchemaTypeOptions = require('./options/SchemaTypeOptions');

/**
* The [node-mongodb-native](https://github.com/mongodb/node-mongodb-native) driver Mongoose uses.
*
Expand Down
13 changes: 13 additions & 0 deletions lib/options/SchemaArrayOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

const SchemaTypeOptions = require('./SchemaTypeOptions');

/**
* The options defined on an Array schematype.
*
* ####Example:
*
* const schema = new Schema({ tags: [String] });
* schema.path('tags').options; // SchemaArrayOptions instance
*
* @api public
* @inherits SchemaTypeOptions
* @constructor SchemaArrayOptions
*/

class SchemaArrayOptions extends SchemaTypeOptions {}

const opts = {
Expand Down
13 changes: 13 additions & 0 deletions lib/options/SchemaBufferOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

const SchemaTypeOptions = require('./SchemaTypeOptions');

/**
* The options defined on a Buffer schematype.
*
* ####Example:
*
* const schema = new Schema({ bitmap: Buffer });
* schema.path('bitmap').options; // SchemaBufferOptions instance
*
* @api public
* @inherits SchemaTypeOptions
* @constructor SchemaBufferOptions
*/

class SchemaBufferOptions extends SchemaTypeOptions {}

const opts = {
Expand Down
13 changes: 13 additions & 0 deletions lib/options/SchemaDateOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

const SchemaTypeOptions = require('./SchemaTypeOptions');

/**
* The options defined on a Date schematype.
*
* ####Example:
*
* const schema = new Schema({ startedAt: Date });
* schema.path('startedAt').options; // SchemaDateOptions instance
*
* @api public
* @inherits SchemaTypeOptions
* @constructor SchemaDateOptions
*/

class SchemaDateOptions extends SchemaTypeOptions {}

const opts = {
Expand Down
13 changes: 13 additions & 0 deletions lib/options/SchemaNumberOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

const SchemaTypeOptions = require('./SchemaTypeOptions');

/**
* The options defined on a Number schematype.
*
* ####Example:
*
* const schema = new Schema({ count: Number });
* schema.path('count').options; // SchemaNumberOptions instance
*
* @api public
* @inherits SchemaTypeOptions
* @constructor SchemaNumberOptions
*/

class SchemaNumberOptions extends SchemaTypeOptions {}

const opts = {
Expand Down
13 changes: 13 additions & 0 deletions lib/options/SchemaObjectIdOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

const SchemaTypeOptions = require('./SchemaTypeOptions');

/**
* The options defined on an ObjectId schematype.
*
* ####Example:
*
* const schema = new Schema({ testId: mongoose.ObjectId });
* schema.path('testId').options; // SchemaObjectIdOptions instance
*
* @api public
* @inherits SchemaTypeOptions
* @constructor SchemaObjectIdOptions
*/

class SchemaObjectIdOptions extends SchemaTypeOptions {}

const opts = {
Expand Down
13 changes: 13 additions & 0 deletions lib/options/SchemaStringOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

const SchemaTypeOptions = require('./SchemaTypeOptions');

/**
* The options defined on a string schematype.
*
* ####Example:
*
* const schema = new Schema({ name: String });
* schema.path('name').options; // SchemaStringOptions instance
*
* @api public
* @inherits SchemaTypeOptions
* @constructor SchemaStringOptions
*/

class SchemaStringOptions extends SchemaTypeOptions {}

const opts = {
Expand Down
12 changes: 12 additions & 0 deletions lib/options/SchemaTypeOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

const utils = require('../utils');

/**
* The options defined on a schematype.
*
* ####Example:
*
* const schema = new Schema({ name: String });
* schema.path('name').options instanceof mongoose.SchemaTypeOptions; // true
*
* @api public
* @constructor SchemaTypeOptions
*/

class SchemaTypeOptions {
constructor(obj) {
if (obj == null) {
Expand Down
2 changes: 1 addition & 1 deletion lib/schematype.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const ValidatorError = MongooseError.ValidatorError;
* schema.path('name') instanceof SchemaType; // true
*
* @param {String} path
* @param {Object} [options]
* @param {SchemaTypeOptions} [options] See [SchemaTypeOptions docs](/docs/api/schematypeoptions.html)
* @param {String} [instance]
* @api public
*/
Expand Down

0 comments on commit 973b1e0

Please sign in to comment.