Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional XmlQualifiedName for guid #403

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions XmlSchemaClassGenerator.Tests/XmlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ private static IEnumerable<string> ConvertXml(string name, string xsd, Generator
const string GraphMLPattern = "xsd/graphml/ygraphml.xsd";
const string UnionPattern = "xsd/union/union.xsd";
const string GuidPattern = "xsd/guid/*.xsd";
const string Guid2Pattern = "xsd/guid2/*.xsd";
const string NullableReferenceAttributesPattern = "xsd/nullablereferenceattributes/nullablereference.xsd";

// IATA test takes too long to perform every time
Expand Down Expand Up @@ -157,11 +158,13 @@ public void TestClient()
SharedTestFunctions.TestSamples(Output, "Client", ClientPattern);
}

[Fact, TestPriority(1)]
[Theory, TestPriority(1)]
[InlineData(GuidPattern)]
[InlineData(Guid2Pattern)]
[UseCulture("en-US")]
public void TestGuid()
public void TestGuid(string pattern)
{
var assembly = Compiler.Generate("Guid", GuidPattern);
var assembly = Compiler.Generate("Guid", pattern);
var testType = assembly.GetType("Guid.Test");
var idProperty = testType.GetProperty("Id");
var elementIdProperty = testType.GetProperty("ElementId");
Expand Down
14 changes: 14 additions & 0 deletions XmlSchemaClassGenerator.Tests/xsd/guid2/guid.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://schemas.microsoft.com/2003/10/Serialization/">
<xs:simpleType name="guid">
<xs:annotation>
<xs:documentation xml:lang="en">
The representation of a GUID, generally the id of an element.
</xs:documentation>
</xs:annotation>
<xs:restriction base="xs:string">
<xs:pattern value="[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
18 changes: 18 additions & 0 deletions XmlSchemaClassGenerator.Tests/xsd/guid2/guidtest.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<xs:schema targetNamespace="http://tempuri.org/XMLSchema.xsd"
elementFormDefault="qualified"
xmlns="http://tempuri.org/XMLSchema.xsd"
xmlns:mstns="http://tempuri.org/XMLSchema.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:s="http://schemas.microsoft.com/2003/10/Serialization/"
>
<xs:import namespace="http://schemas.microsoft.com/2003/10/Serialization/" schemaLocation="guid.xsd"></xs:import>
<xs:element name="Test">
<xs:complexType>
<xs:sequence>
<xs:element name="ElementId" type="s:guid"></xs:element>
</xs:sequence>
<xs:attribute name="Id" type="s:guid"></xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>
22 changes: 22 additions & 0 deletions XmlSchemaClassGenerator.Tests/xsd/guid2/header.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
id="BerichtHeaderSHV"
targetNamespace="http://tempuri.org/v1"
elementFormDefault="qualified"
xmlns="http://tempuri.org/v1"
version="1.0">

<xs:include schemaLocation="uuid.xsd"/>

<xs:complexType name="Header">
<xs:sequence>
<xs:element name="Reference" type="UUID"/>
<xs:element name="Receiver" type="UUID" minOccurs="0" nillable="true"/>
<xs:element name="CrossReference" type="UUID" minOccurs="0" nillable="true"/>
<xs:element name="ConversationReference" type="UUID" minOccurs="0" nillable="true"/>
<xs:element name="Version" type="xs:string"/>
</xs:sequence>
</xs:complexType>

<xs:element name="Header" type="Header"/>
</xs:schema>
17 changes: 17 additions & 0 deletions XmlSchemaClassGenerator.Tests/xsd/guid2/uuid.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:mxs="http://microsoft.com/wsdl/types/"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
id="UUID"
targetNamespace="http://tempuri.org/v1"
xmlns:t="http://tempuri.org/v1"
elementFormDefault="qualified"
version="1.0">

<xs:import schemaLocation="guid.xsd" namespace="http://schemas.microsoft.com/2003/10/Serialization/"/>
<xs:simpleType name="IntermediateUUID">
<xs:restriction base="mxs:guid"/>
</xs:simpleType>
<xs:simpleType name="UUID">
<xs:restriction base="t:IntermediateUUID" />
</xs:simpleType>
</xs:schema>
8 changes: 6 additions & 2 deletions XmlSchemaClassGenerator/CodeUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ private static Type GetIntegerDerivedType(XmlSchemaDatatype xml, GeneratorConfig
Type FromFallback() => configuration.UseIntegerDataTypeAsFallback && configuration.IntegerDataType != null ? configuration.IntegerDataType : typeof(string);
}

private static readonly XmlQualifiedName GuidQualifiedName = new("guid", "http://microsoft.com/wsdl/types/");
private static readonly XmlQualifiedName[] GuidQualifiedNames =
{
new("guid", "http://microsoft.com/wsdl/types/"),
new("guid", "http://schemas.microsoft.com/2003/10/Serialization/")
};

public static Type GetEffectiveType(this XmlSchemaDatatype type, GeneratorConfiguration configuration, IEnumerable<RestrictionModel> restrictions, XmlSchemaType schemaType, bool attribute = false)
{
Expand All @@ -114,7 +118,7 @@ public static Type GetEffectiveType(this XmlSchemaDatatype type, GeneratorConfig
_ => type.ValueType,
};

if (schemaType.IsDerivedFrom(GuidQualifiedName))
if (GuidQualifiedNames.Any(schemaType.IsDerivedFrom))
{
resultType = typeof(Guid);
}
Expand Down