-
-
Save stalniy/05f3940d5a55d80a38557edd8ffbfe14 to your computer and use it in GitHub Desktop.
fast json schema issues
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const compile = require("fast-json-stringify"); | |
const schema = { | |
type: 'array', | |
items: { | |
type: "object", | |
anyOf: [ | |
{ | |
type: 'object', | |
required: [ 'id', 'createdAt', 'author', 'type', 'body' ], | |
properties: { | |
id: { type: 'string' }, | |
createdAt: { type: 'string', format: 'date-time' }, | |
author: { | |
type: 'object', | |
required: [ '_id', 'fullName' ], | |
properties: { _id: { type: 'string' }, fullName: { type: 'string' } }, | |
additionalProperties: false | |
}, | |
type: { type: 'string', enum: [ 'Text' ] }, | |
body: { type: 'string' } | |
}, | |
additionalProperties: false | |
}, | |
{ | |
type: 'object', | |
required: [ 'id', 'createdAt', 'author', 'type', 'status' ], | |
properties: { | |
id: { type: 'string' }, | |
createdAt: { type: 'string', format: 'date-time' }, | |
author: { | |
type: 'object', | |
required: [ '_id', 'fullName' ], | |
properties: { _id: { type: 'string' }, fullName: { type: 'string' } }, | |
additionalProperties: false | |
}, | |
type: { type: 'string', enum: [ 'StatusTransition' ] }, | |
status: { | |
type: 'string', | |
} | |
}, | |
additionalProperties: false | |
} | |
] | |
} | |
} | |
const stringify = compile(schema); | |
console.log(stringify([ | |
{ | |
type: "StatusTransition", | |
id: 1, | |
createdAt: new Date().toISOString(), | |
status: "bla", | |
author: { | |
_id: 2, | |
fullName: "John Doe" | |
} | |
} | |
])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment