diff --git a/xsd/parse.go b/xsd/parse.go index 91f96422..9323f29c 100644 --- a/xsd/parse.go +++ b/xsd/parse.go @@ -850,6 +850,7 @@ func parseAnnotation(el *xmltree.Element) (doc annotation) { func parseSimpleRestriction(root *xmltree.Element, base Type) Restriction { var r Restriction var doc annotation + var enumDoc []annotation // Most of the restrictions on a simpleType are suited for // validating input. This package is not a validator; we assume // that the server sends valid data, and that it will tell us if @@ -859,6 +860,9 @@ func parseSimpleRestriction(root *xmltree.Element, base Type) Restriction { switch el.Name.Local { case "enumeration": r.Enum = append(r.Enum, el.Attr("", "value")) + walk(el, func(enumChild *xmltree.Element) { + enumDoc = append(enumDoc, parseAnnotation(enumChild)) + }) case "minExclusive", "minInclusive": if v, ok := base.(Builtin); ok && v == Date { d, err := time.Parse("2006-01-02", el.Attr("", "value")) @@ -930,6 +934,10 @@ func parseSimpleRestriction(root *xmltree.Element, base Type) Restriction { } }) r.Doc = string(doc) + r.EnumDoc = make([]string, len(enumDoc)) + for idx := range enumDoc { + r.EnumDoc[idx] = string(enumDoc[idx]) + } return r } diff --git a/xsd/testdata/EnumWithDoc.json b/xsd/testdata/EnumWithDoc.json new file mode 100644 index 00000000..150aed40 --- /dev/null +++ b/xsd/testdata/EnumWithDoc.json @@ -0,0 +1,10 @@ +{ + "RestrictionEnum": { + "Base": 38, + "Restriction": { + "Enum": ["FIRST", "SECOND", "OTHER"], + "EnumDoc": ["Documentation to value FIRST", "Documentation to value SECOND"] + }, + "Doc": "Documentation to restriction" + } +} diff --git a/xsd/testdata/EnumWithDoc.xsd b/xsd/testdata/EnumWithDoc.xsd new file mode 100644 index 00000000..bc480e9a --- /dev/null +++ b/xsd/testdata/EnumWithDoc.xsd @@ -0,0 +1,18 @@ + + + Documentation to restriction + + + + + Documentation to value FIRST + + + + + Documentation to value SECOND + + + + + diff --git a/xsd/xsd.go b/xsd/xsd.go index 259f8967..6b6add21 100644 --- a/xsd/xsd.go +++ b/xsd/xsd.go @@ -225,6 +225,8 @@ type Restriction struct { // If len(Enum) > 0, the type must be one of the values contained // in Enum. Enum []string + // Any annotations for each Enum + EnumDoc []string // The minimum and maximum (exclusive) value of this type, if // numeric Min, Max float64