-
Notifications
You must be signed in to change notification settings - Fork 50
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
Return all errors instead of raising exception #103
Comments
The validation is not usable to our project as implemented.Here is our use case:We have a If I have, for example, a "type" field that need to have a value of "FooType" for this payload to be positively identified I might write something like: class FooEvent extends Payload
{
const TYPE = "FooType";
// ... other fields
public string $type;
public static function setUpProperties($props, $schema)
{
// ...
$props->type = Schema::string();
$props->type->enum = [self::TYPE];
// ...
}
public static function positivelyIdentified(Error $error): bool
{
/* Basically if the type value provided is correct the payload is positively identified
and the payload map should not continue to try the data against other payload classes */
return array_search(
"/definitions/FooEvent/properties/type",
$error->schemaPointers
) == false;
}
} But this code flow doesn't work if some unimportant field happens to raise the exception first. Subset of the code talked aboutconst CONTENT_TYPE_JSON = "application/json";
abstract class Payload {
use ClassStructureTrait;
public abstract static function setUpProperties($props, Schema $schema);
public static function parse($data, $contentType = CONTENT_TYPE_JSON) : self
{
// Choose a decoding function based on contentType and then return self::import($decodedData)
}
public static function positivelyIdentified(Error $error): bool
{
return false;
}
}
class PayloadMap {
public function dispatch($data, string $contentType = CONTENT_TYPE_JSON, $errorHandler = null) {
// ...
// the key of the map is the Payload class and the value is a list of handlers / callbacks
// ...
}
} |
I was trying to migrate from justinrainbow/json-schema for validation, but while with other libraries you can get a list of the not passing validations with this one you can only obtain the first one.
It will be handy to have a option to specify that you don't want to throw an exception on the first error.
The text was updated successfully, but these errors were encountered: