Validate requests
Created by: joshuai96
When a request body is bound, Echo does not validate the request body against the struct.
For example:
var request api.CreateComponentJSONRequestBody
err := ctx.Bind(&request)
if err != nil {
return echo.ErrInternalServerError
}
When this code receives a request in the form of an api.Incident
only the overlapping fileds (for api.Component
and api.Incident
it's the DisplayName
field) are filled. Neither leftovers of the request, nor unfilled struct fields raise an error.
Echo explicitly does not validate data.
Echo recommends implementing custom validators using thrid party libraries .
Most of the validtors use struct tags for validation, this can not be used with the api
package, because there the struct tags can not be set manually.
Echo seems to offer no way to get the leftover fields after binding, to easily check for mismatched request types.