Array type checking for attribute values

Hey, for citation we use a special node that has one attribute called “references” which is an array of objects, each of which need to have a “before”, “page” and “source” key. We need to do it like that because every citation contains several references and their rendering depends a bit on one-another.

For reading and writing to the dom, we simply turn the array into a string using JSON.stringify() and when parsing the DOM we now will do some checking instead of just doing JSON.parse(), but while looking at that I was wondering if we should not also do some checks like that when reading the document from the database, just to make sure it’s all as it should be.

Has anyone tried doing something like this by extending on how the schema definition in ProseMirror works?