Skip to content

Commit a016f66

Browse files
benjirotoddbaert
authored andcommitted
feat!: Use same type for flag metadata and event metadata
The spec describes two types(flag metadata, and event metadata) that are functionally the same. This PR makes a breaking change to bring both of the types to use a generic ImmutableMetadata type. - Rename BaseMetadata to Immutable, make sealed class and implement a empty constructor Fixes: #234 Signed-off-by: Benjamin Evenson <[email protected]>
1 parent 43f14cc commit a016f66

7 files changed

+182
-198
lines changed

src/OpenFeature/Model/FlagEvaluationDetails.cs

+60-60
Original file line numberDiff line numberDiff line change
@@ -2,74 +2,74 @@
22

33
namespace OpenFeature.Model
44
{
5-
/// <summary>
6-
/// The contract returned to the caller that describes the result of the flag evaluation process.
7-
/// </summary>
8-
/// <typeparam name="T">Flag value type</typeparam>
9-
/// <seealso href="https://github.com/open-feature/spec/blob/v0.7.0/specification/types.md#evaluation-details"/>
10-
public sealed class FlagEvaluationDetails<T>
11-
{
125
/// <summary>
13-
/// Feature flag evaluated value
6+
/// The contract returned to the caller that describes the result of the flag evaluation process.
147
/// </summary>
15-
public T Value { get; }
8+
/// <typeparam name="T">Flag value type</typeparam>
9+
/// <seealso href="https://github.com/open-feature/spec/blob/v0.7.0/specification/types.md#evaluation-details"/>
10+
public sealed class FlagEvaluationDetails<T>
11+
{
12+
/// <summary>
13+
/// Feature flag evaluated value
14+
/// </summary>
15+
public T Value { get; }
1616

17-
/// <summary>
18-
/// Feature flag key
19-
/// </summary>
20-
public string FlagKey { get; }
17+
/// <summary>
18+
/// Feature flag key
19+
/// </summary>
20+
public string FlagKey { get; }
2121

22-
/// <summary>
23-
/// Error that occurred during evaluation
24-
/// </summary>
25-
public ErrorType ErrorType { get; }
22+
/// <summary>
23+
/// Error that occurred during evaluation
24+
/// </summary>
25+
public ErrorType ErrorType { get; }
2626

27-
/// <summary>
28-
/// Message containing additional details about an error.
29-
/// <para>
30-
/// Will be <see langword="null" /> if there is no error or if the provider didn't provide any additional error
31-
/// details.
32-
/// </para>
33-
/// </summary>
34-
public string? ErrorMessage { get; }
27+
/// <summary>
28+
/// Message containing additional details about an error.
29+
/// <para>
30+
/// Will be <see langword="null" /> if there is no error or if the provider didn't provide any additional error
31+
/// details.
32+
/// </para>
33+
/// </summary>
34+
public string? ErrorMessage { get; }
3535

36-
/// <summary>
37-
/// Describes the reason for the outcome of the evaluation process
38-
/// </summary>
39-
public string? Reason { get; }
36+
/// <summary>
37+
/// Describes the reason for the outcome of the evaluation process
38+
/// </summary>
39+
public string? Reason { get; }
4040

41-
/// <summary>
42-
/// A variant is a semantic identifier for a value. This allows for referral to particular values without
43-
/// necessarily including the value itself, which may be quite prohibitively large or otherwise unsuitable
44-
/// in some cases.
45-
/// </summary>
46-
public string? Variant { get; }
41+
/// <summary>
42+
/// A variant is a semantic identifier for a value. This allows for referral to particular values without
43+
/// necessarily including the value itself, which may be quite prohibitively large or otherwise unsuitable
44+
/// in some cases.
45+
/// </summary>
46+
public string? Variant { get; }
4747

48-
/// <summary>
49-
/// A structure which supports definition of arbitrary properties, with keys of type string, and values of type boolean, string, or number.
50-
/// </summary>
51-
public FlagMetadata? FlagMetadata { get; }
48+
/// <summary>
49+
/// A structure which supports definition of arbitrary properties, with keys of type string, and values of type boolean, string, or number.
50+
/// </summary>
51+
public ImmutableMetadata? FlagMetadata { get; }
5252

53-
/// <summary>
54-
/// Initializes a new instance of the <see cref="FlagEvaluationDetails{T}"/> class.
55-
/// </summary>
56-
/// <param name="flagKey">Feature flag key</param>
57-
/// <param name="value">Evaluated value</param>
58-
/// <param name="errorType">Error</param>
59-
/// <param name="reason">Reason</param>
60-
/// <param name="variant">Variant</param>
61-
/// <param name="errorMessage">Error message</param>
62-
/// <param name="flagMetadata">Flag metadata</param>
63-
public FlagEvaluationDetails(string flagKey, T value, ErrorType errorType, string? reason, string? variant,
64-
string? errorMessage = null, FlagMetadata? flagMetadata = null)
65-
{
66-
this.Value = value;
67-
this.FlagKey = flagKey;
68-
this.ErrorType = errorType;
69-
this.Reason = reason;
70-
this.Variant = variant;
71-
this.ErrorMessage = errorMessage;
72-
this.FlagMetadata = flagMetadata;
53+
/// <summary>
54+
/// Initializes a new instance of the <see cref="FlagEvaluationDetails{T}"/> class.
55+
/// </summary>
56+
/// <param name="flagKey">Feature flag key</param>
57+
/// <param name="value">Evaluated value</param>
58+
/// <param name="errorType">Error</param>
59+
/// <param name="reason">Reason</param>
60+
/// <param name="variant">Variant</param>
61+
/// <param name="errorMessage">Error message</param>
62+
/// <param name="flagMetadata">Flag metadata</param>
63+
public FlagEvaluationDetails(string flagKey, T value, ErrorType errorType, string? reason, string? variant,
64+
string? errorMessage = null, ImmutableMetadata? flagMetadata = null)
65+
{
66+
this.Value = value;
67+
this.FlagKey = flagKey;
68+
this.ErrorType = errorType;
69+
this.Reason = reason;
70+
this.Variant = variant;
71+
this.ErrorMessage = errorMessage;
72+
this.FlagMetadata = flagMetadata;
73+
}
7374
}
74-
}
7575
}

src/OpenFeature/Model/FlagMetadata.cs

-25
This file was deleted.

src/OpenFeature/Model/BaseMetadata.cs src/OpenFeature/Model/ImmutableMetadata.cs

+22-7
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,31 @@
11
using System.Collections.Generic;
22
using System.Collections.Immutable;
33

4+
#nullable enable
45
namespace OpenFeature.Model;
56

67
/// <summary>
7-
/// Represents the base class for metadata objects.
8+
/// Represents immutable metadata associated with feature flags and events.
89
/// </summary>
9-
public abstract class BaseMetadata
10+
/// <seealso href="https://github.com/open-feature/spec/blob/v0.7.0/specification/types.md#flag-metadata"/>
11+
/// <seealso href="https://github.com/open-feature/spec/blob/v0.7.0/specification/types.md#event-metadata"/>
12+
public sealed class ImmutableMetadata
1013
{
1114
private readonly ImmutableDictionary<string, object> _metadata;
1215

13-
internal BaseMetadata(Dictionary<string, object> metadata)
16+
/// <summary>
17+
/// Constructor for the <see cref="ImmutableMetadata"/> class.
18+
/// </summary>
19+
public ImmutableMetadata()
20+
{
21+
this._metadata = ImmutableDictionary<string, object>.Empty;
22+
}
23+
24+
/// <summary>
25+
/// Constructor for the <see cref="ImmutableMetadata"/> class.
26+
/// </summary>
27+
/// <param name="metadata">The dictionary containing the metadata.</param>
28+
public ImmutableMetadata(Dictionary<string, object> metadata)
1429
{
1530
this._metadata = metadata.ToImmutableDictionary();
1631
}
@@ -20,7 +35,7 @@ internal BaseMetadata(Dictionary<string, object> metadata)
2035
/// </summary>
2136
/// <param name="key">The key of the value to retrieve.</param>
2237
/// <returns>The boolean value associated with the key, or null if the key is not found.</returns>
23-
public virtual bool? GetBool(string key)
38+
public bool? GetBool(string key)
2439
{
2540
return this.GetValue<bool>(key);
2641
}
@@ -30,7 +45,7 @@ internal BaseMetadata(Dictionary<string, object> metadata)
3045
/// </summary>
3146
/// <param name="key">The key of the value to retrieve.</param>
3247
/// <returns>The integer value associated with the key, or null if the key is not found.</returns>
33-
public virtual int? GetInt(string key)
48+
public int? GetInt(string key)
3449
{
3550
return this.GetValue<int>(key);
3651
}
@@ -40,7 +55,7 @@ internal BaseMetadata(Dictionary<string, object> metadata)
4055
/// </summary>
4156
/// <param name="key">The key of the value to retrieve.</param>
4257
/// <returns>The double value associated with the key, or null if the key is not found.</returns>
43-
public virtual double? GetDouble(string key)
58+
public double? GetDouble(string key)
4459
{
4560
return this.GetValue<double>(key);
4661
}
@@ -50,7 +65,7 @@ internal BaseMetadata(Dictionary<string, object> metadata)
5065
/// </summary>
5166
/// <param name="key">The key of the value to retrieve.</param>
5267
/// <returns>The string value associated with the key, or null if the key is not found.</returns>
53-
public virtual string? GetString(string key)
68+
public string? GetString(string key)
5469
{
5570
var hasValue = this._metadata.TryGetValue(key, out var value);
5671
if (!hasValue)

src/OpenFeature/Model/ProviderEvents.cs

+27-28
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,39 @@
33

44
namespace OpenFeature.Model
55
{
6-
/// <summary>
7-
/// The EventHandlerDelegate is an implementation of an Event Handler
8-
/// </summary>
9-
public delegate void EventHandlerDelegate(ProviderEventPayload? eventDetails);
10-
11-
/// <summary>
12-
/// Contains the payload of an OpenFeature Event.
13-
/// </summary>
14-
public class ProviderEventPayload
15-
{
166
/// <summary>
17-
/// Name of the provider.
7+
/// The EventHandlerDelegate is an implementation of an Event Handler
188
/// </summary>
19-
public string? ProviderName { get; set; }
9+
public delegate void EventHandlerDelegate(ProviderEventPayload? eventDetails);
2010

2111
/// <summary>
22-
/// Type of the event
12+
/// Contains the payload of an OpenFeature Event.
2313
/// </summary>
24-
public ProviderEventTypes Type { get; set; }
14+
public class ProviderEventPayload
15+
{
16+
/// <summary>
17+
/// Name of the provider.
18+
/// </summary>
19+
public string? ProviderName { get; set; }
2520

26-
/// <summary>
27-
/// A message providing more information about the event.
28-
/// </summary>
29-
public string? Message { get; set; }
21+
/// <summary>
22+
/// Type of the event
23+
/// </summary>
24+
public ProviderEventTypes Type { get; set; }
3025

31-
/// <summary>
32-
/// A List of flags that have been changed.
33-
/// </summary>
34-
public List<string>? FlagsChanged { get; set; }
26+
/// <summary>
27+
/// A message providing more information about the event.
28+
/// </summary>
29+
public string? Message { get; set; }
3530

36-
/// <summary>
37-
/// Metadata information for the event.
38-
/// </summary>
39-
// TODO: This needs to be changed to a EventMetadata object
40-
public Dictionary<string, object>? EventMetadata { get; set; }
41-
}
31+
/// <summary>
32+
/// A List of flags that have been changed.
33+
/// </summary>
34+
public List<string>? FlagsChanged { get; set; }
35+
36+
/// <summary>
37+
/// Metadata information for the event.
38+
/// </summary>
39+
public ImmutableMetadata? EventMetadata { get; set; }
40+
}
4241
}

0 commit comments

Comments
 (0)