xsd2go icon indicating copy to clipboard operation
xsd2go copied to clipboard

Support for `xsd:restriction` with empty base

Open aplr opened this issue 6 months ago • 1 comments

I'm getting the following error when trying to generate code from the referenced XSD files:

panic: Not implemented: xsd:extension/@base empty, cannot extend unknown type

The error is misleading, it should be "xsd:restriction/@base empty ...", I guess it was just copied from xsd:extension, that's one problem.

Below is the part of the XSD where the generator panics. I see this construct is overly complex and in go code it should realistically just be a simple float64 in this case. However, it would be good to have the generator not panic but rather skip / generate a simple type from that.

    <xsd:simpleType name="p7">
        <xsd:restriction> // Here's the empty restriction
            <xsd:simpleType>
                <xsd:union>
                    <xsd:simpleType>
                        <xsd:restriction base="xsd:decimal">
                            <xsd:totalDigits value="12" />
                            <xsd:fractionDigits value="2" />
                            <xsd:minInclusive value="0.01" />
                            <xsd:maxInclusive value="9999999999.99" />
                            <xsd:pattern value="[\+\-]?([1-9]\d{0,9}|0)(\.\d{2})" />
                        </xsd:restriction>
                    </xsd:simpleType>
                    <xsd:simpleType>
                        <xsd:restriction base="xsd:decimal">
                            <xsd:totalDigits value="12" />
                            <xsd:fractionDigits value="2" />
                            <xsd:minInclusive value="-9999999999.99" />
                            <xsd:maxInclusive value="-0.01" />
                            <xsd:pattern value="[\+\-]?([1-9]\d{0,9}|0)(\.\d{2})" />
                        </xsd:restriction>
                    </xsd:simpleType>
                </xsd:union>
            </xsd:simpleType>
        </xsd:restriction>
    </xsd:simpleType>

The XSDs can be downloaded from here: https://developer.datev.de/en/file-format/details/datev-xml-interface-online/xsdminusfiles. The failing restriction is in Belegverwaltung_online_ledger_types_v060.xsd

aplr avatar Jul 11 '25 08:07 aplr

Right, union within restriction is not yet implemented.

isimluk avatar Jul 11 '25 18:07 isimluk