Json schema for validation in sync function

Can I make a feature request for a new function to be added to the sync function?

validate(doc, schema_url)

Where schema_url is the location of a JSON Schema document to validate against. It would raise an exception if validation fails.

This would make full validation of documents easier and help decompose the slightly over burdened sync function responsibilities.

There are both go and js validators for JSON Schema


(ajv looks nice)



1 Like

Thats a good idea. sync gateway might get a partial JSON string. There should be a way to handle that gracefully.

It would check that the function was valid json but it would also be a way to check the content of the json against a schema. It would be a replacement for writing JavaScript to check for required attributes etc.

This would make it much easier to manage avoiding malicious JSON content if you have large or many document types.

The schemas could also be used elsewhere in the project from other languages to centralise data validation, which is something Iā€™d find really useful. Maybe I need to find my golang for dummies.

I saw the pull request for this feature: https://github.com/couchbase/sync_gateway/pull/1470

But does anyone know when will this be live?

If you look at the comments on the pull request it seems like its on the todo list but not very near the top.

nudges @zgramana

this might help you in validating the documents