CaravanStudios / open-product-recovery

Apache License 2.0
26 stars 20 forks source link

Add type assertion capabilities to JSON schema validator #43

Closed johndayrichter closed 1 year ago

johndayrichter commented 1 year ago

Adds a validateAndCast(json, typeNameOrId) method to the JSON schema validator. This method throws an error if the given object does not validate against the given schema identifier. If validation passes, the object is automatically cast to the appropriate typescript type.

Note: This method throws a ValidatorError, NOT a StatusError. If this method is used by an OPR server, the resulting exception should be caught and rethrown as an appropriate StatusError.