Loyalty on show field name
guiferpa opened this issue · 3 comments
Problem
There is a problem when the JSON API has a field in camelCase. For this scene the gody change the field name to lowercase letters.
For example:
Request
POST - /users
Body
{
"firstName": ""
}
Output
field firstname cannot be empty
Solution
Probably a solution for it can be get field names from tag json, for example:
type User struct {
FirstName string `json:"firstName" validate:"not_empty"`
}
In this case the field name must will be firstName
I am trying to understand the issue. In blow snnipet, input is getting converted to lowercase
func (r *notEmpty) Validate(f, v, _ string) (bool, error) { if v == "" { return true, &ErrNotEmpty{strings.ToLower(f)} } return true, nil }
Where correction needs to be made??
Hey @HemantJoshi11
Take a look at line 96
Currently gody normalize struct field name to lowercase. The problem exists when someone use gody to validate JSON contracts from an API using camelCase.
If gody change all field name to lowercase the output doesnt make sense any more. In this case the correct output must will be firstName
and not firstname
.
@HemantJoshi11 you put here a from NotEmpty rule source code but It's just a example, this improvement must will works for all rules.