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

Export reference type #125

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/xsd/attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import (
type Attribute struct {
XMLName xml.Name `xml:"http://www.w3.org/2001/XMLSchema attribute"`
Name string `xml:"name,attr"`
Type reference `xml:"type,attr"`
Type Reference `xml:"type,attr"`
Use string `xml:"use,attr"`
DuplicateCount uint `xml:"-"`
Ref reference `xml:"ref,attr"`
Ref Reference `xml:"ref,attr"`
refAttr *Attribute `xml:"-"`
typ Type `xml:"-"`
schema *Schema `xml:"-"`
Expand Down
2 changes: 1 addition & 1 deletion pkg/xsd/attributegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
type AttributeGroup struct {
XMLName xml.Name `xml:"http://www.w3.org/2001/XMLSchema attributeGroup"`
Name string `xml:"name,attr"`
Ref reference `xml:"ref,attr"`
Ref Reference `xml:"ref,attr"`
AttributesDirect []Attribute `xml:"attribute"`
typ Type `xml:"-"`
schema *Schema `xml:"-"`
Expand Down
10 changes: 5 additions & 5 deletions pkg/xsd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ import (
"github.com/iancoleman/strcase"
)

// Internal XSD reference. Examples: "xml:lang", "cpe2:platform-specification"
type reference string
// Reference XSD reference. Examples: "xml:lang", "cpe2:platform-specification"
type Reference string

func (ref reference) NsPrefix() string {
func (ref Reference) NsPrefix() string {
colonPos := strings.Index(string(ref), ":")
if colonPos == -1 {
return ""
}
return string(ref)[0:colonPos]
}

func (ref reference) Name() string {
func (ref Reference) Name() string {
colonPos := strings.Index(string(ref), ":")
return string(ref)[colonPos+1:]
}

func (ref reference) GoName() string {
func (ref Reference) GoName() string {
return strcase.ToCamel(ref.NsPrefix()) + strcase.ToCamel(ref.Name())
}
8 changes: 4 additions & 4 deletions pkg/xsd/element.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ type Element struct {
Name string `xml:"name,attr"`
nameOverride string `xml:"-"`
XmlNameOverride string `xml:"-"`
FieldOverride bool `xml:"-"`
Type reference `xml:"type,attr"`
Ref reference `xml:"ref,attr"`
MinOccurs string `xml:"minOccurs,attr"`
FieldOverride bool `xml:"-"`
Type Reference `xml:"type,attr"`
Ref Reference `xml:"ref,attr"`
MinOccurs string `xml:"minOccurs,attr"`
MaxOccurs string `xml:"maxOccurs,attr"`
refElm *Element `xml:"-"`
ComplexType *ComplexType `xml:"complexType"`
Expand Down
6 changes: 3 additions & 3 deletions pkg/xsd/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
)

type Extension struct {
XMLName xml.Name `xml:"http://www.w3.org/2001/XMLSchema extension"`
Base reference `xml:"base,attr"`
AttributesDirect []Attribute `xml:"attribute"`
XMLName xml.Name `xml:"http://www.w3.org/2001/XMLSchema extension"`
Base Reference `xml:"base,attr"`
AttributesDirect []Attribute `xml:"attribute"`
AttributeGroups []AttributeGroup `xml:"attributeGroup"`
Sequence *Sequence `xml:"sequence"`
typ Type
Expand Down
6 changes: 3 additions & 3 deletions pkg/xsd/restriction.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
)

type Restriction struct {
XMLName xml.Name `xml:"http://www.w3.org/2001/XMLSchema restriction"`
Base reference `xml:"base,attr"`
AttributesDirect []Attribute `xml:"attribute"`
XMLName xml.Name `xml:"http://www.w3.org/2001/XMLSchema restriction"`
Base Reference `xml:"base,attr"`
AttributesDirect []Attribute `xml:"attribute"`
EnumsDirect []Enumeration `xml:"enumeration"`
SimpleContent *SimpleContent `xml:"simpleContent"`
schema *Schema `xml:"-"`
Expand Down
6 changes: 3 additions & 3 deletions pkg/xsd/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ func (sch *Schema) compile() {
}
}

func (sch *Schema) findReferencedAttribute(ref reference) *Attribute {
func (sch *Schema) findReferencedAttribute(ref Reference) *Attribute {
innerSchema := sch.findReferencedSchemaByPrefix(ref.NsPrefix())
if innerSchema == nil {
panic("Internal error: referenced attribute '" + ref + "' cannot be found.")
}
return innerSchema.GetAttribute(ref.Name())
}

func (sch *Schema) findReferencedElement(ref reference) *Element {
func (sch *Schema) findReferencedElement(ref Reference) *Element {
innerSchema := sch.findReferencedSchemaByPrefix(ref.NsPrefix())
if innerSchema == nil {
panic("Internal error: referenced element '" + string(ref) + "' cannot be found.")
Expand All @@ -89,7 +89,7 @@ func (sch *Schema) findReferencedElement(ref reference) *Element {
return innerSchema.GetElement(ref.Name())
}

func (sch *Schema) findReferencedType(ref reference) Type {
func (sch *Schema) findReferencedType(ref Reference) Type {
innerSchema := sch.findReferencedSchemaByPrefix(ref.NsPrefix())
if innerSchema == nil {
xmlnsUri := sch.Xmlns.UriByPrefix(ref.NsPrefix())
Expand Down