Expose experiment context_keys in the experiments API
Summary
The GET /experiments API does not expose each experiment's declared context_keys. The definition object is serialized from Feature::Definition (lib/feature/shared.rb PARAMS), which has no context field, and context_keys lives on the experiment class (app/experiments/*), not the feature definition.
As a result, API consumers (notably the Experiment Dashboard) cannot tell which context keys (user, namespace, project, actor) an experiment expects when calling the force/read/clear assignment endpoints. The dashboard can therefore only operate on the current user.
Proposal
Expose a top-level context array on the Experiment entity, resolving the experiment class the same way Experiments::ContextResolver does:
expose :context do |definition|
ApplicationExperiment.constantize(definition.attributes[:name]).context_keys
rescue Gitlab::AbstractMethodError, Gitlab::Experiment::UnregisteredExperiment
[]
endReturns e.g. ["user"], or [] for experiments that don't declare context keys / aren't registered.
Acceptance criteria
-
GET /experimentsreturns acontextarray per experiment listing itscontext_keys. - Returns
[]for experiments without declared context keys (no error). - Entity + request spec coverage.
- API docs + regenerated OpenAPI.
Why
Unblocks the dashboard from rendering the correct context inputs so team members can force/clear assignments for arbitrary users/namespaces/projects (gitlab-org/growth/experiment-dashboard#5), not just themselves.
Related to #591174 (closed)