Skip to content

Commit

Permalink
🐛 array form filed name should not contains bracket which led to inva…
Browse files Browse the repository at this point in the history
…lid fieldname in ts codegen
  • Loading branch information
Jinof committed Nov 20, 2023
1 parent 0ade78c commit dd220d1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion field_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (ps *tagBaseFieldParser) FieldName() (string, error) {

func (ps *tagBaseFieldParser) FormName() string {
if ps.field.Tag != nil {
return strings.TrimSpace(strings.Split(ps.tag.Get(formTag), ",")[0])
return strings.TrimRight(strings.TrimSpace(strings.Split(ps.tag.Get(formTag), ",")[0]), "[]")
}
return ""
}
Expand Down
22 changes: 22 additions & 0 deletions field_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -668,4 +668,26 @@ func TestValidTags(t *testing.T) {
assert.NoError(t, err)
assert.Empty(t, schema.Enum)
})

t.Run("Form Filed Name", func(t *testing.T) {
t.Parallel()

filedname, err := newTagBaseFieldParser(
&Parser{},
&ast.Field{Tag: &ast.BasicLit{
Value: `form:"test[]"`,
}},
).FieldName()
assert.NoError(t, err)
assert.Equal(t, "test", filedname)

filedname, err = newTagBaseFieldParser(
&Parser{},
&ast.Field{Tag: &ast.BasicLit{
Value: `form:"test"`,
}},
).FieldName()
assert.NoError(t, err)
assert.Equal(t, "test", filedname)
})
}

0 comments on commit dd220d1

Please sign in to comment.