Converts Mongoose schema objects to Swagger/OpenAPI schema definitions. Currently at v1.5.1, stable and used in production for many projects. Key differentiator is the simplicity of converting any Mongoose model into a Swagger-compatible JSON schema, extracting description, enum, required fields automatically. Supports custom meta property whitelisting and omission of internal Mongoose fields. Does not support OpenAPI 3.0+ yet (Swagger 2.0 only). Released under MIT.
npm install mongoose-to-swaggerNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Converts a Mongoose schema with custom meta properties to a Swagger schema definition.
Use openapi-to-swagger or manually convert to OpenAPI 3.0. Alternatively, use a library like @nestjs/swagger for OpenAPI 3.0.
Manually inspect and adjust the output for complex schemas. Consider using mongoose-to-openapi for better OpenAPI 3.0 support.
Set omitMongooseInternals: false if you need those fields in the output.
Evaluate if it still meets your needs or consider migrating to active forks.
Use const m2s = require('mongoose-to-swagger') or import m2s from 'mongoose-to-swagger'.Ensure you pass a Mongoose model, e.g., const Cat = mongoose.model('Cat', CatSchema); m2s(Cat);Verify the model is defined and not null/undefined.