mirror of
https://github.com/strapi/strapi.git
synced 2025-12-27 15:13:21 +00:00
Update jsonapi-serializer and consider configuration on relationships
This commit is contained in:
parent
4725e87cc4
commit
5995bccf8d
@ -6,7 +6,7 @@
|
||||
|
||||
// Public node modules.
|
||||
const _ = require('lodash');
|
||||
const JSONAPISerializer = require('jsonapi-serializer');
|
||||
const JSONAPI = require('jsonapi-serializer');
|
||||
|
||||
// Local Strapi dependencies.
|
||||
const utils = require('../utils/utils');
|
||||
@ -68,7 +68,7 @@ module.exports = {
|
||||
|
||||
// Assign custom configurations
|
||||
if (_.isPlainObject(strapi.config.jsonapi) && !_.isEmpty(strapi.config.jsonapi)) {
|
||||
_.assign(toSerialize, _.omit(strapi.config.jsonapi, 'enabled'));
|
||||
_.assign(toSerialize, _.pick(strapi.config.jsonapi, 'keyForAttribute'));
|
||||
}
|
||||
|
||||
const PK = utils.getPK(type);
|
||||
@ -125,14 +125,14 @@ module.exports = {
|
||||
|
||||
// Display JSON API version support
|
||||
if (_.isPlainObject(strapi.config.jsonapi) && strapi.config.jsonapi.hasOwnProperty('showVersion') && strapi.config.jsonapi.showVersion === true) {
|
||||
return _.assign(new JSONAPISerializer(type, value, toSerialize), {
|
||||
return _.assign(new JSONAPI(type, value, toSerialize), {
|
||||
jsonapi: {
|
||||
version: '1.0'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return new JSONAPISerializer(type, value, toSerialize);
|
||||
return new JSONAPI.Serializer(type, value, toSerialize);
|
||||
},
|
||||
|
||||
/**
|
||||
@ -155,6 +155,8 @@ module.exports = {
|
||||
// Object
|
||||
toSerialize[relation.alias] = {
|
||||
ref: PK,
|
||||
included: strapi.config.jsonapi.included || false,
|
||||
ignoreRelationshipData: strapi.config.jsonapi.ignoreRelationshipData || false,
|
||||
attributes: _.keys(_.omit(strapi.models[type].attributes, _.isFunction)),
|
||||
relationshipLinks: {
|
||||
self: function (record) {
|
||||
@ -188,6 +190,8 @@ module.exports = {
|
||||
// Array
|
||||
toSerialize[relation.alias] = {
|
||||
ref: PK,
|
||||
included: strapi.config.jsonapi.included || false,
|
||||
ignoreRelationshipData: strapi.config.jsonapi.ignoreRelationshipData || false,
|
||||
typeForAttribute: relation.collection,
|
||||
attributes: _.keys(_.omit(strapi.models[type].attributes, _.isFunction)),
|
||||
relationshipLinks: {
|
||||
|
||||
@ -41,7 +41,7 @@
|
||||
"herd": "~1.0.0",
|
||||
"include-all": "~0.1.6",
|
||||
"json-stringify-safe": "~5.0.1",
|
||||
"jsonapi-serializer": "^2.0.4",
|
||||
"jsonapi-serializer": "seyz/jsonapi-serializer",
|
||||
"koa": "~1.1.2",
|
||||
"koa-bodyparser": "~2.0.1",
|
||||
"koa-compose": "~2.3.0",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user