Flagsmith / Flagsmith/flagsmith

Dependencies API: list dependencies and dependents

Open
#8,414 0 comments 0 reactions 1 assignee Claimed by @emyller View on GitHub
Dominant language
Python
Stars
6.6k
Forks
567
Avg merge
1d 13h
Merged PRs (30d)
121

Description

Add two endpoints:

- `GET /api/v1/environments/{environment_api_key}/features/{feature}/dependencies`
- `GET /api/v1/environments/{environment_api_key}/features/{feature}/dependents`

Both resolve the graph at query time by joining `SegmentFlagReference` rows to live `FeatureSegment` rows, so results reflect the currently live version.

Both must include dependencies / dependents derived from `$.flags` conditions in both user-created and system segments. Only the latter are removable through the API, so entries need to indicate which are API-managed.

`features/{feature}/dependencies` response example (tidy up in accordance with `dependents`):

```json
{
"results": [
{
"feature": "prerequisite",
"segment_id": 1,
"condition": {
"property": "$.flags.prerequisite.value",
"operator": "NOT_EQUAL",
"value": "true"
},
"is_system": true
},
{
"feature": "prerequisite2",
"segment_id": 2,
"condition": {
"property": "$.flags.prerequisite.variant",
"operator": "IN",
"value": "foo,bar"
},
"is_system": false
}
]
}
```

`features/{feature}/dependents` response example:

```json
{
"results": [
{
"feature": {
"id": 8,
"name": "dependent"
},
"segment": {
"id": 3,
"name": "dependency-1",
"condition": {
"property": "$.flags.{feature}.value",
"operator": "NOT_EQUAL",
"value": "true"
},
"is_system": true
}
},
{
"feature": {
"id": 8,
"name": "dependent"
},
"segment": {
"id": 4,
"name": "user segment",
"condition": {
"property": "$.flags.{feature}.value",
"operator": "IN",
"value": "baz,bar"
},
"is_system": false
}
}
]
}
```

### Acceptance criteria

- `GET .../dependencies` lists prerequisites for the feature in the given environment.
- `GET .../dependents` lists features whose evaluation depends on this one in that environment.
- Both include dependencies from user-authored segment conditions, and mark which entries are API-managed.
- Both resolve against the live version; a scheduled but unpublished version is not reflected.
- A dependency present in one environment does not appear in another.
- Query count does not scale with the number of segments in the project.
- Both endpoints appear in the generated OpenAPI schema with typed serializers, and `make generate-full-openapi` reproduces them.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.