From fb5a4876638f361bd3884620dad4483b08fda408 Mon Sep 17 00:00:00 2001 From: Thomas Heartman Date: Mon, 11 Dec 2023 12:01:47 +0100 Subject: [PATCH] feat: add schema for change request strategies (#5578) This change adds a property to the segmentStrategiesSchema to make sure that change request strategies are listed in the openapi spec It also renames the files that contains that schema and its tests from `admin-strategies-schema` to `segment-strategies-schema`. --- .../features/segment/segment-controller.ts | 4 +- src/lib/openapi/index.ts | 4 +- ...=> segment-strategies-schema.test.ts.snap} | 0 ...t.ts => segment-strategies-schema.test.ts} | 0 ...schema.ts => segment-strategies-schema.ts} | 46 +++++++++++++++++++ 5 files changed, 50 insertions(+), 4 deletions(-) rename src/lib/openapi/spec/__snapshots__/{admin-strategies-schema.test.ts.snap => segment-strategies-schema.test.ts.snap} (100%) rename src/lib/openapi/spec/{admin-strategies-schema.test.ts => segment-strategies-schema.test.ts} (100%) rename src/lib/openapi/spec/{admin-strategies-schema.ts => segment-strategies-schema.ts} (52%) diff --git a/src/lib/features/segment/segment-controller.ts b/src/lib/features/segment/segment-controller.ts index 7c96513395..4cca885d2b 100644 --- a/src/lib/features/segment/segment-controller.ts +++ b/src/lib/features/segment/segment-controller.ts @@ -22,7 +22,7 @@ import { getStandardResponses, } from '../../openapi/util/standard-responses'; import { ISegmentService } from '../../segments/segment-service-interface'; -import { SegmentStrategiesSchema } from '../../openapi/spec/admin-strategies-schema'; +import { SegmentStrategiesSchema } from '../../openapi/spec/segment-strategies-schema'; import { AccessService, OpenApiService } from '../../services'; import { CREATE_SEGMENT, @@ -156,7 +156,7 @@ export class SegmentsController extends Controller { description: 'Retrieve all strategies that reference the specified segment.', responses: { - 200: createResponseSchema('adminStrategiesSchema'), + 200: createResponseSchema('segmentStrategiesSchema'), }, }), ], diff --git a/src/lib/openapi/index.ts b/src/lib/openapi/index.ts index 029a3538e8..8dcc628d3b 100644 --- a/src/lib/openapi/index.ts +++ b/src/lib/openapi/index.ts @@ -187,7 +187,7 @@ import { createApplicationSchema } from './spec/create-application-schema'; import { contextFieldStrategiesSchema } from './spec/context-field-strategies-schema'; import { advancedPlaygroundEnvironmentFeatureSchema } from './spec/advanced-playground-environment-feature-schema'; import { createFeatureNamingPatternSchema } from './spec/create-feature-naming-pattern-schema'; -import { segmentStrategiesSchema } from './spec/admin-strategies-schema'; +import { segmentStrategiesSchema } from './spec/segment-strategies-schema'; import { featureDependenciesSchema } from './spec/feature-dependencies-schema'; // Schemas must have an $id property on the form "#/components/schemas/mySchema". @@ -223,7 +223,7 @@ export const schemas: UnleashSchemas = { adminCountSchema, adminFeaturesQuerySchema, adminSegmentSchema, - adminStrategiesSchema: segmentStrategiesSchema, + segmentStrategiesSchema, addonParameterSchema, addonSchema, addonCreateUpdateSchema, diff --git a/src/lib/openapi/spec/__snapshots__/admin-strategies-schema.test.ts.snap b/src/lib/openapi/spec/__snapshots__/segment-strategies-schema.test.ts.snap similarity index 100% rename from src/lib/openapi/spec/__snapshots__/admin-strategies-schema.test.ts.snap rename to src/lib/openapi/spec/__snapshots__/segment-strategies-schema.test.ts.snap diff --git a/src/lib/openapi/spec/admin-strategies-schema.test.ts b/src/lib/openapi/spec/segment-strategies-schema.test.ts similarity index 100% rename from src/lib/openapi/spec/admin-strategies-schema.test.ts rename to src/lib/openapi/spec/segment-strategies-schema.test.ts diff --git a/src/lib/openapi/spec/admin-strategies-schema.ts b/src/lib/openapi/spec/segment-strategies-schema.ts similarity index 52% rename from src/lib/openapi/spec/admin-strategies-schema.ts rename to src/lib/openapi/spec/segment-strategies-schema.ts index 53cc4b74b2..792238330a 100644 --- a/src/lib/openapi/spec/admin-strategies-schema.ts +++ b/src/lib/openapi/spec/segment-strategies-schema.ts @@ -5,6 +5,7 @@ export const segmentStrategiesSchema = { type: 'object', required: ['strategies'], description: 'A collection of strategies belonging to a specified segment.', + additionalProperties: false, properties: { strategies: { description: 'The list of strategies', @@ -50,6 +51,51 @@ export const segmentStrategiesSchema = { }, }, }, + changeRequestStrategies: { + description: + 'A list of strategies that use this segment in active change requests.', + type: 'array', + items: { + type: 'object', + required: [ + 'featureName', + 'projectId', + 'environment', + 'strategyName', + ], + properties: { + id: { + type: 'string', + description: + "The ID of the strategy. Not present on new strategies that haven't been added to the feature flag yet.", + example: 'e465c813-cffb-4232-b184-82b1d6fe9d3d', + }, + featureName: { + type: 'string', + description: + 'The name of the feature flag that this strategy belongs to.', + example: 'new-signup-flow', + }, + projectId: { + type: 'string', + description: + 'The ID of the project that the strategy belongs to.', + example: 'red-vista', + }, + environment: { + type: 'string', + description: + 'The ID of the environment that the strategy belongs to.', + example: 'development', + }, + strategyName: { + type: 'string', + description: "The name of the strategy's type.", + example: 'flexibleRollout', + }, + }, + }, + }, }, components: {}, } as const;