charto / cxsd

Streaming XSD parser and XML parser generator with TypeScript output
MIT License
111 stars 55 forks source link

XSD with xs:redefine #11

Open stckcrsh opened 8 years ago

stckcrsh commented 8 years ago

Sorry i dont know if this is an issue or I am doing this completely wrong

I have two xsd files that i am trying to parse The first has some complex types basic stuff, but the second one has xs:redefine to alter the complex types from the first xsd

example base.xsd

<xs:complexType name="transaction">
    <xs:sequence>
        <xs:element name="id" type="xs:string" minOccurs="0"/>
        <xs:element name="timestamp" type="xs:dateTime" minOccurs="0"/>
    </xs:sequence>
</xs:complexType>

extend.xsd

<xs:redefine schemaLocation="base.xsd">
  <xs:complexType name="transaction">
    <xs:complexContent>
        <xs:extension base="transaction">
            <xs:sequence>
                <xs:element name="partial" type="xs:string" minOccurs="0" />
                <xs:element name="originSrc" type="xs:string" minOccurs="0" />
                <xs:element name="originalPrd" type="xs:string" minOccurs="0" />
                <xs:element name="crn" type="xs:string" minOccurs="0" />
            </xs:sequence>
        </xs:extension>
    </xs:complexContent>
  </xs:complexType> 
</xs:redefine

This is the resulting Typescript i get

interface _transaction extends BaseType {
    id?: string;
    timestamp?: Date;
}
export interface transaction extends _transaction { constructor: { new(): transaction }; }
export var transaction: { new(): transaction };

As I said earlier this might not be an issue, but a problem with how things are done on my side. As some backstory we are upgrading the frontend on an old service that my company has to angular2. They do not want to update any of the server stuff (all the xsds) and i have to generate visualizations off this data that is returned and i do not wish to go through all the xsd files they have and manually try to get this data in.

jjrv commented 7 years ago

There's no support yet for redefine or override. Handling them seems complicated if parsing some XML files that (using xsi) refer to the redefined schema and some only refer to the original. That would allow completely different definitions for the namespace, and TypeScript module augmentations don't seem to support that. Parsing XML would still work, but types couldn't be represented properly in a TypeScript IDE. It could be made to work if both .xsd files are always used together.

stckcrsh commented 7 years ago

In my instance both are always used together.