Skip to content

Commit 342ecb8

Browse files
feat: implementing new datafile structural changes for json variable (#252)
* feat: implementing new datafile structural changes for json variable
1 parent 4536a32 commit 342ecb8

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

pkg/config/datafileprojectconfig/entities/entities.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ type Variable struct {
6868
ID string `json:"id"`
6969
Key string `json:"key"`
7070
Type entities.VariableType `json:"type"`
71+
SubType entities.VariableType `json:"subType"`
7172
}
7273

7374
// TrafficAllocation represents a traffic allocation range from the Optimizely datafile

pkg/config/datafileprojectconfig/mappers/feature.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,17 @@ func MapFeatures(featureFlags []datafileEntities.FeatureFlag, rolloutMap map[str
4646

4747
variableMap := map[string]entities.Variable{}
4848
for _, variable := range featureFlag.Variables {
49+
50+
realType := variable.Type
51+
if variable.Type == entities.String && variable.SubType == entities.JSON {
52+
realType = entities.JSON
53+
}
4954
variableMap[variable.Key] = entities.Variable{
5055
DefaultValue: variable.DefaultValue,
5156
ID: variable.ID,
5257
Key: variable.Key,
53-
Type: variable.Type}
58+
Type: realType}
59+
5460
}
5561

5662
feature.FeatureExperiments = featureExperiments

pkg/config/datafileprojectconfig/mappers/feature_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func TestMapFeatures(t *testing.T) {
3131
"key": "test_feature_21111",
3232
"rolloutId": "41111",
3333
"experimentIds": ["31111"],
34-
"variables": [{"defaultValue":"1","id":"1","key":"test","type":"integer"}]
34+
"variables": [{"defaultValue":"1","id":"1","key":"test","type":"string", "subType": "json"}]
3535
}`
3636

3737
var rawFeatureFlag datafileEntities.FeatureFlag
@@ -57,7 +57,7 @@ func TestMapFeatures(t *testing.T) {
5757
ID: "1",
5858
DefaultValue: "1",
5959
Key: "test",
60-
Type: "integer",
60+
Type: "json",
6161
}
6262
expectedFeatureMap := map[string]entities.Feature{
6363
"test_feature_21111": entities.Feature{

0 commit comments

Comments
 (0)