Skip to content

Commit 973b1e0

Browse files
committedOct 12, 2019
docs: add schema options to API docs
Fix #8012
1 parent cdfb507 commit 973b1e0

12 files changed

+140
-25
lines changed
 

‎docs/api.pug

+10-9
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,16 @@ block content
1616
div.api-nav
1717
div.api-nav-content
1818
each item in docs
19-
div.nav-item(id='nav-' + item.name)
20-
div.nav-item-title
21-
a(href='./api/' + item.name.toLowerCase() + '.html')
22-
| #{item.name}
23-
ul.nav-item-sub
24-
each prop in item.props
25-
li
26-
a(href='./api/' + item.name.toLowerCase() + '.html#' + prop.anchorId)
27-
| #{prop.string}
19+
- if (!item.hideFromNav)
20+
div.nav-item(id='nav-' + item.name)
21+
div.nav-item-title
22+
a(href='./api/' + item.name.toLowerCase() + '.html')
23+
| #{item.name}
24+
ul.nav-item-sub
25+
each prop in item.props
26+
li
27+
a(href='./api/' + item.name.toLowerCase() + '.html#' + prop.anchorId)
28+
| #{prop.string}
2829

2930
each item in docs
3031
hr.separate-api

‎docs/api_split.pug

+15-14
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,21 @@ block content
2525
div.api-nav
2626
div.api-nav-content
2727
each item in docs
28-
div.nav-item(id='nav-' + item.name)
29-
- if (item.name === name)
30-
div.nav-item-title(style="font-weight: bold")
31-
a(href=item.name.toLowerCase() + '.html')
32-
| #{item.name}
33-
ul.nav-item-sub
34-
each prop in item.props
35-
li
36-
a(href='#' + prop.anchorId)
37-
| #{prop.string}
38-
- else
39-
div.nav-item-title
40-
a(href=item.name.toLowerCase() + '.html')
41-
| #{item.name}
28+
- if (!item.hideFromNav || item.name === name)
29+
div.nav-item(id='nav-' + item.name)
30+
- if (item.name === name)
31+
div.nav-item-title(style="font-weight: bold")
32+
a(href=item.name.toLowerCase() + '.html')
33+
| #{item.name}
34+
ul.nav-item-sub
35+
each prop in item.props
36+
li
37+
a(href='#' + prop.anchorId)
38+
| #{prop.string}
39+
- else
40+
div.nav-item-title
41+
a(href=item.name.toLowerCase() + '.html')
42+
| #{item.name}
4243

4344
div.api-content
4445
ul

‎docs/source/api.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,14 @@ const files = [
2424
'lib/virtualtype.js',
2525
'lib/error/index.js',
2626
'lib/types/core_array.js',
27-
'lib/schema/SingleNestedPath.js'
27+
'lib/schema/SingleNestedPath.js',
28+
'lib/options/SchemaTypeOptions.js',
29+
'lib/options/SchemaArrayOptions.js',
30+
'lib/options/SchemaBufferOptions.js',
31+
'lib/options/SchemaDateOptions.js',
32+
'lib/options/SchemaNumberOptions.js',
33+
'lib/options/SchemaObjectIdOptions.js',
34+
'lib/options/SchemaStringOptions.js'
2835
];
2936

3037
module.exports = {
@@ -83,6 +90,9 @@ function parse() {
8390
ctx.name = str;
8491
ctx.string = `${ctx.constructor}.prototype.${ctx.name}`;
8592
break;
93+
case 'type':
94+
ctx.type = Array.isArray(tag.types) ? tag.types.join('|') : tag.types;
95+
break;
8696
case 'static':
8797
ctx.type = 'property';
8898
ctx.static = true;
@@ -164,6 +174,10 @@ function parse() {
164174
}
165175
});
166176

177+
if (props.file.startsWith('lib/options')) {
178+
data.hideFromNav = true;
179+
}
180+
167181
out.push(data);
168182
}
169183
}

‎lib/index.js

+9
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,15 @@ Mongoose.prototype.now = function now() { return new Date(); };
10151015

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

