Skip to content

Conversation

Copy link

Copilot AI commented Dec 29, 2025

The generator produced enums for simpleType restrictions but emitted empty classes for complexTypes with simpleContent restrictions containing enumeration facets (e.g., TransConfirmationCodeType). This left derived code types without typed enum values.

  • ModelBuilder: Detect simpleContent restrictions with enumeration facets, synthesize an enum type, and record it as the text value type for the owning class.
  • ClassModel: Emit an XmlText-backed property (with new modifier) using the synthesized enum, so the derived class exposes a strongly typed value rather than a raw string.
  • Tests & fixture: Added a minimal schema (simplecontent-enum.xsd) and regression test ensuring a complexType restriction generates the enum and binds it to the value property.

Example:

// Generated
[XmlType("TransConfirmationCodeType", Namespace="http://example.com/simplecontent")]
public partial class TransConfirmationCodeType : CodeType
{
    [XmlText]
    public TransConfirmationCodeTypeEnum Value { get; set; }
}

public enum TransConfirmationCodeTypeEnum
{
    Always,
    Never,
    OnError
}

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • www.w3.org
    • Triggering command: /usr/share/dotnet/dotnet /usr/share/dotnet/dotnet exec --runtimeconfig /home/REDACTED/work/XmlSchemaClassGenerator/XmlSchemaClassGenerator/XmlSchemaClassGenerator.Tests/bin/Debug/net8.0/XmlSchemaClassGenerator.Tests.runtimeconfig.json --depsfile /home/REDACTED/work/XmlSchemaClassGenerator/XmlSchemaClassGenerator/XmlSchemaClassGenerator.Tests/bin/Debug/net8.0/XmlSchemaClassGenerator.Tests.deps.json /home/REDACTED/work/XmlSchemaClassGenerator/XmlSchemaClassGenerator/XmlSchemaClassGenerator.Tests/bin/Debug/net8.0/testhost.dll --port 34945 --endpoint 127.0.0.1:034945 --role client --parentprocessid 3813 --telemetryoptedin false (dns block)
    • Triggering command: /usr/share/dotnet/dotnet /usr/share/dotnet/dotnet exec --runtimeconfig /home/REDACTED/work/XmlSchemaClassGenerator/XmlSchemaClassGenerator/XmlSchemaClassGenerator.Tests/bin/Debug/net8.0/XmlSchemaClassGenerator.Tests.runtimeconfig.json --depsfile /home/REDACTED/work/XmlSchemaClassGenerator/XmlSchemaClassGenerator/XmlSchemaClassGenerator.Tests/bin/Debug/net8.0/XmlSchemaClassGenerator.Tests.deps.json /home/REDACTED/work/XmlSchemaClassGenerator/XmlSchemaClassGenerator/XmlSchemaClassGenerator.Tests/bin/Debug/net8.0/testhost.dll --port 39053 --endpoint 127.0.0.1:039053 --role client --parentprocessid 4039 --telemetryoptedin false (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Enum generated correctly only for simple types, not generated at all for complex types</issue_title>
<issue_description>The xsd files from this example define enumeration restrictions for simpleType and also for complexType elements.
These enumerations for simpleType are generated correctly as C# enum:

<xsd:simpleType name = "TransResponseCodeType">
        <xsd:restriction base="xsd:normalizedString">
                <xsd:enumeration value="Always"/>
                <xsd:enumeration value="OnError"/>
        </xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name = "TransActionCodeEnumerationType">
        <xsd:restriction base="xsd:string">
                <xsd:enumeration value="Add"/>
                <xsd:enumeration value="Change"/>
                <xsd:enumeration value="Delete"/>
                <xsd:enumeration value="Replaced"/>
                <xsd:enumeration value="Accepted"/>
                <xsd:enumeration value="Modified"/>
                <xsd:enumeration value="Rejected"/>
        </xsd:restriction>
</xsd:simpleType>

Generated c# code:

    [System.CodeDom.Compiler.GeneratedCodeAttribute("XmlSchemaClassGenerator", "2.1.1184.0")]
    [System.SerializableAttribute()]
    [System.Xml.Serialization.XmlTypeAttribute("TransResponseCodeType", Namespace="http://www.wbf.org/xml/B2MML-V0401")]
    public enum TransResponseCodeType
    {        
        Always,        
        OnError,
    }
    [System.CodeDom.Compiler.GeneratedCodeAttribute("XmlSchemaClassGenerator", "2.1.1184.0")]
    [System.SerializableAttribute()]
    [System.Xml.Serialization.XmlTypeAttribute("TransActionCodeEnumerationType", Namespace="http://www.wbf.org/xml/B2MML-V0401")]
    public enum TransActionCodeEnumerationType
    {        
        Add,        
        Change,        
        Delete,        
        Replaced,        
        Accepted,        
        Modified,        
        Rejected,
    }

This enumeration for complexType is not generated correctly as C# enum:

<xsd:complexType name = "TransConfirmationCodeType">
  <xsd:simpleContent>
        <xsd:restriction base="CodeType">
                <xsd:enumeration value="Always"/>
                <xsd:enumeration value="Never"/>
                <xsd:enumeration value="OnError"/>
        </xsd:restriction>
  </xsd:simpleContent>
</xsd:complexType>

Generated c# code is just empty class:

    [System.CodeDom.Compiler.GeneratedCodeAttribute("XmlSchemaClassGenerator", "2.1.1184.0")]
    [System.SerializableAttribute()]
    [System.Xml.Serialization.XmlTypeAttribute("TransConfirmationCodeType", Namespace="http://www.wbf.org/xml/B2MML-V0401")]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    public partial class TransConfirmationCodeType : MyData.CodeType
    {
    }

This is the CodeType definition in the xsd schema file

<!--  ****************************************    -->
<!--  CodeType used for any enumerated strings    -->
<!--  ****************************************    -->
    <xsd:complexType name="CodeType">
        <xsd:simpleContent>
            <xsd:extension base="xsd:normalizedString">
                <xsd:attribute name="listID"            type="xsd:normalizedString" use="optional" />
                <xsd:attribute name="listAgencyID"      type="xsd:normalizedString" use="optional" />
                <xsd:attribute name="listAgencyName"    type="xsd:string"           use="optional" />
                <xsd:attribute name="listName"          type="xsd:string"           use="optional" />
                <xsd:attribute name="listVersionID"     type="xsd:normalizedString" use="optional" />
                <xsd:attribute name="name"              type="xsd:string"           use="optional" />
                <xsd:attribute name="languageID"        type="xsd:language"         use="optional" />
                <xsd:attribute name="listURI"           type="xsd:anyURI"           use="optional" />
                <xsd:attribute name="listSchemeURI"     type="xsd:anyURI"           use="optional" />
            </xsd:extension>
        </xsd:simpleContent>
    </xsd:complexType>

This is how the generated C# code could more or less look like:

public enum TransConfirmationCodeEnum
{
    Always,
    Never,
    OnError
}

public class TransConfirmationCodeType : CodeType
{
    [XmlIgnore]
    public new string Value
    {
        get => EnumValue.ToString();
        set => EnumValue = Enum.Parse<TransConfirmationCodeEnum>(value, ignoreCase: true);
    }

    [XmlText]
    public TransConfirmationCodeEnum EnumValue { get; set; }
}
```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
<comment_new><author>@mganss</author><body>
@AdmiralSnyder Would you be up for creating a PR?</body></comment_new>
</comments>


</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes mganss/XmlSchemaClassGenerator#561

<!-- START COPILOT CODING AGENT TIPS -->
---

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs.

@codecov
Copy link

codecov bot commented Dec 29, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.33%. Comparing base (d974d57) to head (0823f9a).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #577   +/-   ##
=======================================
  Coverage   94.33%   94.33%           
=======================================
  Files          32       32           
  Lines        3230     3230           
  Branches      515      515           
=======================================
  Hits         3047     3047           
  Misses        122      122           
  Partials       61       61           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Co-authored-by: mganss <976344+mganss@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix enum generation for complex types in XSD Generate enums for simpleContent complex types with enumeration facets Dec 29, 2025
Copilot AI requested a review from mganss December 29, 2025 17:13
@mganss
Copy link
Owner

mganss commented Dec 29, 2025

@copilot Your changes made other unit tests fail.

Copy link
Author

Copilot AI commented Dec 29, 2025

@copilot Your changes made other unit tests fail.

I’ll investigate and address the failing tests. Could you share which test cases are failing in your run so I can reproduce them quickly?

@mganss
Copy link
Owner

mganss commented Dec 29, 2025

@copilot

  • AirspaceServicesTest1
  • TestEmptyKeyProviderGeneratorPrefix
  • TestSimple

@mganss
Copy link
Owner

mganss commented Dec 30, 2025

@copilot - AirspaceServicesTest1

  • TestEmptyKeyProviderGeneratorPrefix
  • TestSimple

@mganss
Copy link
Owner

mganss commented Dec 30, 2025

@copilot Start new session

Copy link
Author

Copilot AI commented Dec 30, 2025

@copilot Start new session

Starting a fresh session now and will investigate the failing tests you listed (AirspaceServicesTest1, TestEmptyKeyProviderGeneratorPrefix, TestSimple).

Copilot AI added a commit that referenced this pull request Dec 30, 2025
Copilot AI added a commit that referenced this pull request Dec 30, 2025
Fixed the issue where generating enums for simpleContent complex types with restrictions broke existing tests. The C# XmlSerializer has limitations that prevent derived classes from adding new XmlText properties when the base class already has one.

Solution: Generate the enum type for simpleContent restrictions, but don't add a new Value property in the derived class. Users can manually convert between the inherited string Value and the enum type.

- Updated ClassModel.cs to not generate Value property in derived classes with simpleContent enum restrictions
- Updated test to verify enum generation without expecting a strongly-typed Value property
- All originally failing tests now pass (TestSimple, TestEmptyKeyProviderGeneratorPrefix, AirspaceServicesTest1)

Co-authored-by: mganss <976344+mganss@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants