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

add parse documentation for each enumeration value #122

Open
wants to merge 2 commits 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions xsd/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"))
Expand Down Expand Up @@ -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
}

Expand Down
10 changes: 10 additions & 0 deletions xsd/testdata/EnumWithDoc.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
18 changes: 18 additions & 0 deletions xsd/testdata/EnumWithDoc.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<simpleType name="RestrictionEnum">
<annotation>
<documentation>Documentation to restriction</documentation>
</annotation>
<restriction base="string">
<enumeration value="FIRST">
<annotation>
<documentation>Documentation to value FIRST</documentation>
</annotation>
</enumeration>
<enumeration value="SECOND">
<annotation>
<documentation>Documentation to value SECOND</documentation>
</annotation>
</enumeration>
<enumeration value="OTHER"/>
</restriction>
</simpleType>
2 changes: 2 additions & 0 deletions xsd/xsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down