jon49 / json-schema-to-mongoose Goto Github PK
View Code? Open in Web Editor NEWA library for converting json-schema to mongoose schema.
License: Apache License 2.0
A library for converting json-schema to mongoose schema.
License: Apache License 2.0
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
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?
Fixed in Pull request #9
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
same thing but backwards pls
Input:-
Valid JSON..
'addressLine1': {
'type': 'string'
},
'addressLine2': {
'type': 'string'
},
-------------------OUTPUT -----------------------
address:
{ addressLine1: { type: [Function: String] },
addressLine2: { type: [Function: String] },
city: { type: [Function: String] },
Why is this extra string "Function" coming ??
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
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?
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".
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.