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

improve anonymous type handling #143

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

SoMuchForSubtlety
Copy link

This PR introduces multiple improves in handling anonymous types:

coalesce identical anonymous types

old behaviour:

type Anon1 struct {
	Elem []string `xml:"http://example.org/ Elem,omitempty"`
}

type Anon2 struct {
	Elem []string `xml:"http://example.org/ Elem,omitempty"`
}

type ListType struct {
	Elem []string `xml:"http://example.org/ Elem,omitempty"`
}

type Type1 struct {
	ListType ListType `xml:"http://example.org/ ListType,omitempty"`
}

type Type2 struct {
	ListType Anon2 `xml:"http://example.org/ ListType,omitempty"`
}

new behaviour:

type ListType struct {
	Elem []string `xml:"http://example.org/ Elem,omitempty"`
}

type Type1 struct {
	ListType ListType `xml:"http://example.org/ ListType,omitempty"`
}

type Type2 struct {
	ListType ListType `xml:"http://example.org/ ListType,omitempty"`
}

remove dangling anon types

The elements in the xml tree would not be properly updated because children weren't stored as pointers. this left unused types in the final output (see Anon1 in the previous example).

use numbered names instead of Anon

If an anonymous type can't be named after the parent's attribute, then try with an integer suffix instead of naming it Anon. Eg. if ListType is already in use, the name the next anonymous type ListType1 (if the elements are not identical anyways).

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.

None yet

1 participant