Skip to content

Commit

Permalink
docs(schema): add examples for remaining functions
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Feb 18, 2019
1 parent 764735b commit 8dc47a5
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion lib/schema.js
Expand Up @@ -267,6 +267,13 @@ Schema.prototype.tree;
/**
* Returns a deep copy of the schema
*
* ####Example:
*
* const schema = new Schema({ name: String });
* const clone = schema.clone();
* clone === schema; // false
* clone.path('name'); // SchemaString { ... }
*
* @return {Schema} the cloned schema
* @api public
* @memberOf Schema
Expand Down Expand Up @@ -763,7 +770,17 @@ Schema.prototype.interpretAsType = function(path, obj, options) {
/**
* Iterates the schemas paths similar to Array#forEach.
*
* The callback is passed the pathname and schemaType as arguments on each iteration.
* The callback is passed the pathname and the schemaType instance.
*
* ####Example:
*
* const userSchema = new Schema({ name: String, registeredAt: Date });
* userSchema.eachPath((pathname, schematype) => {
* // Prints twice:
* // name SchemaString { ... }
* // registeredAt SchemaDate { ... }
* console.log(pathname, schematype);
* });
*
* @param {Function} fn callback function
* @return {Schema} this
Expand Down Expand Up @@ -1389,8 +1406,15 @@ const setSafe = util.deprecate(function setSafe(options, value) {
/**
* Gets a schema option.
*
* ####Example:
*
* schema.get('strict'); // true
* schema.set('strict', false);
* schema.get('strict'); // false
*
* @param {String} key option name
* @api public
* @return {Any} the option's value
*/

Schema.prototype.get = function(key) {
Expand Down Expand Up @@ -1420,7 +1444,19 @@ Object.defineProperty(Schema, 'indexTypes', {
* Returns a list of indexes that this schema declares, via `schema.index()`
* or by `index: true` in a path's options.
*
* ####Example:
*
* const userSchema = new Schema({
* email: { type: String, required: true, unique: true },
* registeredAt: { type: Date, index: true }
* });
*
* // [ [ { email: 1 }, { unique: true, background: true } ],
* // [ { registeredAt: 1 }, { background: true } ] ]
* userSchema.indexes();
*
* @api public
* @return {Array} list of indexes defined in the schema
*/

Schema.prototype.indexes = function() {
Expand Down

0 comments on commit 8dc47a5

Please sign in to comment.