flagpole
flagpole copied to clipboard
Feature Request: exclude/include paths in schema validation
It would be nice if the schema validation supported options to allow passing in a list of json paths to include and/or exclude.
For example:
const jsonData = {
links: {
first: 'http://example.com/events/12345',
},
data: {
type: 'event',
id: '01e84900-8c10-4234-9576-787fb8897399',
attributes: {
name: 'My Event',
},
relationships: {
createdByUser: {
data: { id: '123245', type: 'User' },
},
},
},
jsonapi: {
version: '1.0',
},
};
// Exclude jsonapi and data.relationships when comparing the schema
context.assert(jsonData).schema(fileName, true, { exclude: ['jsonapi', 'data.relationships'] });
// Only include links and the data objects when comparing the schema
context.assert(jsonData).schema(fileName, true, { include: ['links', 'data'] });
I think it's a nice idea. The only problem with it is that AJV does not have this feature as far as I can tell. Trying to maintain compatibility.