From 2091937c9c5373879906799eb9107a492d485701 Mon Sep 17 00:00:00 2001 From: Iceflower Date: Wed, 19 Jun 2024 16:59:07 +0200 Subject: [PATCH] Export reference type --- pkg/xsd/attribute.go | 4 ++-- pkg/xsd/attributegroup.go | 2 +- pkg/xsd/common.go | 10 +++++----- pkg/xsd/element.go | 8 ++++---- pkg/xsd/extension.go | 6 +++--- pkg/xsd/restriction.go | 6 +++--- pkg/xsd/schema.go | 6 +++--- 7 files changed, 21 insertions(+), 21 deletions(-) diff --git a/pkg/xsd/attribute.go b/pkg/xsd/attribute.go index fc23b16..4b75245 100644 --- a/pkg/xsd/attribute.go +++ b/pkg/xsd/attribute.go @@ -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:"-"` diff --git a/pkg/xsd/attributegroup.go b/pkg/xsd/attributegroup.go index 85fe612..d6291e1 100644 --- a/pkg/xsd/attributegroup.go +++ b/pkg/xsd/attributegroup.go @@ -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:"-"` diff --git a/pkg/xsd/common.go b/pkg/xsd/common.go index 8ba03b3..c75425b 100644 --- a/pkg/xsd/common.go +++ b/pkg/xsd/common.go @@ -6,10 +6,10 @@ 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 "" @@ -17,11 +17,11 @@ func (ref reference) NsPrefix() string { 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()) } diff --git a/pkg/xsd/element.go b/pkg/xsd/element.go index 9b93839..ad46c08 100644 --- a/pkg/xsd/element.go +++ b/pkg/xsd/element.go @@ -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"` diff --git a/pkg/xsd/extension.go b/pkg/xsd/extension.go index 2c23a20..a443446 100644 --- a/pkg/xsd/extension.go +++ b/pkg/xsd/extension.go @@ -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 diff --git a/pkg/xsd/restriction.go b/pkg/xsd/restriction.go index 419760d..69497a8 100644 --- a/pkg/xsd/restriction.go +++ b/pkg/xsd/restriction.go @@ -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:"-"` diff --git a/pkg/xsd/schema.go b/pkg/xsd/schema.go index 4799aac..c2bda1f 100644 --- a/pkg/xsd/schema.go +++ b/pkg/xsd/schema.go @@ -69,7 +69,7 @@ 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.") @@ -77,7 +77,7 @@ func (sch *Schema) findReferencedAttribute(ref reference) *Attribute { 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.") @@ -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())