Skip to content

Commit

Permalink
Start supporting xsd:simpleType along the xsd:complexType
Browse files Browse the repository at this point in the history
  • Loading branch information
isimluk committed May 26, 2020
1 parent c3fadd4 commit a46bb14
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/xsd/element.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type Element struct {
Ref reference `xml:"ref,attr"`
refElm *Element `xml:"-"`
ComplexType *ComplexType `xml:"complexType"`
refType *ComplexType `xml:"-"`
refType Type `xml:"-"`
schema *Schema `xml:"-"`
}

Expand Down
10 changes: 8 additions & 2 deletions pkg/xsd/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type Schema struct {
Elements []Element `xml:"element"`
Attributes []Attribute `xml:"attribute"`
ComplexTypes []ComplexType `xml:"complexType"`
SimpleTypes []SimpleType `xml:"simpleType"`
importedModules map[string]*Schema `xml:"-"`
ModulesPath string `xml:"-"`
}
Expand Down Expand Up @@ -67,7 +68,7 @@ func (sch *Schema) findReferencedElement(ref reference) *Element {
return innerSchema.GetElement(ref.Name())
}

func (sch *Schema) findReferencedType(ref reference) *ComplexType {
func (sch *Schema) findReferencedType(ref reference) Type {
innerSchema := sch.findReferencedSchemaByPrefix(ref.NsPrefix())
if innerSchema == nil {
panic("Internal error: referenced type '" + ref + "' cannot be found.")
Expand Down Expand Up @@ -132,12 +133,17 @@ func (sch *Schema) GetElement(name string) *Element {
return nil
}

func (sch *Schema) GetType(name string) *ComplexType {
func (sch *Schema) GetType(name string) Type {
for idx, typ := range sch.ComplexTypes {
if typ.Name == name {
return &sch.ComplexTypes[idx]
}
}
for idx, typ := range sch.SimpleTypes {
if typ.Name == name {
return &sch.SimpleTypes[idx]
}
}
return nil
}

Expand Down
13 changes: 13 additions & 0 deletions pkg/xsd/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import (
"github.com/iancoleman/strcase"
)

type Type interface {
GoName() string
}

type ComplexType struct {
XMLName xml.Name `xml:"http://www.w3.org/2001/XMLSchema complexType"`
Name string `xml:"name,attr"`
Expand All @@ -29,3 +33,12 @@ type Sequence struct {
XMLName xml.Name `xml:"http://www.w3.org/2001/XMLSchema sequence"`
Elements []Element `xml:"element"`
}

type SimpleType struct {
XMLName xml.Name `xml:"http://www.w3.org/2001/XMLSchema simpleType"`
Name string `xml:"name,attr"`
}

func (st *SimpleType) GoName() string {
return strcase.ToCamel(st.Name)
}

0 comments on commit a46bb14

Please # to comment.