GithubHelp home page GithubHelp logo

jon49 / json-schema-to-mongoose Goto Github PK

View Code? Open in Web Editor NEW
45.0 45.0 12.0 14.9 MB

A library for converting json-schema to mongoose schema.

License: Apache License 2.0

TypeScript 46.11% JavaScript 53.89%

json-schema-to-mongoose's People

Contributors

agrozyme avatar chemdrew avatar iaincollins avatar jon-uhi avatar jon49 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

json-schema-to-mongoose's Issues

TypeError: Invalid schema configuration: `Lodash` is not a valid type at path `placeholder`

Hi there!!

For this awesome work!

Trying to use this file:
https://github.com/mariohmol/mean-crud-generator/blob/master/demo/schema/pet.json

But is giving me this error:

(node:8145) UnhandledPromiseRejectionWarning: TypeError: Invalid schema configuration: Lodash is not a valid type at path placeholder. See http://bit.ly/mongoose-schematypes for a list of valid schema types.
at Schema.interpretAsType (/Users/mariohmol/projetos/mean-crud-generator/node_modules/mongoose/lib/schema.js:981:11)
at Schema.path (/Users/mariohmol/projetos/mean-crud-generator/node_modules/mongoose/lib/schema.js:678:27)
at Schema.add (/Users/mariohmol/projetos/mean-crud-generator/node_modules/mongoose/lib/schema.js:491:12)
at new Schema (/Users/mariohmol/projetos/mean-crud-generator/node_modules/mongoose/lib/schema.js:130:10)
at Object. (/Users/mariohmol/projetos/mean-crud-generator/backend/model.ts:23:24)
at step (/Users/mariohmol/projetos/mean-crud-generator/backend/model.ts:32:23)
at Object.next (/Users/mariohmol/projetos/mean-crud-generator/backend/model.ts:13:53)
at fulfilled (/Users/mariohmol/projetos/mean-crud-generator/backend/model.ts:4:58)

Any ideas?

thanks

Input parameters and supported json schema keywords not described in a README

In your README file you provide the following example:

var mongooseSchema = createMongooseSchema(refs, schema)

Could you please provide more details about the parameters refs and schema? And also supported json schema keywords.

I have schema looking like this:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "id": "http://mydomain.net/schemas/enduser.json",
  "type": "object",
  "properties": {
    "personaldata": {
      "$ref": "http://mydomain.net/schemas/personaldata.json"
    }
  },
  "additionalProperties": false,
  "required": [
    "personaldata"
  ]
}

but i can't generate a mongoose schema with your module. Is there any possibility for that?

Error: Unsupported $ref value: #/definitions/mongoIdentifier

Hi,

I am using a JSON schema that passes through both http://www.jsonschemavalidator.net/ and http://jsonschemalint.com/draft4/. It uses $ref attributes which point to a defitions section inside the same JSON schema file, e.g. #/definitions/mongoIdentifier.

This fails both when I pass I pass the definitions from the schema file as a parameter

const mongooseSchema = createMongooseSchema(schema.definitions, schema);

and when I pass an empty object:

const mongooseSchema = createMongooseSchema({ }, schema);

The library says this is currently unsupported. How easy would it be to remedy, or am I just doing something incorrectly?

Thanks,
Danny

All types getting tagged with 'Function'

Input:-
Valid JSON..

'addressLine1': {
'type': 'string'
},
'addressLine2': {
'type': 'string'
},
-------------------OUTPUT -----------------------
address:
{ addressLine1: { type: [Function: String] },
addressLine2: { type: [Function: String] },
city: { type: [Function: String] },

postalCode: { type: [Function: String] } },

Why is this extra string "Function" coming ??

Schema type enum fails with Unsupported JSON schema type, `[object Object]`

Hi,

I cannot transform an enum qualified by:

"notifyState": { "type" : { "enum" : ["UNREAD", "DELIVERED", "READ", "DELETED"]}, "required": false },

Do you have any ideas why this is not working? It's alittle bit tricky to step through the convert function ;-) I also looked at your tests, but could not find an example for an enumeration.

Any help is appreciated.

Olli

Support for required fields

So, this library is a life saver, but it doesn't seem to register required objects as required

Here is the json schema

jsonSchema: {
    '$ref': '#/definitions/mySchema',
    definitions: {
      mySchema: {
        type: 'object',
        properties: {
          myString: { type: 'string', minLength: 5 },
          myUnion: { type: 'number' }
        },
        required: [ 'myUnion' ],
        additionalProperties: false,
        description: 'My neat object schema'
      }
    },
    '$schema': 'http://json-schema.org/draft-07/schema#'
  },

// convert
const mongooseSchema = createMongooseSchema({}, jsonSchema.definitions?.mySchema,);


//final object
  mongooseSchema: {
    myString: { type: [Function: String], minlength: 5 },
    myUnion: { type: [Function: Number] }
  }

Am i doing something wrong?

Schema error on parent of nested object if parent is required

If the schema contains:

{
	"$schema": "http://json-schema.org/draft-04/schema#",
	"type": "object",
	"properties": {
		"parent": {
			"type": "object",
			"properties": {
				"child": {
					"type": "string",
				}
			},
			"required": ["child"]
		}
	},
	"required": ["parent"]
}

Then it fails with the following message:

TypeError: Undefined type `undefined` at `parent.required`
  Did you try nesting Schemas? You can only nest using refs or arrays.
  ...

Mongoose automatically makes the parent required if any of the children are.
Therefore we should ignore the required tag for parent objects with type="object".

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.