xsd2jsonschema
Version:
A pure JavaScript library for converting complex XML Schemas into equivalent JSON Schemas.
32 lines (28 loc) • 1.02 kB
JavaScript
'use strict';
const XML_SCHEMA_ANNOTATION = `
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" >
<xs:simpleType name="XXXX">
<xs:annotation>
<xs:documentation>
<whyIsItUsed>
<usedBy>Used somewhere over a rainbow</usedBy>
<usedFor>Used for the pot of gold</usedFor>
</whyIsItUsed>
<whenIsItUsed>Upon acquisition of the pot of gold</whenIsItUsed>
Living on the edge outside a tag on the other side of the rainbow
</xs:documentation>
</xs:annotation>
<xs:restriction base="xs:token">
<xs:pattern value=".{1,24}" />
</xs:restriction>
</xs:simpleType>
</xs:schema>
`;
const Xsd2JsonSchema = require('xsd2jsonschema').Xsd2JsonSchema;
const xs2js = new Xsd2JsonSchema();
const convertedSchemas = xs2js.processAllSchemas({
schemas: { 'annotation.xsd': XML_SCHEMA_ANNOTATION }
});
const jsonSchema = convertedSchemas['annotation.xsd'].getJsonSchema();
console.log(JSON.stringify(jsonSchema, null, 2));