danivek/json-api-serializer

Is it possible to include resource level meta information?

kbsanders opened this issue · 2 comments

The JSON API spec states that resources can contain their own meta information:

https://jsonapi.org/format/#document-resource-objects

meta: a meta object containing non-standard meta-information about a resource that can not be represented as an attribute or relationship.

Note that this is different than top level (root) meta or relationship level meta. This is meta information that appears on each resource object.

I don't see a way to include resource meta using the serializer.

Trying to include a meta object or function when I register my type throws an error:

serializer.register( "Activity", {
    id: "activityId",
    whitelist: [ "name" ],
    topLevelMeta: { ... }, // <- Not the same as resource level meta
    meta: { ... } // <- Throws an error
});

Error: ValidationError: "meta" is not allowed

Is it possible to include resource level meta information?

Yes, actually meta object is missing for resource. Will try to add it ASAP.

I forked the repo and added it in. No tests added (yet). Please feel free to use that as a starting point, update it, or ignore it. I used the function version of meta (meta: function(data, extraData) {}) in my work to build values from properties in the data. I don't know how useful a static object version is for resource-level meta.

#74