rootsdev / gedcomx-json-schema

JSON Schema (v4) for GEDCOM X
MIT License
4 stars 2 forks source link

Support extensions #11

Closed justincy closed 7 years ago

justincy commented 7 years ago

Provide an easy way for GedcomX extensions to use this library as a base and add their schema.

The tricky part is being able to hook into the hierarchy. The schema definition is output as a static JSON object but it's calculated on load to allow for inheritance of properties: Subject copies the properties of Conclusion which copies the properties of ExtensibleData. Ideally extensions wouldn't have to modify all inheriting data types if they add properties to Conclusion.

justincy commented 7 years ago

I don't know how this would be possible without calculating the schema definition on the fly. Instead of exporting a static object we would export a method which calculates and returns the schema. It would have properties attached to it which expose the data types and the hierarchy in a pseudo json-schema.

justincy commented 7 years ago

An example of what I was thinking:

// Fetch the schema
gedxSchema();

// The psuedo-schema
gedxSchema.Subject = {
    extends: 'Conclusion',
    type: 'object',
    properties: {...}
};

But that's actually not good enough. We would need to write the entire schema as a modified version with the extends keyword that gets interpreted at runtime and transformed into valid schema.

justincy commented 7 years ago

It appears that there's already a way to do this via the allOf keyword that requires a given element to successfully validate against all the referenced elements. I'll try it out.