Closed azaslonov closed 3 years ago
Hi @azaslonov - all file IO was removed from the library in v0.3.1.
https://github.com/andrewbober/xsd2jsonschema/releases/tag/0.3.1
Hi @andrewbober, thanks for the quick reply. Looks like there are still dependencies, this is what my browser says:
I'm using package version 0.3.7, and using the example from Quickstart with no changes:
const XML_SCHEMA = `
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:simpleType name="C">
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="Char_20">
<xs:restriction base="C">
<xs:minLength value="1"/>
<xs:maxLength value="20"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
`;
const Xsd2JsonSchema = require('xsd2jsonschema').Xsd2JsonSchema;
const xs2js = new Xsd2JsonSchema();
const convertedSchemas = xs2js.processAllSchemas({
schemas: {'hello_world.xsd': XML_SCHEMA}
});
const jsonSchema = convertedSchemas['hello_world.xsd'].getJsonSchema();
console.log(JSON.stringify(jsonSchema, null, 2));
Hi @azaslonov - The line you have highlighted simply parses a string to provide a name for the resulting JSON Schema. There is no actual file io. Are you getting a specific error that I can help with?
Hi @andrewbober, thanks for your response. The error on the screenshot above is from the browser, so it fails on that line, because of the "path" object which is not defined in the browser environment. I could probably do some stub like window.path = { parse: () => {...} }
, but I'm sure other people (with web apps) will hit this error as well, so it would be great to have it working universally in both browser and node.
Is it possible to make this wonderful library browser compatible, that would do the conversion without referring to the file system?