mganss / XmlSchemaClassGenerator

Generate C# classes from XML Schema files
Apache License 2.0
603 stars 180 forks source link

Weird WSDL if there is Collection of enum #516

Closed Dialecticus closed 4 months ago

Dialecticus commented 4 months ago

Suppose we have this example.xsd:

<xs:schema xmlns:tns="example.com" targetNamespace="example.com" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="Example" type="tns:Example" />

<xs:complexType name="Example">
    <xs:sequence>
        <xs:element name="exampleString" type="xs:string" />
        <xs:element minOccurs="0" maxOccurs="unbounded" name="exampleThings" type="tns:Thing" />
    </xs:sequence>
</xs:complexType>

<xs:simpleType name="Thing">
   <xs:restriction base="xs:string">
      <xs:enumeration value="alpha" />
      <xs:enumeration value="beta" />
      <xs:enumeration value="gamma" />
   </xs:restriction>
</xs:simpleType>
</xs:schema>

If I use xscgen to create code from it, the code appears to be looking good. But, if I create a C# web service in .NET 6 with this Example class as a parameter to a web method the resulting WSDL will contain two definitions of Thing enum. First is the usual one:

<xsd:simpleType name="Thing">
   <xsd:restriction base="xsd:string">
      <xsd:enumeration value="alpha"/>
      <xsd:enumeration value="beta"/>
      <xsd:enumeration value="gamma"/>
   </xsd:restriction>
</xsd:simpleType>

The second one is weird (and unnecessary):

<xsd:complexType name="Thing">
   <xsd:sequence>
      <xsd:element minOccurs="1" maxOccurs="1" name="value__" type="xsd:int"/>
      <xsd:element minOccurs="1" maxOccurs="1" name="alpha" type="tns:Thing"/>
      <xsd:element minOccurs="1" maxOccurs="1" name="beta" type="tns:Thing"/>
      <xsd:element minOccurs="1" maxOccurs="1" name="gamma" type="tns:Thing"/>
   </xsd:sequence>
</xsd:complexType>

The second definition should not exist. What am I doing wrong? Code is generate with command line

xscgen example.xsd -a- --csm=Public -cc- -c -n:example.com

mganss commented 4 months ago

I have a feeling this is outside of the scope of XmlSchemaClassGenerator. Is it even valid to have two types with the same name?

Perhaps you can try and manually modify the code so that the complex type goes away? Then we can see if it's possible to suppress what's causing it from the output of xscgen.

Dialecticus commented 4 months ago

Yeah, probably a bug in SoapCore library (or maybe I need to configure it better). If I receive more info I'll come back here with it.