xsd2ttcn creates cyclical definitions
Submitted by Anton Vikstrom
Link to original bug (#569238)
Description
"xsd2ttcn -h" creates cyclical type definitions when one of the choices in a complexType choice is restricted to the type of another choice.
Consider the following .xsd file:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://uri/test2" targetNamespace="http://uri/test2" version="2.4.1" elementFormDefault="qualified"
<xs:simpleType name="IMSI">
<xs:restriction base="xs:token">
<xs:pattern value="[0-9]{6,15}"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="SUPIIMSI">
<xs:restriction base="IMSI"/>
</xs:simpleType>
</xs:schema>
Using xsd2ttcn -h on this creates one type for IMSI (a restricted XSD.token charstring) and one type for SUPIIMSI (type alias of IMSI):
type XSD.Token IMSI (pattern "[0-9]#(6,15)"); type IMSI SUPIIMSI;
Now consider the same file, with an additional type:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://uri/test" targetNamespace="http://uri/test" version="2.4.1" elementFormDefault="qualified"
<xs:simpleType name="IMSI">
<xs:restriction base="xs:token">
<xs:pattern value="[0-9]{6,15}"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="SUPIIMSI">
<xs:restriction base="IMSI"/>
</xs:simpleType>
<xs:complexType name="TargetIdentifier">
<xs:choice>
<xs:element name="imsi" type="IMSI"/>
<xs:element name="supiimsi" type="SUPIIMSI"/>
</xs:choice>
</xs:complexType>
</xs:schema>
Using xsd2ttcn -h on this will create a cyclical type definition (IMSI_derivations contains itself, as SUPIIMSI is IMSI_derivations):
type XSD.Token IMSI (pattern "[0-9]#(6,15)"); type IMSI_derivations SUPIIMSI; type union IMSI_derivations { IMSI iMSI, SUPIIMSI sUPIIMSI } with { variant "useType"; variant (iMSI) "name as capitalized"; variant (sUPIIMSI) "name as capitalized"; };
Normally, the "derivations" created by the -h flag are needed to make sure that various types extending another type can be used everywhere where that type is used, but here, since SUPIIMSI is restricted by the type IMSI, it seems like no IMSI_derivations should have been created in this case. The derivation becomes cyclical.
(I should add that we are trying to generate ETSI X1 protocol files from official ETSI specifications. The X1 xsd file requires the flag -h in order to create useful definitions, but it also uses the ETSI Types xsd, which contains the SUPIIMSI definition.)
Version: 7.1.0