Skip to content

Commit

Permalink
Merge pull request #214 from ieure/fix-complextype-string-aliasing
Browse files Browse the repository at this point in the history
Correctly generate `complexType`s which extend `string`.
  • Loading branch information
c4milo authored Dec 2, 2021
2 parents 9e1cc9a + e6365dc commit 3ba62c6
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
6 changes: 5 additions & 1 deletion fixtures/epcis/epcisquery.src
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ type Partner struct {
ContactInformation []*ContactInformation `xml:"ContactInformation,omitempty" json:"ContactInformation,omitempty"`
}

type PartnerIdentification string
type PartnerIdentification struct {
Value string `xml:",chardata" json:"-,"`

Authority string `xml:"Authority,attr,omitempty" json:"Authority,omitempty"`
}

type ContactInformation struct {
Contact string `xml:"Contact,omitempty" json:"Contact,omitempty"`
Expand Down
22 changes: 22 additions & 0 deletions fixtures/workday-time-min.wsdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wd-wsdl="urn:com.workday/bsvc/Time_Tracking" xmlns:wd="urn:com.workday/bsvc" xmlns:nyw="urn:com.netyourwork/aod" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapbind="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:httpbind="http://schemas.xmlsoap.org/wsdl/http/" xmlns:mimebind="http://schemas.xmlsoap.org/wsdl/mime/" name="Time_Tracking" targetNamespace="urn:com.workday/bsvc/Time_Tracking">
<wsdl:documentation>Operations for importing and exporting time and work schedule information.</wsdl:documentation>
<wsdl:types>
<xsd:schema elementFormDefault="qualified" attributeFormDefault="qualified" targetNamespace="urn:com.workday/bsvc">
<xsd:complexType name="WorkerObjectIDType">
<xsd:annotation>
<xsd:documentation>Contains a unique identifier for an instance of an object.</xsd:documentation>
</xsd:annotation>
<xsd:simpleContent>
<xsd:extension base="xsd:string">
<xsd:attribute name="type" type="wd:WorkerReferenceEnumeration" use="required">
<xsd:annotation>
<xsd:documentation>The unique identifier type. Each "ID" for an instance of an object contains a type and a value. A single instance of an object can have multiple "ID" but only a single "ID" per "type". Some "types" require a reference to a parent instance.</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
</xsd:schema>
</wsdl:types>
</wsdl:definitions>
24 changes: 24 additions & 0 deletions gowsdl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,30 @@ func TestEnumerationsGeneratedCorrectly(t *testing.T) {

}

func TestComplexTypeGeneratedCorrectly(t *testing.T) {
g, err := NewGoWSDL("fixtures/workday-time-min.wsdl", "myservice", false, true)
if err != nil {
t.Error(err)
}

resp, err := g.Start()
if err != nil {
t.Error(err)
}

decl, err := getTypeDeclaration(resp, "WorkerObjectIDType")

expected := "type WorkerObjectIDType struct"
re := regexp.MustCompile(expected)
matches := re.FindStringSubmatch(decl)

if len(matches) != 1 {
t.Errorf("No match or too many matches found for WorkerObjectIDType")
} else if matches[0] != expected {
t.Errorf("WorkerObjectIDType got '%s' but expected '%s'", matches[1], expected)
}
}

func TestEPCISWSDL(t *testing.T) {
log.SetFlags(0)
log.SetOutput(os.Stdout)
Expand Down
2 changes: 1 addition & 1 deletion types_tmpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ var typesTmpl = `
{{range .ComplexTypes}}
{{/* ComplexTypeGlobal */}}
{{$name := replaceReservedWords .Name | makePublic}}
{{if eq (toGoType .SimpleContent.Extension.Base false) "string"}}
{{if and (eq (len .SimpleContent.Extension.Attributes) 0) (eq (toGoType .SimpleContent.Extension.Base false) "string") }}
type {{$name}} string
{{else}}
type {{$name}} struct {
Expand Down

0 comments on commit 3ba62c6

Please sign in to comment.