/
playground-strategy-schema.ts
133 lines (129 loc) · 4.5 KB
/
playground-strategy-schema.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import { FromSchema } from 'json-schema-to-ts';
import { parametersSchema } from './parameters-schema';
import { playgroundConstraintSchema } from './playground-constraint-schema';
import { playgroundSegmentSchema } from './playground-segment-schema';
export const playgroundStrategyEvaluation = {
evaluationComplete: 'complete',
evaluationIncomplete: 'incomplete',
unknownResult: 'unknown',
} as const;
export const strategyEvaluationResults = {
anyOf: [
{
type: 'object',
additionalProperties: false,
required: ['evaluationStatus', 'enabled'],
properties: {
evaluationStatus: {
type: 'string',
description:
"Signals that this strategy could not be evaluated. This is most likely because you're using a custom strategy that Unleash doesn't know about.",
enum: [playgroundStrategyEvaluation.evaluationIncomplete],
},
enabled: {
description:
"Whether this strategy resolves to `false` or if it might resolve to `true`. Because Unleash can't evaluate the strategy, it can't say for certain whether it will be `true`, but if you have failing constraints or segments, it _can_ determine that your strategy would be `false`.",
anyOf: [
{ type: 'boolean', enum: [false] },
{
type: 'string',
enum: [playgroundStrategyEvaluation.unknownResult],
},
],
},
},
},
{
type: 'object',
additionalProperties: false,
required: ['evaluationStatus', 'enabled'],
properties: {
evaluationStatus: {
description:
'Signals that this strategy was evaluated successfully.',
type: 'string',
enum: ['complete'],
},
enabled: {
type: 'boolean',
description:
'Whether this strategy evaluates to true or not.',
},
},
},
],
} as const;
export const playgroundStrategySchema = {
$id: '#/components/schemas/playgroundStrategySchema',
type: 'object',
additionalProperties: false,
required: [
'id',
'name',
'result',
'segments',
'constraints',
'parameters',
'disabled',
],
properties: {
name: {
description: "The strategy's name.",
type: 'string',
},
title: {
type: 'string',
example: 'Beta rollout',
description: "Description of the feature's purpose.",
},
id: {
description: "The strategy's id.",
type: 'string',
},
result: {
description: `The strategy's evaluation result. If the strategy is a custom strategy that Unleash can't evaluate, \`evaluationStatus\` will be \`${playgroundStrategyEvaluation.unknownResult}\`. Otherwise, it will be \`true\` or \`false\``,
...strategyEvaluationResults,
},
disabled: {
type: 'boolean',
description:
"The strategy's status. Disabled strategies are not evaluated",
example: false,
nullable: true,
},
segments: {
type: 'array',
description:
"The strategy's segments and their evaluation results.",
items: {
$ref: playgroundSegmentSchema.$id,
},
},
constraints: {
type: 'array',
description:
"The strategy's constraints and their evaluation results.",
items: {
$ref: playgroundConstraintSchema.$id,
},
},
parameters: {
description:
"The strategy's constraints and their evaluation results.",
example: {
myParam1: 'param value',
},
$ref: parametersSchema.$id,
},
},
components: {
schemas: {
playgroundConstraintSchema,
playgroundSegmentSchema,
parametersSchema,
},
},
} as const;
export type PlaygroundStrategySchema = FromSchema<
typeof playgroundStrategySchema
>;