|
1 | 1 | { |
2 | 2 | "$id": "https://flagd.dev/schema/v0/flags.json", |
3 | 3 | "$schema": "http://json-schema.org/draft-07/schema#", |
4 | | - "title": "flagd Flag Configuration", |
5 | | - "description": "Defines flags for use in flagd, including typed variants and rules.", |
6 | | - "type": "object", |
7 | | - "properties": { |
8 | | - "flags": { |
| 4 | + "$ref": "#/definitions/providerConfig", |
| 5 | + "definitions": { |
| 6 | + "flagsMap": { |
9 | 7 | "title": "Flags", |
10 | 8 | "description": "Top-level flags object. All flags are defined here.", |
11 | 9 | "type": "object", |
12 | 10 | "$comment": "flag objects are one of the 4 flag types defined in definitions", |
13 | 11 | "additionalProperties": false, |
14 | 12 | "patternProperties": { |
15 | 13 | "^.{1,}$": { |
16 | | - "oneOf": [ |
17 | | - { |
18 | | - "title": "Boolean flag", |
19 | | - "description": "A flag having boolean values.", |
20 | | - "$ref": "#/definitions/booleanFlag" |
21 | | - }, |
22 | | - { |
23 | | - "title": "String flag", |
24 | | - "description": "A flag having string values.", |
25 | | - "$ref": "#/definitions/stringFlag" |
| 14 | + "$ref": "#/definitions/anyFlag" |
| 15 | + } |
| 16 | + } |
| 17 | + }, |
| 18 | + "flagsArray": { |
| 19 | + "title": "Flags", |
| 20 | + "description": "Top-level flags array. All flags are defined here.", |
| 21 | + "type": "array", |
| 22 | + "items": { |
| 23 | + "allOf": [ |
| 24 | + { |
| 25 | + "$ref": "#/definitions/anyFlag" |
| 26 | + }, |
| 27 | + { |
| 28 | + "type": "object", |
| 29 | + "properties": { |
| 30 | + "key": { |
| 31 | + "description": "Key of the flag: uniquely identifies this flag within it's flagSet", |
| 32 | + "type": "string", |
| 33 | + "minLength": 1 |
| 34 | + } |
26 | 35 | }, |
27 | | - { |
28 | | - "title": "Numeric flag", |
29 | | - "description": "A flag having numeric values.", |
30 | | - "$ref": "#/definitions/numberFlag" |
| 36 | + "required": [ |
| 37 | + "key" |
| 38 | + ] |
| 39 | + } |
| 40 | + ] |
| 41 | + } |
| 42 | + }, |
| 43 | + "baseConfig": { |
| 44 | + "title": "flagd Flag Configuration", |
| 45 | + "description": "Defines flags for use in flagd providers, including typed variants and rules.", |
| 46 | + "type": "object", |
| 47 | + "properties": { |
| 48 | + "$evaluators": { |
| 49 | + "title": "Evaluators", |
| 50 | + "description": "Reusable targeting rules that can be referenced with \"$ref\": \"myRule\" in multiple flags.", |
| 51 | + "type": "object", |
| 52 | + "additionalProperties": false, |
| 53 | + "patternProperties": { |
| 54 | + "^.{1,}$": { |
| 55 | + "$comment": "this relative ref means that targeting.json MUST be in the same dir, or available on the same HTTP path", |
| 56 | + "$ref": "./targeting.json" |
| 57 | + } |
| 58 | + } |
| 59 | + }, |
| 60 | + "metadata": { |
| 61 | + "title": "Flag Set Metadata", |
| 62 | + "description": "Metadata about the flag set, with keys of type string, and values of type boolean, string, or number.", |
| 63 | + "properties": { |
| 64 | + "flagSetId": { |
| 65 | + "description": "The unique identifier for the flag set.", |
| 66 | + "type": "string" |
31 | 67 | }, |
32 | | - { |
33 | | - "title": "Object flag", |
34 | | - "description": "A flag having arbitrary object values.", |
35 | | - "$ref": "#/definitions/objectFlag" |
| 68 | + "version": { |
| 69 | + "description": "The version of the flag set.", |
| 70 | + "type": "string" |
36 | 71 | } |
37 | | - ] |
| 72 | + }, |
| 73 | + "$ref": "#/definitions/metadata" |
38 | 74 | } |
39 | 75 | } |
40 | 76 | }, |
41 | | - "$evaluators": { |
42 | | - "title": "Evaluators", |
43 | | - "description": "Reusable targeting rules that can be referenced with \"$ref\": \"myRule\" in multiple flags.", |
| 77 | + "providerConfig": { |
| 78 | + "description": "Defines flags for use in providers (not flagd), including typed variants and rules.", |
44 | 79 | "type": "object", |
45 | | - "additionalProperties": false, |
46 | | - "patternProperties": { |
47 | | - "^.{1,}$": { |
48 | | - "$comment": "this relative ref means that targeting.json MUST be in the same dir, or available on the same HTTP path", |
49 | | - "$ref": "./targeting.json" |
| 80 | + "allOf": [ |
| 81 | + { |
| 82 | + "$ref": "#/definitions/baseConfig" |
50 | 83 | } |
51 | | - } |
52 | | - }, |
53 | | - "metadata": { |
54 | | - "title": "Flag Set Metadata", |
55 | | - "description": "Metadata about the flag set, with keys of type string, and values of type boolean, string, or number.", |
| 84 | + ], |
56 | 85 | "properties": { |
57 | | - "flagSetId": { |
58 | | - "description": "The unique identifier for the flag set.", |
59 | | - "type": "string" |
60 | | - }, |
61 | | - "version": { |
62 | | - "description": "The version of the flag set.", |
63 | | - "type": "string" |
| 86 | + "flags": { |
| 87 | + "$ref": "#/definitions/flagsMap" |
64 | 88 | } |
65 | 89 | }, |
66 | | - "$ref": "#/definitions/metadata" |
67 | | - } |
68 | | - }, |
69 | | - "definitions": { |
70 | | - "flag": { |
| 90 | + "required": [ |
| 91 | + "flags" |
| 92 | + ] |
| 93 | + }, |
| 94 | + "flagdConfig": { |
| 95 | + "description": "Defines flags for use in the flagd daemon (a superset of what's available in providers), including typed variants and rules. Flags can be defined as an array or an object.", |
| 96 | + "type": "object", |
| 97 | + "allOf": [ |
| 98 | + { |
| 99 | + "$ref": "#/definitions/baseConfig" |
| 100 | + }, |
| 101 | + { |
| 102 | + "properties": { |
| 103 | + "flags": { |
| 104 | + "oneOf": [ |
| 105 | + { |
| 106 | + "$ref": "#/definitions/flagsMap" |
| 107 | + }, |
| 108 | + { |
| 109 | + "$ref": "#/definitions/flagsArray" |
| 110 | + } |
| 111 | + ] |
| 112 | + } |
| 113 | + } |
| 114 | + } |
| 115 | + ], |
| 116 | + "required": [ |
| 117 | + "flags" |
| 118 | + ] |
| 119 | + }, |
| 120 | + "baseFlag": { |
71 | 121 | "$comment": "base flag object; no title/description here, allows for better UX, keep it in the overrides", |
72 | 122 | "type": "object", |
73 | 123 | "properties": { |
|
82 | 132 | }, |
83 | 133 | "defaultVariant": { |
84 | 134 | "title": "Default Variant", |
85 | | - "description": "The variant to serve if no dynamic targeting applies (including if the targeting returns null).", |
86 | | - "type": "string" |
| 135 | + "description": "The variant to serve if no dynamic targeting applies (including if the targeting returns null). Set to null to use code-defined default.", |
| 136 | + "type": [ |
| 137 | + "string", |
| 138 | + "null" |
| 139 | + ] |
87 | 140 | }, |
88 | 141 | "targeting": { |
89 | 142 | "$ref": "./targeting.json" |
|
92 | 145 | "title": "Flag Metadata", |
93 | 146 | "description": "Metadata about an individual feature flag, with keys of type string, and values of type boolean, string, or number.", |
94 | 147 | "$ref": "#/definitions/metadata" |
| 148 | + }, |
| 149 | + "variants": { |
| 150 | + "type": "object", |
| 151 | + "minProperties": 1, |
| 152 | + "additionalProperties": false, |
| 153 | + "patternProperties": { |
| 154 | + "^.{1,}$": {} |
| 155 | + } |
95 | 156 | } |
96 | 157 | }, |
97 | 158 | "required": [ |
98 | 159 | "state", |
99 | | - "defaultVariant" |
| 160 | + "variants" |
100 | 161 | ] |
101 | 162 | }, |
102 | 163 | "booleanVariants": { |
|
109 | 170 | "^.{1,}$": { |
110 | 171 | "type": "boolean" |
111 | 172 | } |
112 | | - }, |
113 | | - "default": { |
114 | | - "true": true, |
115 | | - "false": false |
116 | 173 | } |
117 | 174 | } |
118 | 175 | } |
|
159 | 216 | } |
160 | 217 | } |
161 | 218 | }, |
| 219 | + "anyFlag": { |
| 220 | + "anyOf": [ |
| 221 | + { |
| 222 | + "$ref": "#/definitions/booleanFlag" |
| 223 | + }, |
| 224 | + { |
| 225 | + "$ref": "#/definitions/numberFlag" |
| 226 | + }, |
| 227 | + { |
| 228 | + "$ref": "#/definitions/stringFlag" |
| 229 | + }, |
| 230 | + { |
| 231 | + "$ref": "#/definitions/objectFlag" |
| 232 | + } |
| 233 | + ] |
| 234 | + }, |
162 | 235 | "booleanFlag": { |
163 | 236 | "$comment": "merge the variants with the base flag to build our typed flags", |
| 237 | + "title": "Boolean flag", |
| 238 | + "description": "A flag having boolean values.", |
164 | 239 | "allOf": [ |
165 | 240 | { |
166 | | - "$ref": "#/definitions/flag" |
| 241 | + "$ref": "#/definitions/baseFlag" |
167 | 242 | }, |
168 | 243 | { |
169 | 244 | "$ref": "#/definitions/booleanVariants" |
170 | 245 | } |
171 | 246 | ] |
172 | 247 | }, |
173 | 248 | "stringFlag": { |
| 249 | + "title": "String flag", |
| 250 | + "description": "A flag having string values.", |
174 | 251 | "allOf": [ |
175 | 252 | { |
176 | | - "$ref": "#/definitions/flag" |
| 253 | + "$ref": "#/definitions/baseFlag" |
177 | 254 | }, |
178 | 255 | { |
179 | 256 | "$ref": "#/definitions/stringVariants" |
180 | 257 | } |
181 | 258 | ] |
182 | 259 | }, |
183 | 260 | "numberFlag": { |
| 261 | + "title": "Numeric flag", |
| 262 | + "description": "A flag having numeric values.", |
184 | 263 | "allOf": [ |
185 | 264 | { |
186 | | - "$ref": "#/definitions/flag" |
| 265 | + "$ref": "#/definitions/baseFlag" |
187 | 266 | }, |
188 | 267 | { |
189 | 268 | "$ref": "#/definitions/numberVariants" |
190 | 269 | } |
191 | 270 | ] |
192 | 271 | }, |
193 | 272 | "objectFlag": { |
| 273 | + "title": "Object flag", |
| 274 | + "description": "A flag having arbitrary object values.", |
194 | 275 | "allOf": [ |
195 | 276 | { |
196 | | - "$ref": "#/definitions/flag" |
| 277 | + "$ref": "#/definitions/baseFlag" |
197 | 278 | }, |
198 | 279 | { |
199 | 280 | "$ref": "#/definitions/objectVariants" |
|
203 | 284 | "metadata": { |
204 | 285 | "type": "object", |
205 | 286 | "additionalProperties": { |
206 | | - "description": "Any additional key/value pair with value of type boolean, string, or number.", |
207 | 287 | "type": [ |
208 | 288 | "string", |
209 | 289 | "number", |
210 | 290 | "boolean" |
211 | 291 | ] |
212 | | - }, |
213 | | - "required": [] |
| 292 | + } |
214 | 293 | } |
215 | 294 | } |
216 | 295 | } |
0 commit comments