jsonschema-mongoose-converter
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

jsonschema-to-mongoose-schema

Utility which converts jsonschema to mongoose schema.

Build Status npm version

NPM

Development

Run test

npm run test

Install

npm i jsonschema-mongoose-converter

Usage

import {convertToMongooseSchema} from "@hemanthsr/jsonschema-to-mongoose-schema"

const jsonSchema = {
    "$schema": "http://json-schema.org/draft-07/schema#",
    "title": "User",
    "description": "A user schema with id and name",
    "type": "object",
    "properties": {
        "id": {
            "type": "number",
            "description": "The unique identifier for a user"
        },
        "name": {
            "type": "string",
            "description": "The name of the user"
        }
    },
    "required": ["id", "name"],
    "additionalProperties": false
}

const mSchema = convertToMongooseSchema(jsonSchema)
console.log(mSchema)
/*
{
  id: { type: Number, required: true },
  name: { type: String, required: true }
}
 */
const UserSchema = new mongoose.Schema(mSchema)

Contributions

You are welcome to contribute to this project if you see something missing. Follow https://kbroman.org/github_tutorial/pages/fork.html for step-by-step guide.

Package Sidebar

Install

npm i jsonschema-mongoose-converter

Weekly Downloads

0

Version

1.0.2

License

ISC

Unpacked Size

7 kB

Total Files

5

Last publish

Collaborators

  • hemanthsr