Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
QuickMick opened this issue Mar 1, 2022 · 1 comment

Comments

@QuickMick
Copy link

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);
@martyzz1
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants