mongoose-schema-jsonschema icon indicating copy to clipboard operation
mongoose-schema-jsonschema copied to clipboard

Feature Request: Add interface to be more static JsonSchema(mongooseModel)

Open QuickMick opened this issue 3 years ago • 1 comments

i think it would be less error prone to have an option for passing the model to a function, without having the need for extending all the mongoose types. e.g. i have my models in a different package than the schema-creation script. now i need to include mongoose, for schema creation and it seems, there is something off with peerDependencies or so, because the .jsonSchema function does not exist.

so instead of

mongooseModel.jsonSchema();

i would like to do:

const JsonSChema =require("mongoose-schema-jsonschema");
JsonSchema(mongooseModel);

QuickMick avatar Mar 01 '22 11:03 QuickMick

yes, this... I use shared mongoose libraries, so the Models are instantiated through a provided mongoose connection... Can't seem to find the right way to ensure the JsonSchema function is added to the model...

I tried

module.exports = function connectionFactory(connection) {
  logger.trace(`transactionLog model connection ${connection.id}`);
  extendMongooose(connection);
  return connection.model('TransactionLog', transactionLogSchema);
};

But that results in

TypeError: Cannot destructure property 'Types' of 'mongoose.Schema' as it is undefined.

martyzz1 avatar May 24 '23 08:05 martyzz1