Schema validator

Validating socket data made easy


SugoiJS provides easy, one line solution to validating the socket event payload using @SocketSchemaPolicy decorator.

The SocketSchemaPolicy is similar to server module RequestSchemaPolicy method.

How it works

Schema policy wrap the method with the SugoiJS core module ValidateSchemaUtil.validateArgs function. This function validate the payload using ComparableSchema object. In case the payload not fit the schema exception will thrown with details about the validation error.


For using the socket payload schema validator all you need to do is to add single line after the @SocketOn\@ServerOn decorators


registerForClientUsage(socket, msg) {

In that case we to validate the msg is indeed of type string, otherwise the function shouldn't apply.

Last updated