nette / schema

📐 Validating data structures against a given Schema.
https://doc.nette.org/schema
Other
886 stars 26 forks source link

Custom error message mapping #34

Closed repli2dev closed 3 years ago

repli2dev commented 3 years ago

The error messages created by the library are quite nice (they contain path, expected type and actual values). However in usability in real world APIs (at least at our company) we need programatically to map these error messages to either our error codes (numbers or strings) or custom error messages for example to provide more details, links or just keep consistent with our documentation language.

dg commented 3 years ago

There is also codes in error messages.

repli2dev commented 3 years ago

Thanks for pushing it forward...

I have tested today and attempted to use it to reimplement our validation structure these our my findings:

Not any of this is a blocker for our purpose, though they make the nice validation structure a bit harder to read due to high number of custom validators.

Feel free to utiilize this feedback or close the issue :-)

repli2dev commented 3 years ago

My note about readability could be addressed by creating custom Scheme implementations (with custom rules), however from docs I am not sure if it is a supported way we could potentially rely on.

dg commented 3 years ago

@repli2dev I added two new errors Message::OUT_OF_RANGE & Message::LENGTH_OUT_OF_RANGE for min/max violations

ad DateTime: try to create a separate issue on it, so that it is not forgotten

repli2dev commented 3 years ago

@dg created #36 for the DateTime, thanks for the new codes.