lib/schema.js
function schema_jsonSchema(name) {

  let result;

  name = name || this.options.name;

  if (this.__buildingSchema) {
    this.__jsonSchemaId =
      this.__jsonSchemaId ||
      '#schema-' + (++schema_jsonSchema.__jsonSchemaIdCounter);
    return {'$ref': this.__jsonSchemaId}
  }

  if (!this.__jsonSchema) {
    this.__buildingSchema = true;
    this.__jsonSchema = __build(name, this);
    this.__buildingSchema = false;
    if (this.__jsonSchemaId) {
      this.__jsonSchema = Object.assign(
        {id: this.__jsonSchemaId}, this.__jsonSchema
      )
    }
  }

  result = JSON.parse(JSON.stringify(this.__jsonSchema));

  if (name) {
    result.title = name;
  } else {
    delete result.title;
  }
  return result;
}
function schema_jsonSchema(name) {

  let result;

  name = name || this.options.name;

  if (this.__buildingSchema) {
    this.__jsonSchemaId =
      this.__jsonSchemaId ||
      '#schema-' + (++schema_jsonSchema.__jsonSchemaIdCounter);
    return {'$ref': this.__jsonSchemaId}
  }

  if (!this.__jsonSchema) {
    this.__buildingSchema = true;
    this.__jsonSchema = __build(name, this);
    this.__buildingSchema = false;
    if (this.__jsonSchemaId) {
      this.__jsonSchema = Object.assign(
        {id: this.__jsonSchemaId}, this.__jsonSchema
      )
    }
  }

  result = JSON.parse(JSON.stringify(this.__jsonSchema));

  if (name) {
    result.title = name;
  } else {
    delete result.title;
  }
  return result;
}
function schema_jsonSchema ( name ) { let result ; name = name || this . options . name ; if ( this . __buildingSchema ) { this . __jsonSchemaId = this . __jsonSchemaId || '#schema-' + ( ++ schema_jsonSchema . __jsonSchemaIdCounter ) ; return { '$ref' : this . __jsonSchemaId } } if ( ! this . __jsonSchema ) { this . __buildingSchema = true ; this . __jsonSchema = __build ( name , this ) ; this . __buildingSchema = false ; if ( this . __jsonSchemaId ) { this . __jsonSchema = Object . assign ( { id : this . __jsonSchemaId } , this . __jsonSchema ) } } result = JSON . parse ( JSON . stringify ( this . __jsonSchema ) ) ; if ( name ) { result . title = name ; } else { delete result . title ; } return result ; }
schema_jsonSchema - builds the json schema based on the Mongooose schema.
if schema has been already built the method returns new deep copy

Method considers the `schema.options.toJSON.virtuals` to included
the virtual paths (without detailed description)

@memberof mongoose.Schema

@param  {String} name Name of the object
@return {Object}          json schema
schema_jsonSchema - builds the json schema based on the Mongooose schema . if schema has been already built the method returns new deep copy