json-schema-xsd-tools
Installation
yarn add @bratislava/json-schema-xsd-tools
or
npm i @bratislava/json-schema-xsd-tools
Get started
import { loadAndBuildXsd, loadAndBuildDefaultXslt, loadAndValidate, fakeData } from 'json-schema-xsd-tools'
import { readFile, writeFile } from 'node:fs/promises'
const jsonSchema = {
title: 'A registration form',
description: 'A simple form example.',
type: 'object',
required: ['firstName', 'lastName'],
properties: {
firstName: {
type: 'string',
title: 'First name',
default: 'Chuck',
},
lastName: {
type: 'string',
title: 'Last name',
},
telephone: {
type: 'string',
title: 'Telephone',
minLength: 10,
},
},
}
const xsd = loadAndBuildXsd(jsonSchema)
await writeFile('schema.xsd', xsd)
const xslt = loadAndBuildDefaultXslt(jsonSchema, 'text')
await writeFile('form.sb.xslt', xslt)
const data = fakeData(jsonSchema)
await writeFile('form.json', data)
const errors = loadAndValidate(xsd, jsonSchema)
console.log(errors) // => []
Documentation
Explore the docs.
Publishing new version
- Run
npm version [<newversion> | major | minor | patch | premajor | preminor | prepatch | prerelease | from-git]
- Or update the version manually in package.json and create a tag with prefix
core-v
. - Push changes.
- Action publish package to npm. Check the status of workflow run.