@@ -23,7 +23,82 @@ class RuleAction(str, Enum):
23
23
CONTAINS = "CONTAINS"
24
24
25
25
26
- class SchemaValidator :
26
+ class SchemaValidator (BaseValidator ):
27
+ """Validates feature flag schema configuration
28
+
29
+ Schema
30
+ ------
31
+
32
+ **Feature object**
33
+
34
+ A dictionary containing default value and rules for matching.
35
+ The value MUST be an object and MIGHT contain the following members:
36
+
37
+ * **default**: `bool`. Defines default feature value. This MUST be present
38
+ * **rules**: `Dict[str, Dict]`. Rules object. This MIGHT be present
39
+
40
+ ```json
41
+ {
42
+ "my_feature": {
43
+ "default": True,
44
+ "rules": {}
45
+ }
46
+ }
47
+ ```
48
+
49
+ **Rules object**
50
+
51
+ A dictionary with each rule and their conditions that a feature might have.
52
+ The value MIGHT be present, and when defined it MUST contain the following members:
53
+
54
+ * **when_match**: `bool`. Defines value to return when context matches conditions
55
+ * **conditions**: `List[Dict]`. Conditions object. This MUST be present
56
+
57
+ ```json
58
+ {
59
+ "my_feature": {
60
+ "default": True,
61
+ "rules": {
62
+ "tenant id equals 345345435": {
63
+ "when_match": False,
64
+ "conditions": []
65
+ }
66
+ }
67
+ }
68
+ }
69
+ ```
70
+
71
+ **Conditions object**
72
+
73
+ A list of dictionaries containing conditions for a given rule.
74
+ The value MUST contain the following members:
75
+
76
+ * **action**: `str`. Operation to perform to match a key and value.
77
+ The value MUST be either EQUALS, STARTSWITH, ENDSWITH, CONTAINS
78
+ * **key**: `str`. Key in given context to perform operation
79
+ * **value**: `Any`. Value in given context that should match action operation.
80
+
81
+ ```json
82
+ {
83
+ "my_feature": {
84
+ "default": True,
85
+ "rules": {
86
+ "tenant id equals 345345435": {
87
+ "when_match": False,
88
+ "conditions": [
89
+ {
90
+ "action": "EQUALS",
91
+ "key": "tenant_id",
92
+ "value": "345345435",
93
+ }
94
+ ]
95
+ }
96
+ }
97
+ }
98
+ }
99
+ ```
100
+ """
101
+
27
102
def __init__ (self , schema : Dict [str , Any ]):
28
103
self .schema = schema
29
104
@@ -37,6 +112,8 @@ def validate(self) -> None:
37
112
38
113
39
114
class FeaturesValidator (BaseValidator ):
115
+ """Validates each feature and calls RulesValidator to validate its rules"""
116
+
40
117
def __init__ (self , schema : Dict ):
41
118
self .schema = schema
42
119
@@ -58,6 +135,8 @@ def validate_feature(name, feature):
58
135
59
136
60
137
class RulesValidator (BaseValidator ):
138
+ """Validates each rule and calls ConditionsValidator to validate each rule's conditions"""
139
+
61
140
def __init__ (self , feature : Dict [str , Any ]):
62
141
self .feature = feature
63
142
self .feature_name = next (iter (self .feature ))
0 commit comments