mirror of
https://github.com/Unleash/unleash.git
synced 2025-09-05 17:53:12 +02:00
Feat: update schemas to use 'variants' in place of 'variant'
This commit is contained in:
parent
789b70dcfe
commit
f4ed7d0893
@ -1,4 +1,5 @@
|
|||||||
import fc, { Arbitrary } from 'fast-check';
|
import fc, { Arbitrary } from 'fast-check';
|
||||||
|
import { WeightType } from '../../../lib/types/model';
|
||||||
import { urlFriendlyString } from '../../../test/arbitraries.test';
|
import { urlFriendlyString } from '../../../test/arbitraries.test';
|
||||||
import { validateSchema } from '../validate';
|
import { validateSchema } from '../validate';
|
||||||
import {
|
import {
|
||||||
@ -12,7 +13,8 @@ export const generate = (): Arbitrary<PlaygroundFeatureSchema> =>
|
|||||||
isEnabled: fc.constant(isEnabled),
|
isEnabled: fc.constant(isEnabled),
|
||||||
projectId: urlFriendlyString(),
|
projectId: urlFriendlyString(),
|
||||||
name: urlFriendlyString(),
|
name: urlFriendlyString(),
|
||||||
variant: fc.record(
|
variants: fc.uniqueArray(
|
||||||
|
fc.record(
|
||||||
{
|
{
|
||||||
name: urlFriendlyString(),
|
name: urlFriendlyString(),
|
||||||
enabled: fc.constant(isEnabled),
|
enabled: fc.constant(isEnabled),
|
||||||
@ -32,8 +34,21 @@ export const generate = (): Arbitrary<PlaygroundFeatureSchema> =>
|
|||||||
value: fc.string(),
|
value: fc.string(),
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
|
weight: fc.nat({ max: 1000 }),
|
||||||
|
weightType: fc.constant(WeightType.VARIABLE),
|
||||||
|
stickiness: fc.constant('default'),
|
||||||
},
|
},
|
||||||
{ requiredKeys: ['name', 'enabled'] },
|
{
|
||||||
|
requiredKeys: [
|
||||||
|
'name',
|
||||||
|
'enabled',
|
||||||
|
'weight',
|
||||||
|
'stickiness',
|
||||||
|
'weightType',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
),
|
||||||
|
{ selector: (variant) => variant.name },
|
||||||
),
|
),
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
import { FromSchema } from 'json-schema-to-ts';
|
import { FromSchema } from 'json-schema-to-ts';
|
||||||
|
import { overrideSchema } from './override-schema';
|
||||||
|
import { variantSchema } from './variant-schema';
|
||||||
|
|
||||||
export const playgroundFeatureSchema = {
|
export const playgroundFeatureSchema = {
|
||||||
$id: '#/components/schemas/playgroundFeatureSchema',
|
$id: '#/components/schemas/playgroundFeatureSchema',
|
||||||
@ -6,36 +8,28 @@ export const playgroundFeatureSchema = {
|
|||||||
'A simplified feature toggle model intended for the Unleash playground.',
|
'A simplified feature toggle model intended for the Unleash playground.',
|
||||||
type: 'object',
|
type: 'object',
|
||||||
additionalProperties: false,
|
additionalProperties: false,
|
||||||
required: ['name', 'projectId', 'isEnabled', 'variant'],
|
required: ['name', 'projectId', 'isEnabled', 'variants'],
|
||||||
properties: {
|
properties: {
|
||||||
name: { type: 'string', examples: ['my-feature'] },
|
name: { type: 'string', examples: ['my-feature'] },
|
||||||
projectId: { type: 'string', examples: ['my-project'] },
|
projectId: { type: 'string', examples: ['my-project'] },
|
||||||
isEnabled: { type: 'boolean', examples: [true] },
|
isEnabled: { type: 'boolean', examples: [true] },
|
||||||
variant: {
|
variants: {
|
||||||
|
type: 'array',
|
||||||
|
items: {
|
||||||
|
allOf: [
|
||||||
|
{ $ref: variantSchema.$id },
|
||||||
|
{
|
||||||
type: 'object',
|
type: 'object',
|
||||||
additionalProperties: false,
|
required: ['enabled'],
|
||||||
required: ['name', 'enabled'],
|
|
||||||
properties: {
|
properties: {
|
||||||
name: { type: 'string' },
|
enabled: { type: 'boolean', examples: [true] },
|
||||||
enabled: { type: 'boolean' },
|
|
||||||
payload: {
|
|
||||||
type: 'object',
|
|
||||||
additionalProperties: false,
|
|
||||||
required: ['type', 'value'],
|
|
||||||
properties: {
|
|
||||||
type: {
|
|
||||||
type: 'string',
|
|
||||||
enum: ['json', 'csv', 'string'],
|
|
||||||
},
|
},
|
||||||
value: { type: 'string' },
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
nullable: true,
|
components: { schemas: { variantSchema, overrideSchema } },
|
||||||
examples: ['green'],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
components: { schemas: {} },
|
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
export type PlaygroundFeatureSchema = FromSchema<
|
export type PlaygroundFeatureSchema = FromSchema<
|
||||||
|
@ -5,12 +5,14 @@ import {
|
|||||||
} from '../../../lib/openapi/spec/playground-response-schema';
|
} from '../../../lib/openapi/spec/playground-response-schema';
|
||||||
import { validateSchema } from '../validate';
|
import { validateSchema } from '../validate';
|
||||||
import { generate as generateInput } from './playground-request-schema.test';
|
import { generate as generateInput } from './playground-request-schema.test';
|
||||||
import { generate as generateToggles } from './playground-feature-schema.test';
|
import { generate as generateFeature } from './playground-feature-schema.test';
|
||||||
|
|
||||||
const generate = (): Arbitrary<PlaygroundResponseSchema> =>
|
const generate = (): Arbitrary<PlaygroundResponseSchema> =>
|
||||||
fc.record({
|
fc.record({
|
||||||
input: generateInput(),
|
input: generateInput(),
|
||||||
features: fc.array(generateToggles()),
|
features: fc.uniqueArray(generateFeature(), {
|
||||||
|
selector: (feature) => feature.name,
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
test('playgroundResponseSchema', () =>
|
test('playgroundResponseSchema', () =>
|
||||||
|
@ -3,6 +3,8 @@ import { sdkContextSchema } from './sdk-context-schema';
|
|||||||
import { playgroundRequestSchema } from './playground-request-schema';
|
import { playgroundRequestSchema } from './playground-request-schema';
|
||||||
import { playgroundFeatureSchema } from './playground-feature-schema';
|
import { playgroundFeatureSchema } from './playground-feature-schema';
|
||||||
import { featureVariantsSchema } from './feature-variants-schema';
|
import { featureVariantsSchema } from './feature-variants-schema';
|
||||||
|
import { variantSchema } from './variant-schema';
|
||||||
|
import { overrideSchema } from './override-schema';
|
||||||
|
|
||||||
export const playgroundResponseSchema = {
|
export const playgroundResponseSchema = {
|
||||||
$id: '#/components/schemas/playgroundResponseSchema',
|
$id: '#/components/schemas/playgroundResponseSchema',
|
||||||
@ -17,21 +19,7 @@ export const playgroundResponseSchema = {
|
|||||||
features: {
|
features: {
|
||||||
type: 'array',
|
type: 'array',
|
||||||
items: {
|
items: {
|
||||||
allOf: [
|
$ref: playgroundFeatureSchema.$id,
|
||||||
{ $ref: playgroundFeatureSchema.$id },
|
|
||||||
{
|
|
||||||
type: 'object',
|
|
||||||
required: ['variants'],
|
|
||||||
properties: {
|
|
||||||
variants: {
|
|
||||||
type: 'array',
|
|
||||||
items: {
|
|
||||||
$ref: featureVariantsSchema.$id,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -41,6 +29,8 @@ export const playgroundResponseSchema = {
|
|||||||
playgroundFeatureSchema,
|
playgroundFeatureSchema,
|
||||||
playgroundRequestSchema,
|
playgroundRequestSchema,
|
||||||
sdkContextSchema,
|
sdkContextSchema,
|
||||||
|
variantSchema,
|
||||||
|
overrideSchema,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
} as const;
|
} as const;
|
||||||
|
@ -4,7 +4,6 @@ import { overrideSchema } from './override-schema';
|
|||||||
export const variantSchema = {
|
export const variantSchema = {
|
||||||
$id: '#/components/schemas/variantSchema',
|
$id: '#/components/schemas/variantSchema',
|
||||||
type: 'object',
|
type: 'object',
|
||||||
additionalProperties: false,
|
|
||||||
required: ['name', 'weight', 'weightType', 'stickiness'],
|
required: ['name', 'weight', 'weightType', 'stickiness'],
|
||||||
properties: {
|
properties: {
|
||||||
name: {
|
name: {
|
||||||
|
Loading…
Reference in New Issue
Block a user