Skip to content

Commit

Permalink
Use form tags when available (#1422)
Browse files Browse the repository at this point in the history
* Add support for form tags

---------

Co-authored-by: Philip Constantinou <phil@Philips-MacBook-Pro-3.local>
  • Loading branch information
pconstantinou and Philip Constantinou authored Mar 13, 2023
1 parent 996983d commit 19ddb4d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
7 changes: 7 additions & 0 deletions field_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,20 @@ func (ps *tagBaseFieldParser) ShouldSkip() bool {

func (ps *tagBaseFieldParser) FieldName() (string, error) {
var name string

if ps.field.Tag != nil {
// json:"tag,hoge"
name = strings.TrimSpace(strings.Split(ps.tag.Get(jsonTag), ",")[0])

if name != "" {
return name, nil
}

// use "form" tag over json tag
name = strings.TrimSpace(strings.Split(ps.tag.Get(formTag), ",")[0])
if name != "" {
return name, nil
}
}

if ps.field.Names == nil {
Expand Down
1 change: 1 addition & 0 deletions operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ func (operation *Operation) ParseParamComment(commentLine string, astFile *ast.F
}

const (
formTag = "form"
jsonTag = "json"
bindingTag = "binding"
defaultTag = "default"
Expand Down

0 comments on commit 19ddb4d

Please sign in to comment.