From 848236f3c9e41087f06e3bfc71e155a1f6ea689b Mon Sep 17 00:00:00 2001 From: Igor Makarov Date: Sun, 13 Sep 2020 18:38:25 +0400 Subject: [PATCH 1/2] Parse documentation for each enumeration value --- xsd/parse.go | 8 ++++++++ xsd/testdata/EnumWithDoc.json | 9 +++++++++ xsd/testdata/EnumWithDoc.xsd | 14 ++++++++++++++ xsd/xsd.go | 2 ++ 4 files changed, 33 insertions(+) create mode 100644 xsd/testdata/EnumWithDoc.json create mode 100644 xsd/testdata/EnumWithDoc.xsd 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..a8ba4a94 --- /dev/null +++ b/xsd/testdata/EnumWithDoc.json @@ -0,0 +1,9 @@ +{ + "RestrictionEnum": { + "Base": 38, + "Restriction": { + "Enum": ["FIRST", "SECOND"], + "EnumDoc": ["Documentation to value FIRST", "Documentation to value SECOND"] + } + } +} diff --git a/xsd/testdata/EnumWithDoc.xsd b/xsd/testdata/EnumWithDoc.xsd new file mode 100644 index 00000000..2e7034be --- /dev/null +++ b/xsd/testdata/EnumWithDoc.xsd @@ -0,0 +1,14 @@ + + + + + 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 From 28734953764428777320ddc2cbfc445e37bfff9d Mon Sep 17 00:00:00 2001 From: Igor Makarov Date: Sun, 13 Sep 2020 18:44:26 +0400 Subject: [PATCH 2/2] Add test case to RestrictionEnum --- xsd/testdata/EnumWithDoc.json | 5 +++-- xsd/testdata/EnumWithDoc.xsd | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/xsd/testdata/EnumWithDoc.json b/xsd/testdata/EnumWithDoc.json index a8ba4a94..150aed40 100644 --- a/xsd/testdata/EnumWithDoc.json +++ b/xsd/testdata/EnumWithDoc.json @@ -2,8 +2,9 @@ "RestrictionEnum": { "Base": 38, "Restriction": { - "Enum": ["FIRST", "SECOND"], + "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 index 2e7034be..bc480e9a 100644 --- a/xsd/testdata/EnumWithDoc.xsd +++ b/xsd/testdata/EnumWithDoc.xsd @@ -1,4 +1,7 @@ + + Documentation to restriction + @@ -10,5 +13,6 @@ Documentation to value SECOND +