This tool allows you to generate Mongoose models from JSON schemas.
Install the package globally using npm:
npm install json2mongoose -g
To use the tool from the command line, run the following command:
json2mongoose ./jsonSchema ./output
You can also use the tool programmatically in your Node.js scripts:
import json2mongoose from "json2mongoose"
const schemaDir = "path/to/jsonSchema";
const modelDir = "path/to/model";
const typeDir = "path/to/types";
json2mongoose.genarate(schemaDir: string, modelDir: string, typeDir: string);
Please replace the paths with the actual paths to your JSON schemas and output directory.
The generated file is named based on the schema file's name.
the x-documentConfig.documentName
will only effect on mongoose api.
ex: docuemt interface, schema, model.
if you don't wish to drop your hair after some bug came out,
match the schema file name with document name.
[] validation of json schema,
- x-foreignKey collection exist
-
This project is licensed under the terms of the MIT license. See the LICENSE file for details.