libopenapi-validator icon indicating copy to clipboard operation
libopenapi-validator copied to clipboard

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

Open abhishek-galoda opened this issue 1 year ago • 2 comments

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

abhishek-galoda avatar Feb 16 '24 20:02 abhishek-galoda

OK.

daveshanley avatar Feb 22 '24 11:02 daveshanley

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

eliofery avatar Jun 18 '24 16:06 eliofery