From b05b075ac894c2c604abe4e4906e9d6f5ecaa458 Mon Sep 17 00:00:00 2001 From: Mateusz Kwasniewski Date: Thu, 9 Mar 2023 14:45:03 +0100 Subject: [PATCH] feat: filter out all data fields other than explicit openapi fields (#3284) Co-authored-by: Tymoteusz Czech <2625371+Tymek@users.noreply.github.com> --- src/lib/openapi/spec/client-feature-schema.ts | 2 ++ src/lib/routes/client-api/feature.ts | 2 +- src/lib/services/feature-toggle-service.ts | 32 ++++++++++++++++++- .../__snapshots__/openapi.e2e.test.ts.snap | 6 ++-- 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/lib/openapi/spec/client-feature-schema.ts b/src/lib/openapi/spec/client-feature-schema.ts index 966d8ff2f8..532c42e601 100644 --- a/src/lib/openapi/spec/client-feature-schema.ts +++ b/src/lib/openapi/spec/client-feature-schema.ts @@ -49,6 +49,7 @@ export const clientFeatureSchema = { items: { $ref: '#/components/schemas/featureStrategySchema', }, + deprecated: true, }, variants: { type: 'array', @@ -56,6 +57,7 @@ export const clientFeatureSchema = { $ref: '#/components/schemas/variantSchema', }, nullable: true, + deprecated: true, }, }, components: { diff --git a/src/lib/routes/client-api/feature.ts b/src/lib/routes/client-api/feature.ts index b42303babd..0de26335e2 100644 --- a/src/lib/routes/client-api/feature.ts +++ b/src/lib/routes/client-api/feature.ts @@ -81,7 +81,7 @@ export default class FeatureController extends Controller { operationId: 'getClientFeature', tags: ['Client'], responses: { - 200: createResponseSchema('clientFeaturesSchema'), + 200: createResponseSchema('clientFeatureSchema'), }, }), ], diff --git a/src/lib/services/feature-toggle-service.ts b/src/lib/services/feature-toggle-service.ts index 19ab473746..b99346d2ea 100644 --- a/src/lib/services/feature-toggle-service.ts +++ b/src/lib/services/feature-toggle-service.ts @@ -688,7 +688,37 @@ class FeatureToggleService { query?: IFeatureToggleQuery, includeIds?: boolean, ): Promise { - return this.featureToggleClientStore.getClient(query, includeIds); + const result = await this.featureToggleClientStore.getClient( + query, + includeIds, + ); + return result.map( + ({ + name, + type, + enabled, + project, + stale, + strategies, + variants, + description, + createdAt, + lastSeenAt, + impressionData, + }) => ({ + name, + type, + enabled, + project, + stale, + strategies, + variants, + description, + createdAt, + lastSeenAt, + impressionData, + }), + ); } /** diff --git a/src/test/e2e/api/openapi/__snapshots__/openapi.e2e.test.ts.snap b/src/test/e2e/api/openapi/__snapshots__/openapi.e2e.test.ts.snap index e6bb1aba67..8476db710c 100644 --- a/src/test/e2e/api/openapi/__snapshots__/openapi.e2e.test.ts.snap +++ b/src/test/e2e/api/openapi/__snapshots__/openapi.e2e.test.ts.snap @@ -489,6 +489,7 @@ exports[`should serve the OpenAPI spec 1`] = ` "type": "boolean", }, "strategies": { + "deprecated": true, "items": { "$ref": "#/components/schemas/featureStrategySchema", }, @@ -498,6 +499,7 @@ exports[`should serve the OpenAPI spec 1`] = ` "type": "string", }, "variants": { + "deprecated": true, "items": { "$ref": "#/components/schemas/variantSchema", }, @@ -8567,11 +8569,11 @@ If the provided project does not exist, the list of events will be empty.", "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/clientFeaturesSchema", + "$ref": "#/components/schemas/clientFeatureSchema", }, }, }, - "description": "clientFeaturesSchema", + "description": "clientFeatureSchema", }, }, "tags": [