Configuration schema and models
The feature-flag configuration model defines a stable contract from flag files to flag evaluation. It describes each flag as a set of typed variations plus targeting and rollout rules, then carries that data through an input DTO into the validated domain model used by the SDK.
Configuration document
The configuration document is a map from flag names to flag definitions. YAML, JSON, and TOML inputs use the same field names, so the file format changes how data is read but not the meaning of a valid flag.
The top-level flag definition supports these groups of data:
| Group | Purpose |
|---|---|
| Variations | Names the values that evaluation can return. All values for one flag must have the same type. |
| Targeting | Lists rules that can select a variation for a matching evaluation context. |
| Default rule | Selects the result when no targeting rule matches. |
| Rollout controls | Describes percentage distribution, progressive rollout, scheduled changes, or an experiment window. |
| Flag state | Controls disablement, event tracking, and the flag version. |
| Supporting data | Provides a bucketing key and free-form metadata. |
The JSON Schema in .schema/flag-schema.json is the validation-facing description of this shape. It requires variations and defaultRule at the flag level and rejects fields outside the declared schema objects. The schema also describes rule fields and the date-time fields used by experimentation, progressive rollout, and scheduled changes.
Flag data transfer object
The DTO is the input representation for one flag. It preserves optional fields as pointers so that an omitted value remains distinct from an explicit false, zero, or empty value. This distinction lets later processing apply defaults and merge scheduled changes without losing the author’s intent. modules/…/dto.go defines the shared representation, while model/…/dto.go re-exports it for the public model package.
The DTO is read as a map keyed by flag name. The configuration loader parses supported file formats into this map, and retrievers use the same shape when they deliver new flag data. This keeps file loading and remote retrieval on one compatibility boundary.
flowchart LR
A[Flag file or retriever bytes] --> B[DTO map keyed by flag name]
B --> C[InternalFlag conversion]
C --> D[Validation]
D --> E[Evaluation-ready flag state]
References: .schema/flag-schema.json• L1-65 modules/…/dto.go• L7-53 model/…/dto.go• L1-8 cmdhelpers/…/read_config_file.go• L20-82 retriever/manager.go• L295-366
Domain flag model
The InternalFlag is the domain representation of a flag after input decoding. It holds the same user-facing configuration concepts as the DTO, but it is the model consumed by validation and evaluation. The conversion is intentionally direct for the shared fields; experimentation is mapped from its DTO form to the domain rollout form.
An InternalFlag exposes a flag value through the evaluation context. It applies active scheduled changes, checks disablement and experiment timing, then evaluates targeting rules before the default rule. The model therefore connects configuration compatibility to the values and resolution details returned to SDK callers.
The domain model also provides the Flag interface used by consumers of loaded state. That interface exposes value resolution, version, event tracking, disablement, variation lookup, and metadata without requiring callers to know the stored representation.
References: modules/…/internal_flag.go• L19-61 modules/…/internal_flag.go• L63-130 modules/…/flag.go• L7-32 modules/…/converter.go• L7-51
Variation and rule model
Variations are the named outcomes of a flag. A rule chooses one outcome directly, distributes users across outcomes by percentage, or moves users between two outcomes through a progressive rollout. A rule can also be disabled, and a targeting rule can carry a name so scheduled changes can identify it.
Targeting rules use a query against the evaluation context. The model accepts the repository’s default query syntax and JSONLogic when the rule declares that format. A rule without a query is valid only in the default-rule position; the default rule is the final choice after all targeting rules fail to apply.
The model requires a bucketing key for percentage and progressive rollout behavior. The key makes distribution stable for the same flag and evaluation subject. A direct variation result does not need that key.
References: modules/…/rule.go• L19-50 modules/…/rule.go• L53-104 modules/…/rule_validation.go• L11-159 modules/…/internal_flag.go• L160-201
Rollout representations
Rollout data extends the same flag model instead of defining a separate kind of flag. Each representation changes when or how the existing flag fields apply.
| Representation | Configuration meaning | Compatibility concern |
|---|---|---|
| Percentage rule | Splits users among named variations. | Every referenced variation must exist and the configured total cannot be zero. |
| Progressive rollout | Moves from an initial percentage and variation to an end state over time. | Both steps need valid dates and variations, and the end percentage cannot be below the initial percentage. |
| Experimentation | Limits active evaluation to a start and end time. | The time window controls whether normal evaluation can run. |
| Scheduled rollout | Applies dated partial updates to a flag. | Rule names support targeted rule updates, and later active steps override earlier changes. |
Scheduled steps reuse the flag fields inside a dated step. This allows a step to update only the parts of a flag that it declares, while the active flag keeps the rest of its current configuration.
References: modules/…/rollout_scheduled.go• L7-11 modules/…/rollout_progressive.go• L7-54 modules/…/rollout_experimentation.go• L7-13 modules/…/internal_flag.go• L204-276 modules/…/rule_validation.go• L40-105
Compatibility validation
Validation protects the boundary between accepted configuration and evaluation-ready state. The cache converts each DTO, validates the resulting domain flag, and keeps only valid flags. An invalid flag is reported and omitted from the active in-memory set rather than being evaluated as if it were complete.
Validation checks both structure and relationships. A flag needs variations and a default rule. Variation values must be non-nil and share one type. Each rule needs a usable result, and references from direct, percentage, or progressive rollout rules must resolve to declared variations. Targeting queries must also parse in their selected query format.
The checks are complementary rather than interchangeable:
- The JSON Schema describes the external shape and field types.
- DTO decoding maps supported file formats into the shared input form.
- Domain validation checks cross-field rules that a shape schema cannot fully express.
- Cache admission determines which validated flags become available to evaluation.
References: .schema/flag-schema.json• L59-65 modules/…/internal_flag.go• L286-340 modules/…/rule_validation.go• L11-159 internal/…/in_memory_cache.go• L26-32 internal/…/in_memory_cache.go• L68-80
Validation-facing manifest
The flag manifest is a separate, compact representation for tooling. It summarizes each flag with a flag type, default value, and description inside an envelope that declares the OpenFeature CLI schema URL. It is generated from the same DTO-to-domain path, so invalid or unsupported flag definitions can affect manifest generation as well as runtime loading.
The manifest does not replace the full flag configuration. It gives tools a standard view of the values and types exposed by the configuration, while the DTO and domain model retain targeting and rollout behavior.
References: cmd/…/manifest.go• L19-74 cmd/…/flag_manifest.go• L9-27 cmdhelpers/…/flag_definition.go• L3-7 cmdhelpers/…/flag_type.go• L3-11
Change checklist
When these files or sections are changed, remember to consider these:
- Keep .schema/flag-schema.json aligned with the serialized field names and required fields in modules/…/dto.go and modules/…/rule.go.
- Preserve the DTO-to-domain mapping in modules/…/converter.go when adding or renaming a configuration field.
- Update both direct flag fields and embedded scheduled-step fields when a change must be available to scheduled rollouts.
- Keep domain validation consistent with fields that the schema accepts, especially variation references, query formats, and rollout dates.
- Check manifest generation when changing variation types or default-result behavior because it reads the same configuration model.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A flag has no variations or no default rule. | The flag is rejected and is not placed in the active cache. | Schema requirements and InternalFlag.IsValid enforce both fields. |
| Variations use different value types. | The flag fails validation instead of exposing an inconsistent evaluation result. | Domain validation compares all variation types. |
| A rule names a missing variation. | Direct or rollout evaluation cannot produce a declared value. | Rule validation checks every referenced variation. |
| A targeting query is missing or cannot be parsed. | The targeting rule is rejected. | Non-default rules require a valid query in the selected format. |
| A percentage or progressive rule lacks a usable bucketing key at evaluation time. | Evaluation returns the SDK default with a targeting-key error. | The rule model marks these modes as bucketing-dependent. |
Key files
| File | Why to read it |
|---|---|
| .schema/flag-schema.json | Defines the external compatibility shape for flag files. |
| modules/…/dto.go | Defines the input DTO and its serialized configuration fields. |
| modules/…/converter.go | Shows the boundary from input data to the domain flag model. |
| modules/…/internal_flag.go | Defines the evaluation-facing flag state and whole-flag validation. |
| modules/…/rule.go | Defines targeting, direct variation, percentage, and progressive rollout behavior. |
| modules/…/rule_validation.go | Defines cross-field checks for rule compatibility. |
| modules/…/rollout_scheduled.go | Defines dated partial flag updates. |
| cmdhelpers/…/read_config_file.go | Shows how supported file formats enter the shared DTO shape. |
| internal/…/in_memory_cache.go | Shows how validated domain flags become active runtime state. |
| cmd/…/manifest.go | Shows how the shared model produces a tooling-facing manifest. |