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

xsdgen: duplicated fields for nested complexType #41

Closed
flisky opened this issue Oct 26, 2017 · 6 comments
Closed

xsdgen: duplicated fields for nested complexType #41

flisky opened this issue Oct 26, 2017 · 6 comments

Comments

@flisky
Copy link
Contributor

flisky commented Oct 26, 2017

Such as the following diff:

diff --git a/xsd/testdata/ComplexType.xsd b/xsd/testdata/ComplexType.xsd
index f7f060b..dcf9ce8 100644
--- a/xsd/testdata/ComplexType.xsd
+++ b/xsd/testdata/ComplexType.xsd
@@ -5,12 +5,13 @@
     <element name='ContactTitle' type='string'/>
     <element name='Phone' type='string'/>
     <element name='Fax' minOccurs='0' type='string'/>
-    <element name='FullAddress' type='tns:AddressType'/>
+    <element name='FullAddress' ref='tns:AddressType'/>
   </sequence>
   <attribute name='CustomerID' type='token'/>
 </complexType>

-<complexType name='AddressType'>
+<element name='AddressType'>
+<complexType>
   <sequence>
     <element name='Address' type='string'/>
     <element name='City' type='string'/>
@@ -20,3 +21,4 @@
   </sequence>
   <attribute name='CustomerID' type='token'/>
 </complexType>
+</element>
diff --git a/xsd/xsd_test.go b/xsd/xsd_test.go
index 5307fe3..6c461e5 100644
--- a/xsd/xsd_test.go
+++ b/xsd/xsd_test.go
@@ -151,7 +151,7 @@ func unmarshal(t *testing.T, data []byte) blob {

 func parseFragment(t *testing.T, filename string) Schema {
 	const tmpl = `<schema targetNamespace="tns" ` +
-		`xmlns="http://www.w3.org/2001/XMLSchema">%s</schema>`
+		`xmlns="http://www.w3.org/2001/XMLSchema" xmlns:tns="tns">%s</schema>`
 	data, err := ioutil.ReadFile(filename)
 	if err != nil {
 		t.Fatal(err)
@droyo
Copy link
Owner

droyo commented Oct 27, 2017

The bug is here:

ref.StartElement = real.StartElement

Ironically I had the comment "It's OK to modify ref", but I neglected to say "It's not OK to modify real" :)

@flisky
Copy link
Contributor Author

flisky commented Oct 27, 2017

Sorry, the above case is still failed. Could you please take a double check?

@droyo droyo reopened this Oct 27, 2017
droyo added a commit that referenced this issue Oct 27, 2017
@droyo
Copy link
Owner

droyo commented Oct 27, 2017

OK, I pushed the dup-deref branch with your patch applied, plus some extra logging to show the XML pre-processing output.

I can see what's happening now; we give the anonymous complexType a name, but when its container is dereferenced, the type comes along with it.

I think a sensible approach would be to move any nested type declarations up to the top-level if/when they get a name. Need to be a little careful when "un-nesting" anonymous types that themselves contain anonymous types.

That said, the current behavior shouldn't do any harm; the duplicated anonymous type is simply ignored. PR #43 fixed the harmful error where the source element was renamed.

@droyo
Copy link
Owner

droyo commented Oct 27, 2017

Ah, I can see the other problem; the type name is copied, so now you have two types named AddressType. Sorry it took me so long to realize :)

droyo added a commit that referenced this issue Oct 28, 2017
This avoids unnecessary copying when dereferencing links in XSD,
which can introduce duplicate type names (see #41).

One caveat to this change is that elements that contain chardata
alongside anonymous types, that chardata will be removed. I'm fine
with this.
@droyo
Copy link
Owner

droyo commented Oct 28, 2017

Ok, this should be fixed. Give it a try and let me know if you have any trouble.

@flisky
Copy link
Contributor Author

flisky commented Oct 28, 2017

Confirmed, and thanks!

@flisky flisky closed this as completed Oct 28, 2017
LudmilaSamalova pushed a commit to Deutsche-Boerse/go-xml that referenced this issue Jan 2, 2020
LudmilaSamalova pushed a commit to Deutsche-Boerse/go-xml that referenced this issue Jan 2, 2020
LudmilaSamalova pushed a commit to Deutsche-Boerse/go-xml that referenced this issue Jan 2, 2020
This avoids unnecessary copying when dereferencing links in XSD,
which can introduce duplicate type names (see droyo#41).

One caveat to this change is that elements that contain chardata
alongside anonymous types, that chardata will be removed. I'm fine
with this.
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

No branches or pull requests

2 participants