{"library":"mongoose-schema-jsonschema","title":"Mongoose Schema JSON Schema Generator","description":"This package extends Mongoose's core classes (`Schema`, `Model`, and `Query`) to automatically generate JSON Schema representations from existing Mongoose definitions. It provides a `jsonSchema()` method accessible directly on Mongoose schemas, models, and queries, streamlining the creation of JSON Schemas for API documentation (e.g., OpenAPI), data validation, or UI generation. The current stable version is 4.0.1, indicating active maintenance and compatibility with Mongoose versions 6.x through 9.x. Key differentiators include its direct integration into Mongoose prototypes, a caching mechanism for built schemas with an explicit `forceRebuild` option, and configurable mapping for custom Mongoose field options to JSON Schema extensions (`fieldOptionsMapping`). The package typically releases new versions as needed to support newer Mongoose versions or JSON Schema specification updates.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install mongoose-schema-jsonschema"],"cli":null},"imports":["const mongoose = require('mongoose');\nrequire('mongoose-schema-jsonschema')(mongoose);","const config = require('mongoose-schema-jsonschema/config');"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const mongoose = require('mongoose');\nrequire('mongoose-schema-jsonschema')(mongoose);\n\nconst Schema = mongoose.Schema;\n\nconst BookSchema = new Schema({\n  title: { type: String, required: true, minLength: 3 },\n  year: { type: Number, min: 1900, max: new Date().getFullYear() },\n  author: { type: String, required: true },\n  tags: [{ type: String }],\n  meta: {\n    isbn: String,\n    pages: Number\n  }\n});\n\nconst jsonSchema = BookSchema.jsonSchema();\n\nconsole.dir(jsonSchema, { depth: null });\n\n/* Example Output:\n{\n  type: 'object',\n  properties: {\n    title: { type: 'string', minLength: 3 },\n    year: { type: 'number', minimum: 1900, maximum: 2024 },\n    author: { type: 'string' },\n    tags: { type: 'array', items: { type: 'string' } },\n    meta: {\n      type: 'object',\n      properties: {\n        isbn: { type: 'string' },\n        pages: { type: 'number' }\n      },\n      required: []\n    },\n    _id: { type: 'string', pattern: '^[0-9a-fA-F]{24}$' }\n  },\n  required: [ 'title', 'author' ]\n}\n*/","lang":"javascript","description":"This quickstart demonstrates how to extend Mongoose and then generate a JSON Schema from a simple Mongoose Schema definition, showcasing basic type mapping and required fields.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}