flagpole icon indicating copy to clipboard operation
flagpole copied to clipboard

Feature Request: exclude/include paths in schema validation

Open DougForst opened this issue 5 years ago • 1 comments

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'] });

DougForst avatar Jun 12 '20 18:06 DougForst

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.

jasonbyrne avatar Jul 03 '20 18:07 jasonbyrne