Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request - To get the field name from the incoming request #52

Open
abhishek-galoda opened this issue Feb 16, 2024 · 2 comments
Open
Labels
enhancement New feature or request

Comments

@abhishek-galoda
Copy link

Hello,

I would like to ask, if you can add a feature where in Request/Response Validation Errors we can get the "field" name . This is also provided in Kin api but not in this API.

I think this would be great addittion to this great API

@daveshanley
Copy link
Member

OK.

@daveshanley daveshanley added the enhancement New feature or request label Feb 22, 2024
@eliofery
Copy link

Is there progress in this direction?

Since it is impossible to directly obtain the field name, you have to use regular expressions.

Example:

func errorFormat(errMsg error) error {
    reg, err := regexp.Compile(`Reason: (.*), Location: (.*)`)
    if err != nil {
        return err
    }

    match := reg.FindStringSubmatch(errMsg.Error())
    if len(match) > 2 {
        return fmt.Errorf("%s: %s", match[2], match[1])
    }

    return errMsg
}

Which is not entirely convenient and instead of the field name you get something like this: /properties/password/minLength

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants