andrewbober / xsd2jsonschema

A pure JavaScript library for translating complex XML Schemas into JSON Schemas.
https://www.xsd2jsonschema.org
Apache License 2.0
48 stars 25 forks source link

Unable to generate JSON schema #29

Open sunildabburi opened 3 years ago

sunildabburi commented 3 years ago

I may be doing something wrong here. I am trying the examples documented on your github page. Please find attached XSD (as text file) that I am trying to convert to a JSON schema. I pasted the XSD file content and assigned that to the XML_SCHEMA variable as shown below

'use strict';

const XML_SCHEMA = `
<pasted attached file xsd content here>
`;

const Xsd2JsonSchema = require('xsd2jsonschema').Xsd2JsonSchema;
const xs2js = new Xsd2JsonSchema();

const convertedSchemas = xs2js.processAllSchemas( {
    schemas: {'test.xsd': XML_SCHEMA}
});
const jsonSchema = convertedSchemas['test.xsd'].getJsonSchema();
console.log(JSON.stringify(jsonSchema, null, 2));

I get this error

> xsd2jsonschema@0.3.7 test/Users/abcd/xsd2jsonschema
> node examples/test.js

/Users/abcd/xsd2jsonschema/src/visitors/visitor.js:66
            throw err;
            ^

TypeError: qualifiedTypeName.getLocal is not a function
    at ConverterDraft07.createAttributeSchema (/Users/abcd/xsd2jsonschema/src/converterDraft04.js:220:47)
    at ConverterDraft07.process (/Users/abcd/xsd2jsonschema/src/converterDraft04.js:120:83)
    at BaseConversionVisitor.visit (/Users/abcd/xsd2jsonschema/src/visitors/visitor.js:60:26)
    at DepthFirstTraversal.walk (/Users/abcd/xsd2jsonschema/src/depthFirstTraversal.js:47:34)
    at DepthFirstTraversal.walk (/Users/abcd/xsd2jsonschema/src/depthFirstTraversal.js:52:12)
    at DepthFirstTraversal.traverse (/Users/abcd/xsd2jsonschema/src/depthFirstTraversal.js:78:9)
    at Xsd2JsonSchema.processSchema (/Users/abcd/xsd2jsonschema/src/xsd2JsonSchema.js:264:37)
    at Xsd2JsonSchema.<anonymous> (/Users/abcd/xsd2jsonschema/src/xsd2JsonSchema.js:287:18)
    at Array.forEach (<anonymous>)
    at Xsd2JsonSchema.processSchemas (/Users/abcd/xsd2jsonschema/src/xsd2JsonSchema.js:286:19)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! xsd2jsonschema@0.3.7 test: `node examples/test.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the xsd2jsonschema@0.3.7 test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

schema.txt

andrewbober commented 3 years ago

Thanks for submitting this issue. I've confirmed it is a bug.