Skip to content

Commit 8a3b455

Browse files
committed
feat: add support for more detailed owner schema in flagpole
1 parent aa58e30 commit 8a3b455

File tree

2 files changed

+46
-6
lines changed

2 files changed

+46
-6
lines changed

src/flagpole/__init__.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,22 @@ def load_json_schema() -> dict[str, Any]:
8787
return data
8888

8989

90+
@dataclasses.dataclass(frozen=True)
91+
class OwnerInfo:
92+
team: str
93+
"The team that owns this feature."
94+
95+
email: str | None = None
96+
"The email address of the owner."
97+
98+
9099
@dataclasses.dataclass(frozen=True)
91100
class Feature:
92101
name: str
93102
"The feature name."
94103

95-
owner: str
96-
"The owner of this feature. Either an email address or team name, preferably."
104+
owner: str | OwnerInfo
105+
"The owner of this feature."
97106

98107
enabled: bool = dataclasses.field(default=True)
99108
"Whether or not the feature is enabled."
@@ -133,9 +142,20 @@ def from_feature_dictionary(cls, name: str, config_dict: dict[str, Any]) -> Feat
133142
raise InvalidFeatureFlagConfiguration("Feature has no segments defined")
134143
try:
135144
segments = [Segment.from_dict(segment) for segment in segment_data]
145+
146+
raw_owner = config_dict.get("owner", "")
147+
owner: str | OwnerInfo
148+
if isinstance(raw_owner, dict):
149+
owner = OwnerInfo(
150+
team=raw_owner["team"],
151+
email=raw_owner.get("email"),
152+
)
153+
else:
154+
owner = str(raw_owner)
155+
136156
feature = cls(
137157
name=name,
138-
owner=str(config_dict.get("owner", "")),
158+
owner=owner,
139159
enabled=bool(config_dict.get("enabled", True)),
140160
created_at=str(config_dict.get("created_at")),
141161
segments=segments,

src/flagpole/flagpole-schema.json

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,29 @@
1010
},
1111
"owner": {
1212
"title": "Owner",
13-
"description": "The owner of this feature. Either an email address or team name, preferably.",
14-
"minLength": 1,
15-
"type": "string"
13+
"description": "The owner of this feature.",
14+
"oneOf": [
15+
{
16+
"type": "string",
17+
"minLength": 1
18+
},
19+
{
20+
"type": "object",
21+
"properties": {
22+
"team": {
23+
"type": "string",
24+
"minLength": 1,
25+
"description": "The team that owns this feature."
26+
},
27+
"email": {
28+
"type": ["string", "null"],
29+
"description": "The email address of the owner. Not required."
30+
}
31+
},
32+
"required": ["team"],
33+
"additionalProperties": false
34+
}
35+
]
1636
},
1737
"segments": {
1838
"title": "Segments",

0 commit comments

Comments
 (0)