-
Notifications
You must be signed in to change notification settings - Fork 48
BREAKING CHANGE: Add generic structure type, use context/getObject #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
32ae215
to
036d920
Compare
FYI @rgrassian-split. I would like to get your thoughts on this. How would this change impact the provider you're working on? |
@beeme1mr Hey! This is a fantastic change, I was actually running into some issues with the |
@rgrassian-split it would be good if you could put some feedback in #50. Really glad to have your input. |
@toddbaert Just did, that is actually the bigger deal for us that I very much support switching it from the current approach |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lots of formatting churn makes the testing stuff (especially spec definitions) a bit hard to read.
036d920
to
f5d302f
Compare
Codecov Report
@@ Coverage Diff @@
## main #51 +/- ##
============================================
- Coverage 93.01% 90.79% -2.22%
- Complexity 124 146 +22
============================================
Files 17 19 +2
Lines 272 326 +54
Branches 12 7 -5
============================================
+ Hits 253 296 +43
- Misses 11 20 +9
- Partials 8 10 +2
Flags with carried forward coverage won't be shown. Click here to find out more.
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
a70cb15
to
7c02ac7
Compare
8520078
to
2fdc4ee
Compare
@justinabrahms I think I've cleaned up a lot of the whitespace changes. A few are possibly improvements (missing newlines in some places, etc). I've left those. I also added array support in I'm going to test this locally in my provider and see if it makes things nicer. Let me know what you think. I had to rebase/squash to fix the whitespace issue, so previous commits are gone... I hope that's not a problem 😬 |
@justinabrahms I made some more changes. Our abstraction was leaky because any node in a JSON structure can be a JSON structure, an array or a primitive. That wasn't reflected the implementation leading to some issues, particularly with type safety around arrays. What I've done in this commit, is introduce a This is similar to how java-grpc represents their profobuf, which is similar in structure to JSON, and something like a simplified version of LDValue. I've maintained most of the previous work. I think this is something along the lines of what @kinyoklion was recommending as well. |
@@ -86,7 +86,7 @@ public EvaluationContext add(String key, Structure value) { | |||
return this; | |||
} | |||
|
|||
public <T> EvaluationContext add(String key, List<T> value) { | |||
public <T extends Value> EvaluationContext add(String key, List<Value> value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lists must be of type Value
.
ee58654
to
25138b2
Compare
Signed-off-by: Todd Baert <toddbaert@gmail.com>
25138b2
to
b81b944
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I need to play around with constructing a few of these objects to figure out what the API feels like.
src/main/java/dev/openfeature/javasdk/internal/StructureFieldType.java
Outdated
Show resolved
Hide resolved
OK @justinabrahms, I'll leave it up to you to merge it then (or message with more feedback). @kinyoklion has also approved. I think we'll need to do something similar in dotnet cc @benjiro |
Signed-off-by: Todd Baert <toddbaert@gmail.com>
* @return all attributes on the structure | ||
*/ | ||
public Map<String, Value> asMap() { | ||
return new HashMap<>(this.attributes); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we OK with a shallow copy of the values? The application developer will use this to obtain all the values hence a shallow copy is OK in that scenario. But will this structure also be used during building and mutating the EvaluationContext?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a good question...
I suspect that for mutating, users will be using the merge
and add
functions in the EvaluationContext. I don't have any strong opinions about if this should be a shallow copy, deep copy, or just expose the inner map (though I think in most cases, that's a bad choice). I guess whatever we choose it should be well-documented.
Does anyone have a strong argument for a particular direction on this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#53 Moved this discussion here.
Signed-off-by: Todd Baert <toddbaert@gmail.com>
…viders. Signed-off-by: Justin Abrahms <justin@abrah.ms>
…sage of the API ambiguous. Signed-off-by: Justin Abrahms <justin@abrah.ms>
Signed-off-by: Justin Abrahms <justin@abrah.ms>
Fix a few intellij complains in the README as well Signed-off-by: Justin Abrahms <justin@abrah.ms>
Clear up warning of parameterized types. Signed-off-by: Justin Abrahms <justin@abrah.ms>
bcf9a6c
to
c86b4c1
Compare
33c1f26
to
4662444
Compare
As described in #50, I think that expected a
T
back from object flag resolvers is not sustainable. I believe it pushes too much of a burden on providers to instantiate a new T (whatever it may be) and map the attributes received from the backend into it.Instead, I've added a more generic
Structure
(language used in the OpenFeature spec) with methods similar to the existingEvaluationContext
. I've also made theEvaluationContext
inherit from this to reduce duplication (theEvaluationContext
is also referred to as a "structure" in the spec.After this change, providers will create a new
Structure
and add the corresponding fields from the json/xml/protobuf they are concerned with.In summary:
Structure
type which represents JSON dataEvaluationContext
inheritsencapsultes this using lombok's@Delegate
.addIntegerAttribute
,addStringAttribute
, etc, inEvaluationContext
to a single overloadedadd
method.EvaluationContext
(I'm not convinced these are that valuable, but I'll take feedback).Value
wrapper class that houses one of: Structure, List, Boolean, etc (representations of all the possible JSON node values).