From 666ca1935cc611cd52b7a08ce69315454d2d4a71 Mon Sep 17 00:00:00 2001 From: olav Date: Tue, 2 Aug 2022 13:06:10 +0200 Subject: [PATCH] fix: add missing client variant schema fields (#1880) * refactor: format file * fix: use correct variants schema reference * fix: add missing client variant schema fields --- .../spec/client-features-schema.test.ts | 679 +++++++++--------- .../openapi/spec/client-features-schema.ts | 4 +- src/lib/openapi/spec/client-variant-schema.ts | 6 + .../__snapshots__/openapi.e2e.test.ts.snap | 6 + 4 files changed, 363 insertions(+), 332 deletions(-) diff --git a/src/lib/openapi/spec/client-features-schema.test.ts b/src/lib/openapi/spec/client-features-schema.test.ts index ce8395e4f9..620b976ecf 100644 --- a/src/lib/openapi/spec/client-features-schema.test.ts +++ b/src/lib/openapi/spec/client-features-schema.test.ts @@ -16,6 +16,14 @@ test('clientFeaturesSchema required fields', () => { name: 'some-name', enabled: false, impressionData: false, + variants: [ + { + name: 'a', + weight: 1, + weightType: 'b', + stickiness: 'c', + }, + ], }, ], }; @@ -27,102 +35,101 @@ test('clientFeaturesSchema required fields', () => { test('clientFeaturesSchema java-sdk expected response', () => { const json = `{ - "version": 2, - "segments": [ + "version": 2, + "segments": [ { - "id": 1, - "name": "some-name", - "description": null, - "constraints": [ - { - "contextName": "some-name", - "operator": "IN", - "value": "name", - "inverted": false, - "caseInsensitive": true - } - ] - } - ], - "features": [ + "id": 1, + "name": "some-name", + "description": null, + "constraints": [ { - "name": "Test.old", - "description": "No variants here!", - "enabled": true, - "strategies": [ - { - "name": "default" - } - ], - "variants": null, - "createdAt": "2019-01-24T10:38:10.370Z" - }, - { - "name": "Test.variants", - "description": null, - "enabled": true, - "strategies": [ - { - "name": "default", - "segments": [ - 1 - ] - } - ], - "variants": [ - { - "name": "variant1", - "weight": 50 - }, - { - "name": "variant2", - "weight": 50 - } - ], - "createdAt": "2019-01-24T10:41:45.236Z" - }, - { - "name": "featureX", - "enabled": true, - "strategies": [ - { - "name": "default" - } - ] - }, - { - "name": "featureY", - "enabled": false, - "strategies": [ - { - "name": "baz", - "parameters": { - "foo": "bar" - } - } - ] - - }, - { - "name": "featureZ", - "enabled": true, - "strategies": [ - { - "name": "default" - }, - { - "name": "hola", - "parameters": { - "name": "val" - }, - "segments": [1] - } - ] - + "contextName": "some-name", + "operator": "IN", + "value": "name", + "inverted": false, + "caseInsensitive": true } - ] -} -`; + ] + } + ], + "features": [ + { + "name": "Test.old", + "description": "No variants here!", + "enabled": true, + "strategies": [ + { + "name": "default" + } + ], + "variants": null, + "createdAt": "2019-01-24T10:38:10.370Z" + }, + { + "name": "Test.variants", + "description": null, + "enabled": true, + "strategies": [ + { + "name": "default", + "segments": [ + 1 + ] + } + ], + "variants": [ + { + "name": "variant1", + "weight": 50 + }, + { + "name": "variant2", + "weight": 50 + } + ], + "createdAt": "2019-01-24T10:41:45.236Z" + }, + { + "name": "featureX", + "enabled": true, + "strategies": [ + { + "name": "default" + } + ] + }, + { + "name": "featureY", + "enabled": false, + "strategies": [ + { + "name": "baz", + "parameters": { + "foo": "bar" + } + } + ] + }, + { + "name": "featureZ", + "enabled": true, + "strategies": [ + { + "name": "default" + }, + { + "name": "hola", + "parameters": { + "name": "val" + }, + "segments": [ + 1 + ] + } + ] + } + ] + }`; expect( validateSchema( @@ -134,102 +141,101 @@ test('clientFeaturesSchema java-sdk expected response', () => { test('clientFeaturesSchema unleash-proxy expected response', () => { const json = `{ - "version": 2, - "segments": [ + "version": 2, + "segments": [ { - "id": 1, - "name": "some-name", - "description": null, - "constraints": [ - { - "contextName": "some-name", - "operator": "IN", - "value": "name", - "inverted": false, - "caseInsensitive": true - } - ] - } - ], - "features": [ + "id": 1, + "name": "some-name", + "description": null, + "constraints": [ { - "name": "Test.old", - "description": "No variants here!", - "enabled": true, - "strategies": [ - { - "name": "default" - } - ], - "variants": null, - "createdAt": "2019-01-24T10:38:10.370Z" - }, - { - "name": "Test.variants", - "description": null, - "enabled": true, - "strategies": [ - { - "name": "default", - "segments": [ - 1 - ] - } - ], - "variants": [ - { - "name": "variant1", - "weight": 50 - }, - { - "name": "variant2", - "weight": 50 - } - ], - "createdAt": "2019-01-24T10:41:45.236Z" - }, - { - "name": "featureX", - "enabled": true, - "strategies": [ - { - "name": "default" - } - ] - }, - { - "name": "featureY", - "enabled": false, - "strategies": [ - { - "name": "baz", - "parameters": { - "foo": "bar" - } - } - ] - - }, - { - "name": "featureZ", - "enabled": true, - "strategies": [ - { - "name": "default" - }, - { - "name": "hola", - "parameters": { - "name": "val" - }, - "segments": [1] - } - ] - + "contextName": "some-name", + "operator": "IN", + "value": "name", + "inverted": false, + "caseInsensitive": true } - ] -} -`; + ] + } + ], + "features": [ + { + "name": "Test.old", + "description": "No variants here!", + "enabled": true, + "strategies": [ + { + "name": "default" + } + ], + "variants": null, + "createdAt": "2019-01-24T10:38:10.370Z" + }, + { + "name": "Test.variants", + "description": null, + "enabled": true, + "strategies": [ + { + "name": "default", + "segments": [ + 1 + ] + } + ], + "variants": [ + { + "name": "variant1", + "weight": 50 + }, + { + "name": "variant2", + "weight": 50 + } + ], + "createdAt": "2019-01-24T10:41:45.236Z" + }, + { + "name": "featureX", + "enabled": true, + "strategies": [ + { + "name": "default" + } + ] + }, + { + "name": "featureY", + "enabled": false, + "strategies": [ + { + "name": "baz", + "parameters": { + "foo": "bar" + } + } + ] + }, + { + "name": "featureZ", + "enabled": true, + "strategies": [ + { + "name": "default" + }, + { + "name": "hola", + "parameters": { + "name": "val" + }, + "segments": [ + 1 + ] + } + ] + } + ] + }`; expect( validateSchema( @@ -241,150 +247,163 @@ test('clientFeaturesSchema unleash-proxy expected response', () => { test('clientFeaturesSchema client specification test 15', () => { const json = `{ - "version": 2, - "features": [ - { - "name": "F9.globalSegmentOn", - "description": "With global segment referencing constraint in on state", - "enabled": true, - "strategies": [ - { - "name": "default", - "parameters": {}, - "segments": [1] - } - ] - }, - { - "name": "F9.globalSegmentOff", - "description": "With global segment referencing constraint in off state", - "enabled": true, - "strategies": [ - { - "name": "default", - "parameters": {}, - "segments": [2] - } - ] - }, - { - "name": "F9.globalSegmentAndConstraint", - "description": "With global segment and constraint both on", - "enabled": true, - "strategies": [ - { - "name": "default", - "parameters": {}, - "constraints": [ - { - "contextName": "version", - "operator": "SEMVER_EQ", - "value": "1.2.2" - } - ], - "segments": [1] - } - ] - }, - { - "name": "F9.withExtraParams", - "description": "With global segment that doesn't exist", - "enabled": true, - "project": "some-project", - "strategies": [ - { - "name": "default", - "parameters": {}, - "constraints": [ - { - "contextName": "version", - "operator": "SEMVER_EQ", - "value": "1.2.2" - } - ], - "segments": [3] - } - ] - }, - { - "name": "F9.withSeveralConstraintsAndSegments", - "description": "With several segments and constraints", - "enabled": true, - "strategies": [ - { - "name": "default", - "parameters": {}, - "constraints": [ - { - "contextName": "customNumber", - "operator": "NUM_LT", - "value": "10" - }, - { - "contextName": "version", - "operator": "SEMVER_LT", - "value": "3.2.2" - } - ], - "segments": [1, 4, 5] - } - ] - } - ], - "segments": [ - { - "id": 1, - "constraints": [ - { - "contextName": "version", - "operator": "SEMVER_EQ", - "value": "1.2.2" - } - ] - }, - { - "id": 2, - "constraints": [ - { - "contextName": "version", - "operator": "SEMVER_EQ", - "value": "3.1.4" - } - ] - }, - { - "id": 3, - "constraints": [ - { - "contextName": "version", - "operator": "SEMVER_EQ", - "value": "3.1.4" - } - ] - }, - { - "id": 4, - "constraints": [ - { - "contextName": "customName", - "operator": "STR_CONTAINS", - "values": ["Pi"] - } - ] - }, - { - "id": 5, - "constraints": [ - { - "contextName": "slicesLeft", - "operator": "NUM_LTE", - "value": "4" - } - ] - } - ] - } -`; + "version": 2, + "features": [ + { + "name": "F9.globalSegmentOn", + "description": "With global segment referencing constraint in on state", + "enabled": true, + "strategies": [ + { + "name": "default", + "parameters": {}, + "segments": [ + 1 + ] + } + ] + }, + { + "name": "F9.globalSegmentOff", + "description": "With global segment referencing constraint in off state", + "enabled": true, + "strategies": [ + { + "name": "default", + "parameters": {}, + "segments": [ + 2 + ] + } + ] + }, + { + "name": "F9.globalSegmentAndConstraint", + "description": "With global segment and constraint both on", + "enabled": true, + "strategies": [ + { + "name": "default", + "parameters": {}, + "constraints": [ + { + "contextName": "version", + "operator": "SEMVER_EQ", + "value": "1.2.2" + } + ], + "segments": [ + 1 + ] + } + ] + }, + { + "name": "F9.withExtraParams", + "description": "With global segment that doesn't exist", + "enabled": true, + "project": "some-project", + "strategies": [ + { + "name": "default", + "parameters": {}, + "constraints": [ + { + "contextName": "version", + "operator": "SEMVER_EQ", + "value": "1.2.2" + } + ], + "segments": [ + 3 + ] + } + ] + }, + { + "name": "F9.withSeveralConstraintsAndSegments", + "description": "With several segments and constraints", + "enabled": true, + "strategies": [ + { + "name": "default", + "parameters": {}, + "constraints": [ + { + "contextName": "customNumber", + "operator": "NUM_LT", + "value": "10" + }, + { + "contextName": "version", + "operator": "SEMVER_LT", + "value": "3.2.2" + } + ], + "segments": [ + 1, + 4, + 5 + ] + } + ] + } + ], + "segments": [ + { + "id": 1, + "constraints": [ + { + "contextName": "version", + "operator": "SEMVER_EQ", + "value": "1.2.2" + } + ] + }, + { + "id": 2, + "constraints": [ + { + "contextName": "version", + "operator": "SEMVER_EQ", + "value": "3.1.4" + } + ] + }, + { + "id": 3, + "constraints": [ + { + "contextName": "version", + "operator": "SEMVER_EQ", + "value": "3.1.4" + } + ] + }, + { + "id": 4, + "constraints": [ + { + "contextName": "customName", + "operator": "STR_CONTAINS", + "values": [ + "Pi" + ] + } + ] + }, + { + "id": 5, + "constraints": [ + { + "contextName": "slicesLeft", + "operator": "NUM_LTE", + "value": "4" + } + ] + } + ] + }`; expect( validateSchema( diff --git a/src/lib/openapi/spec/client-features-schema.ts b/src/lib/openapi/spec/client-features-schema.ts index 19504c2b80..e1d62617d2 100644 --- a/src/lib/openapi/spec/client-features-schema.ts +++ b/src/lib/openapi/spec/client-features-schema.ts @@ -6,8 +6,8 @@ import { environmentSchema } from './environment-schema'; import { overrideSchema } from './override-schema'; import { parametersSchema } from './parameters-schema'; import { featureStrategySchema } from './feature-strategy-schema'; -import { variantSchema } from './variant-schema'; import { clientFeatureSchema } from './client-feature-schema'; +import { clientVariantSchema } from './client-variant-schema'; export const clientFeaturesSchema = { $id: '#/components/schemas/clientFeaturesSchema', @@ -43,7 +43,7 @@ export const clientFeaturesSchema = { overrideSchema, parametersSchema, featureStrategySchema, - variantSchema, + clientVariantSchema, }, }, } as const; diff --git a/src/lib/openapi/spec/client-variant-schema.ts b/src/lib/openapi/spec/client-variant-schema.ts index 4e3f32f5a7..432575e04c 100644 --- a/src/lib/openapi/spec/client-variant-schema.ts +++ b/src/lib/openapi/spec/client-variant-schema.ts @@ -12,6 +12,12 @@ export const clientVariantSchema = { weight: { type: 'number', }, + weightType: { + type: 'string', + }, + stickiness: { + type: 'string', + }, payload: { type: 'object', required: ['type', 'value'], 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 a25504da7b..6b128bce34 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 @@ -660,9 +660,15 @@ Object { ], "type": "object", }, + "stickiness": Object { + "type": "string", + }, "weight": Object { "type": "number", }, + "weightType": Object { + "type": "string", + }, }, "required": Array [ "name",