From c5601a5c6359250d4b8e992b7e3848c84b974dd4 Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Wed, 16 Feb 2022 16:48:01 -0500 Subject: [PATCH] chore: support `filters` when it is a string by converting to an array --- addons/api/addon/serializers/host-set.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/addons/api/addon/serializers/host-set.js b/addons/api/addon/serializers/host-set.js index 613caf1ab..5749cd993 100644 --- a/addons/api/addon/serializers/host-set.js +++ b/addons/api/addon/serializers/host-set.js @@ -1,4 +1,5 @@ import ApplicationSerializer from './application'; +import { copy } from 'ember-copy'; const fieldByType = { aws: ['preferred_endpoints', 'filters'], @@ -69,4 +70,19 @@ export default class HostSetSerializer extends ApplicationSerializer { } return value; } + + /** + * Temporarily converts `filters` to an array if it is a string. This is a + * quirk of the API. + * + * TODO: remove once API consistently returns arrays. + */ + normalize(typeClass, hash, ...rest) { + const normalizedHash = copy(hash, true); + if (typeof normalizedHash?.filters === 'string') { + normalizedHash.filters = [normalizedHash.filters]; + } + const normalized = super.normalize(typeClass, normalizedHash, ...rest); + return normalized; + } }