Skip to content

Commit

Permalink
Merge pull request #30 from nicoflink/bugfix/Usage-SimpleTypes
Browse files Browse the repository at this point in the history
Use SimpleTypes in elements
  • Loading branch information
isimluk authored Nov 27, 2021
2 parents 1ff4e8b + a7cf97c commit f6c28e9
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 18 deletions.
2 changes: 1 addition & 1 deletion pkg/template/pkged.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/template/types.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import (

// XSD SimpleType declarations
{{range .ExportableSimpleTypes }}
type {{ .GoName }} string
type {{ .GoName }} {{ .GoTypeName }}

{{ $simpleType := . }}
{{ range .Enums }}
Expand Down
2 changes: 1 addition & 1 deletion pkg/xsd/element.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (e *Element) GoMemLayout() string {

func (e *Element) GoTypeName() string {
if e.Type != "" {
return e.typ.GoTypeName()
return e.typ.GoName()
} else if e.Ref != "" {
return e.refElm.GoTypeName()
} else if e.isPlainString() {
Expand Down
4 changes: 4 additions & 0 deletions pkg/xsd/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ func (st *SimpleType) compile(sch *Schema, parentElement *Element) {
if st.schema == nil {
st.schema = sch
}

if st.Restriction != nil {
st.Restriction.compile(sch, parentElement)
}
}

func (st *SimpleType) Attributes() []Attribute {
Expand Down
30 changes: 15 additions & 15 deletions tests/xsd-examples/valid/xmldsig-core-schema.xsd.out
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type SignatureMethod struct {

Algorithm string `xml:"Algorithm,attr"`

HMACOutputLength string `xml:",any"`
HMACOutputLength *HMACOutputLengthType `xml:",any"`
}

// Element
Expand All @@ -73,7 +73,7 @@ type Reference struct {

DigestMethod DigestMethodType `xml:"DigestMethod"`

DigestValue string `xml:"DigestValue"`
DigestValue DigestValueType `xml:"DigestValue"`
}

// Element
Expand Down Expand Up @@ -234,20 +234,20 @@ type SignatureProperty struct {
type DSAKeyValue struct {
XMLName xml.Name `xml:"DSAKeyValue"`

G string `xml:"G"`
G *CryptoBinary `xml:"G"`

Y string `xml:"Y"`
Y CryptoBinary `xml:"Y"`

J string `xml:"J"`
J *CryptoBinary `xml:"J"`
}

// Element
type RSAKeyValue struct {
XMLName xml.Name `xml:"RSAKeyValue"`

Modulus string `xml:"Modulus"`
Modulus CryptoBinary `xml:"Modulus"`

Exponent string `xml:"Exponent"`
Exponent CryptoBinary `xml:"Exponent"`
}

// XSD ComplexType declarations
Expand Down Expand Up @@ -304,7 +304,7 @@ type SignatureMethodType struct {

Algorithm string `xml:"Algorithm,attr"`

HMACOutputLength string `xml:",any"`
HMACOutputLength *HMACOutputLengthType `xml:",any"`

InnerXml string `xml:",innerxml"`
}
Expand All @@ -322,7 +322,7 @@ type ReferenceType struct {

DigestMethod DigestMethodType `xml:"DigestMethod"`

DigestValue string `xml:"DigestValue"`
DigestValue DigestValueType `xml:"DigestValue"`

InnerXml string `xml:",innerxml"`
}
Expand Down Expand Up @@ -486,21 +486,21 @@ type SignaturePropertyType struct {
type DSAKeyValueType struct {
XMLName xml.Name

G string `xml:"G"`
G *CryptoBinary `xml:"G"`

Y string `xml:"Y"`
Y CryptoBinary `xml:"Y"`

J string `xml:"J"`
J *CryptoBinary `xml:"J"`

InnerXml string `xml:",innerxml"`
}

type RSAKeyValueType struct {
XMLName xml.Name

Modulus string `xml:"Modulus"`
Modulus CryptoBinary `xml:"Modulus"`

Exponent string `xml:"Exponent"`
Exponent CryptoBinary `xml:"Exponent"`

InnerXml string `xml:",innerxml"`
}
Expand All @@ -511,4 +511,4 @@ type CryptoBinary string

type DigestValueType string

type HMACOutputLengthType string
type HMACOutputLengthType int64

0 comments on commit f6c28e9

Please sign in to comment.