diff --git a/core/server/api/v2/utils/serializers/output/utils/clean.js b/core/server/api/v2/utils/serializers/output/utils/clean.js index f4041f8d66..a10df51fc4 100644 --- a/core/server/api/v2/utils/serializers/output/utils/clean.js +++ b/core/server/api/v2/utils/serializers/output/utils/clean.js @@ -1,25 +1,28 @@ const _ = require('lodash'); const localUtils = require('../../../index'); -const tag = (attrs) => { +const tag = (attrs, frame) => { + if (localUtils.isContentAPI(frame)) { + delete attrs.created_at; + delete attrs.updated_at; + + // We are standardising on returning null from the Content API for any empty values + if (attrs.meta_title === '') { + attrs.meta_title = null; + } + if (attrs.meta_description === '') { + attrs.meta_description = null; + } + if (attrs.description === '') { + attrs.description = null; + } + } + // Already deleted in model.toJSON, but leaving here so that we can clean that up when we deprecate v0.1 delete attrs.parent_id; // Extra properties removed from v2 delete attrs.parent; - delete attrs.created_at; - delete attrs.updated_at; - - // We are standardising on returning null from the Content API for any empty values - if (attrs.meta_title === '') { - attrs.meta_title = null; - } - if (attrs.meta_description === '') { - attrs.meta_description = null; - } - if (attrs.description === '') { - attrs.description = null; - } return attrs; }; diff --git a/core/server/api/v2/utils/serializers/output/utils/mapper.js b/core/server/api/v2/utils/serializers/output/utils/mapper.js index 995c569528..065650d1d4 100644 --- a/core/server/api/v2/utils/serializers/output/utils/mapper.js +++ b/core/server/api/v2/utils/serializers/output/utils/mapper.js @@ -21,10 +21,7 @@ const mapTag = (model, frame) => { const jsonModel = model.toJSON ? model.toJSON(frame.options) : model; url.forTag(model.id, jsonModel); - - if (utils.isContentAPI(frame)) { - clean.tag(jsonModel); - } + clean.tag(jsonModel, frame); return jsonModel; }; diff --git a/core/test/acceptance/old/admin/utils.js b/core/test/acceptance/old/admin/utils.js index 455b5c9ab5..1a9128aeae 100644 --- a/core/test/acceptance/old/admin/utils.js +++ b/core/test/acceptance/old/admin/utils.js @@ -35,8 +35,8 @@ const expectedProperties = { , tag: _(schema.tags) .keys() - // Tag API swaps parent_id to parent - .without('parent_id').concat('parent') + // unused field + .without('parent_id') , setting: _(schema.settings) .keys() diff --git a/core/test/regression/api/v2/admin/utils.js b/core/test/regression/api/v2/admin/utils.js index cff21dd144..c8f3a8d828 100644 --- a/core/test/regression/api/v2/admin/utils.js +++ b/core/test/regression/api/v2/admin/utils.js @@ -32,8 +32,8 @@ const expectedProperties = { , tag: _(schema.tags) .keys() - // Tag API swaps parent_id to parent - .without('parent_id').concat('parent') + // unused field + .without('parent_id') , setting: _(schema.settings) .keys()