1018+
/**
1019+
* The constructor used for schematype options
1020+
*
1021+
* @method SchemaTypeOptions
1022+
* @api public
1023+
*/
1024+
1025+
Mongoose.prototype.SchemaTypeOptions = require('./options/SchemaTypeOptions');
1026+
10181027
/**
10191028
* The [node-mongodb-native](https://github.com/mongodb/node-mongodb-native) driver Mongoose uses.
10201029
*

‎lib/options/SchemaArrayOptions.js

+13
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22

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

5+
/**
6+
* The options defined on an Array schematype.
7+
*
8+
* ####Example:
9+
*
10+
* const schema = new Schema({ tags: [String] });
11+
* schema.path('tags').options; // SchemaArrayOptions instance
12+
*
13+
* @api public
14+
* @inherits SchemaTypeOptions
15+
* @constructor SchemaArrayOptions
16+
*/
17+
518
class SchemaArrayOptions extends SchemaTypeOptions {}
619

720
const opts = {

‎lib/options/SchemaBufferOptions.js

+13
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22

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

5+
/**
6+
* The options defined on a Buffer schematype.
7+
*
8+
* ####Example:
9+
*
10+
* const schema = new Schema({ bitmap: Buffer });
11+
* schema.path('bitmap').options; // SchemaBufferOptions instance
12+
*
13+
* @api public
14+
* @inherits SchemaTypeOptions
15+
* @constructor SchemaBufferOptions
16+
*/
17+
518
class SchemaBufferOptions extends SchemaTypeOptions {}
619

720
const opts = {

‎lib/options/SchemaDateOptions.js

+13
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22

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

5+
/**
6+
* The options defined on a Date schematype.
7+
*
8+
* ####Example:
9+
*
10+
* const schema = new Schema({ startedAt: Date });
11+
* schema.path('startedAt').options; // SchemaDateOptions instance
12+
*
13+
* @api public
14+
* @inherits SchemaTypeOptions
15+
* @constructor SchemaDateOptions
16+
*/
17+
518
class SchemaDateOptions extends SchemaTypeOptions {}
619

720
const opts = {

‎lib/options/SchemaNumberOptions.js

+13
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22

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

5+
/**
6+
* The options defined on a Number schematype.
7+
*
8+
* ####Example:
9+
*
10+
* const schema = new Schema({ count: Number });
11+
* schema.path('count').options; // SchemaNumberOptions instance
12+
*
13+
* @api public
14+
* @inherits SchemaTypeOptions
15+
* @constructor SchemaNumberOptions
16+
*/
17+
518
class SchemaNumberOptions extends SchemaTypeOptions {}
619

720
const opts = {

‎lib/options/SchemaObjectIdOptions.js

+13
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22

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

5+
/**
6+
* The options defined on an ObjectId schematype.
7+
*
8+
* ####Example:
9+
*
10+
* const schema = new Schema({ testId: mongoose.ObjectId });
11+
* schema.path('testId').options; // SchemaObjectIdOptions instance
12+
*
13+
* @api public
14+
* @inherits SchemaTypeOptions
15+
* @constructor SchemaObjectIdOptions
16+
*/
17+
518
class SchemaObjectIdOptions extends SchemaTypeOptions {}
619

720
const opts = {

‎lib/options/SchemaStringOptions.js

+13
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22

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

5+
/**
6+
* The options defined on a string schematype.
7+
*
8+
* ####Example:
9+
*
10+
* const schema = new Schema({ name: String });
11+
* schema.path('name').options; // SchemaStringOptions instance
12+
*
13+
* @api public
14+
* @inherits SchemaTypeOptions
15+
* @constructor SchemaStringOptions
16+
*/
17+
518
class SchemaStringOptions extends SchemaTypeOptions {}
619

720
const opts = {

‎lib/options/SchemaTypeOptions.js

+12
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22

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

5+
/**
6+
* The options defined on a schematype.
7+
*
8+
* ####Example:
9+
*
10+
* const schema = new Schema({ name: String });
11+
* schema.path('name').options instanceof mongoose.SchemaTypeOptions; // true
12+
*
13+
* @api public
14+
* @constructor SchemaTypeOptions
15+
*/
16+
517
class SchemaTypeOptions {
618
constructor(obj) {
719
if (obj == null) {

‎lib/schematype.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const ValidatorError = MongooseError.ValidatorError;
2929
* schema.path('name') instanceof SchemaType; // true
3030
*
3131
* @param {String} path
32-
* @param {Object} [options]
32+
* @param {SchemaTypeOptions} [options] See [SchemaTypeOptions docs](/docs/api/schematypeoptions.html)
3333
* @param {String} [instance]
3434
* @api public
3535
*/

0 commit comments

Comments
 (0)