Skip to content

Instantly share code, notes, and snippets.

@stalniy

stalniy/issue.js Secret

Created July 16, 2021 16:59
Show Gist options
  • Save stalniy/05f3940d5a55d80a38557edd8ffbfe14 to your computer and use it in GitHub Desktop.
Save stalniy/05f3940d5a55d80a38557edd8ffbfe14 to your computer and use it in GitHub Desktop.
fast json schema issues
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