redhat-developer / vscode-xml

Editing XML in Visual Studio Code made easy
Eclipse Public License 2.0
262 stars 82 forks source link

`Insert only required elements` adds optional elements #993

Open GniLudio opened 6 months ago

GniLudio commented 6 months ago

I have the following xsd with these types: Timestamp, EpisodeID, EpisodeTime, EpisodeType. But Insert only required elements adds episodeType altough that element is optional.

XSD (test.xsd)

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="testing" xmlns="testing" elementFormDefault="qualified">
    <!-- Just setting root to a timestamp -->
    <xs:element name="root" type="Timestamp" />

    <!-- Timestamp: EpisodeID + EpisodeTime -->
    <xs:complexType name="Timestamp">
        <xs:complexContent>
            <xs:extension base="EpisodeID">
                <xs:sequence>
                    <xs:element name="episodeTime" type="EpisodeTime" />
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>

    <!-- EpisodeID: EpisodeNumber + EpisodeType (optional) -->
    <xs:complexType name="EpisodeID">
        <xs:sequence>
            <xs:element name="episode" type="xs:decimal"></xs:element>
            <xs:element name="episodeType" type="EpisodeType" minOccurs="0" />
        </xs:sequence>
    </xs:complexType>

    <!-- EpisodeTime: eg. 00:00:00 or 05:33 -->
    <xs:simpleType name="EpisodeTime">
        <xs:restriction base="xs:string">
            <xs:pattern value="([0-9]?[0-9]:)?([0-9]?[0-9]:)?([0-9]?[0-9])" />
        </xs:restriction>
    </xs:simpleType>

    <!-- EpisodeType: full | trailer | bonus -->
    <xs:simpleType name="EpisodeType">
        <xs:restriction base="xs:string">
            <xs:enumeration value="full" />
            <xs:enumeration value="trailer" />
            <xs:enumeration value="bonus" />
        </xs:restriction>
    </xs:simpleType>
</xs:schema>

XML (test.xml)

Before inserting required elements:

<?xml version="1.0" encoding="UTF-8"?>
<root
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="testing" 
    xsi:schemaLocation="testing test.xsd">
</root>

After inserting required elements:

<?xml version="1.0" encoding="UTF-8"?>
<root
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="testing" 
    xsi:schemaLocation="testing test.xsd">
    <episode></episode>
    <episodeType>full</episodeType>
    <episodeTime></episodeTime>
</root>
angelozerr commented 6 months ago

Thanks for having reported the issue.

I think it is a usecase we dont cover. Need some times to investigate the problem.

GniLudio commented 6 months ago

I think it is caused by extending multiple times. (the bug doesn't occur when inlining everything in Timestamp)

angelozerr commented 6 months ago

Ok thanks for your feedback.