OpenFeature (Java)
An OpenFeature provider: code written against the vendor-neutral OpenFeature API evaluates Switchyard flags, in memory, through switchyard-java. Moving to (or away from) Switchyard then means changing one line: the provider.
java
OpenFeatureAPI api = OpenFeatureAPI.getInstance();
api.setProviderAndWait(new SwitchyardProvider(
SwitchyardClient.builder(System.getenv("SWITCHYARD_SDK_KEY"))
.baseUri("https://flags.example.com")
.build()));
Client flags = api.getClient();
boolean newCheckout = flags.getBooleanValue("new-checkout", false, new ImmutableContext(userId));
String color = flags.getStringValue("checkout-button", "green",
new ImmutableContext(userId, Map.of("plan", new Value("pro"))));Add io.github.nikolaviews:switchyard-openfeature next to dev.openfeature:sdk (1.15 or later; your application chooses the version).
How it maps
| OpenFeature | Switchyard |
|---|---|
| targeting key | the context key (rollouts, rules on key) |
| other context entries | attributes: text as is, numbers and booleans as text, instants as RFC 3339 timestamps (lists and structures are skipped) |
getBooleanValue |
boolean flags |
getStringValue |
text flags |
getIntegerValue, getDoubleValue |
number flags (TYPE_MISMATCH for a non-whole number asked as an integer) |
getObjectValue |
JSON flags |
reason TARGETING_MATCH / DEFAULT / DISABLED |
a rule matched (its index is in the flag metadata as ruleIndex) / everyone else's value / the flag is off |
reason PREREQUISITE_FAILED |
a prerequisite flag didn't give the value it needs |
| variant | the variation's index, or true/false |
error FLAG_NOT_FOUND, TYPE_MISMATCH, PROVIDER_NOT_READY |
unknown flag, wrong type asked for, no flags yet: OpenFeature returns your default |
Flag changes are sent on as PROVIDER_CONFIGURATION_CHANGED events with the changed keys. shutdown() closes the client.
Develop
bash
../../server/mvnw -f ../java/pom.xml install -DskipTests # the provider builds on the local client
../../server/mvnw verify