diff --git a/pkg/xsd/element.go b/pkg/xsd/element.go index 8d9548f..3b95481 100644 --- a/pkg/xsd/element.go +++ b/pkg/xsd/element.go @@ -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:"-"` } diff --git a/pkg/xsd/schema.go b/pkg/xsd/schema.go index 976fd01..f5fce57 100644 --- a/pkg/xsd/schema.go +++ b/pkg/xsd/schema.go @@ -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:"-"` } @@ -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.") @@ -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 } diff --git a/pkg/xsd/types.go b/pkg/xsd/types.go index 9c8d238..ade4497 100644 --- a/pkg/xsd/types.go +++ b/pkg/xsd/types.go @@ -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"` @@ -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) +}