From a3f693b4726482fff1fc28f8e655de609fdbd931 Mon Sep 17 00:00:00 2001 From: Fabien O'Carroll Date: Wed, 8 Jul 2020 14:47:44 +0200 Subject: [PATCH] Updated tags output serialiasation for v2 API no-issue This ensures that the v2 API only outputs the tag properties we specify, and doesn't include any new fields, like the new metadata columns. --- .../utils/serializers/output/utils/clean.js | 42 +++++++++++++------ .../utils/serializers/output/utils/mapper.js | 4 +- 2 files changed, 32 insertions(+), 14 deletions(-) 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 d15b4cce67..f3f385665c 100644 --- a/core/server/api/v2/utils/serializers/output/utils/clean.js +++ b/core/server/api/v2/utils/serializers/output/utils/clean.js @@ -3,25 +3,43 @@ const localUtils = require('../../../index'); const tag = (attrs, frame) => { if (localUtils.isContentAPI(frame)) { - delete attrs.created_at; - delete attrs.updated_at; + const contentAttrs = _.pick(attrs, [ + 'description', + 'feature_image', + 'id', + 'meta_description', + 'meta_title', + 'name', + 'slug', + 'url', + 'visibility' + ]); // We are standardising on returning null from the Content API for any empty values - if (attrs.meta_title === '') { - attrs.meta_title = null; + if (contentAttrs.meta_title === '') { + contentAttrs.meta_title = null; } - if (attrs.meta_description === '') { - attrs.meta_description = null; + if (contentAttrs.meta_description === '') { + contentAttrs.meta_description = null; } - if (attrs.description === '') { - attrs.description = null; + if (contentAttrs.description === '') { + contentAttrs.description = null; } } - delete attrs.parent_id; - delete attrs.parent; - - return attrs; + return _.pick(attrs, [ + 'created_at', + 'description', + 'feature_image', + 'id', + 'meta_description', + 'meta_title', + 'name', + 'slug', + 'updated_at', + 'url', + 'visibility' + ]); }; const author = (attrs, frame) => { 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 ee1673cc14..9eb8b034e1 100644 --- a/core/server/api/v2/utils/serializers/output/utils/mapper.js +++ b/core/server/api/v2/utils/serializers/output/utils/mapper.js @@ -21,9 +21,9 @@ const mapTag = (model, frame) => { const jsonModel = model.toJSON ? model.toJSON(frame.options) : model; url.forTag(model.id, jsonModel, frame.options); - clean.tag(jsonModel, frame); + const cleanedAttrs = clean.tag(jsonModel, frame); - return jsonModel; + return cleanedAttrs; }; const mapPost = (model, frame) => {