orisai / object-mapper

Raw data mapping to validated objects
Mozilla Public License 2.0
10 stars 1 forks source link

Types - invalid value tracking #10

Closed mabar closed 3 years ago

mabar commented 3 years ago

Types are representation of whole VO structure and are also able to track exact keys which are invalid. In order to check which keys were invalid, user has to compare invalid keys with sent data and that's impractical.

All the Type methods which mark value invalid should be required to also add that value to Type so it could be rendered together with invalid key by Formatter.

In this stage we should resolve the problem to satisfaction just in Type. Optimal rendering in ErrorFormatter could be quite complex and for now only minimal implementation in VisualErrorFormatter should be enough to verify solution - something like key: string (received int(123) instead)

mabar commented 3 years ago

Most complicated part of issue is having an easy to understand and hard to misuse API.

e.g. StringRule uses SimpleValueType which can mark multiple parameters (minLength, notEmpty, pattern, ...) invalid at the same time. In case any of the parameters is invalid (markParameterInvalid()) then invalid value should be tracked, but it does not make sense to add invalid value with each markParameterInvalid() call. Some higher level errors api (object wrapping invalid value and parameters) is needed in order to not be able mark parameter invalid without adding invalid value and vice-versa.

In case StringRule validation fails completely (value is not a string), rule throws an exception and invalidation is handled by rule above - one of ArrayOfRule, ListOfRule, AnyOfRule, AllOfRule or StructureRule.

AnyOfRule and AllOfRule should be handled carefully. Both of these rules use CompoundType but have one important difference:

@mrceperka Hope it is understandable, let me know in case anything is unclear.

github-actions[bot] commented 2 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.