Skip to content

Commit

Permalink
fix: validator.v9 enum flag is "oneof"
Browse files Browse the repository at this point in the history
  • Loading branch information
denouche committed Dec 9, 2019
1 parent 24bd020 commit c8d4119
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docparser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
)

var enumRegex = regexp.MustCompile(`enum=([\w ]+)`)
var oneOfRegex = regexp.MustCompile(`oneof=([\w ]+)`) // validator.v9 enum tag is oneof

func parseFile(path string) (*ast.File, error) {
data, err := ioutil.ReadFile(path) // just pass the file name
Expand Down Expand Up @@ -61,6 +62,9 @@ func parseJSONTag(field *ast.Field) (j jsonTagInfo, err error) {
if matches := enumRegex.FindStringSubmatch(v); len(matches) > 0 {
j.enum = strings.Fields(matches[1])
}
if matches := oneOfRegex.FindStringSubmatch(v); len(matches) > 0 {
j.enum = strings.Fields(matches[1])
}
}

j.name = jsonName
Expand Down

0 comments on commit c8d4119

Please sign in to comment.