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

Usability feature request #477

Open
crodwell opened this issue Jan 18, 2022 · 2 comments
Open

Usability feature request #477

crodwell opened this issue Jan 18, 2022 · 2 comments

Comments

@crodwell
Copy link
Contributor

crodwell commented Jan 18, 2022

Unless I'm mistaken, there is no easy way to dissect a RequestError into something useful for the user.

Take the following

requestError := err.(*openapi3filter.RequestError)

fmt.Println(requestError.Error())

/* output:
@body.name:
	Error at "/name":Field must be set to string or not be present
Schema:
  {
    "example": "doggie",
    "type": "string"
  }

Value:
  "number, integer"
*/

Further errors are just seperated via pipe and become unreadable quickly.

Would it make sense to define additional properties on the RequestError?

// RequestError is returned by ValidateRequest when request does not match OpenAPI spec
type RequestError struct {
	Input       *RequestValidationInput
	Parameter   *openapi3.Parameter
	RequestBody *openapi3.RequestBody
        ErrorItems []struct {
              Path  string                                                    // "/name"
              ValidationError string                                    //  "Field must be set to string or not be present"
        }
	Reason      string
	Err         error
}
@crodwell
Copy link
Contributor Author

likely related to #465

@fenollp
Copy link
Collaborator

fenollp commented Feb 23, 2022

ErrorItems is a sensible addition. Feel free to open a PR with some tests (please)

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

No branches or pull requests

2 participants