-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathfeatures.dart
96 lines (83 loc) · 2.44 KB
/
features.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/// See https://unleash.github.io/docs/api/client/features
class Features {
Features({this.version, this.features});
factory Features.fromJson(Map<String, dynamic> json) {
var features = <FeatureToggle>[];
if (json['features'] != null) {
json['features'].forEach((dynamic v) {
features.add(FeatureToggle.fromJson(v as Map<String, dynamic>));
});
}
return Features(
version: json['version'] as int?,
features: features,
);
}
final int? version;
final List<FeatureToggle>? features;
Map<String, dynamic> toJson() {
return <String, dynamic>{
if (version != null) 'version': version,
if (features?.isNotEmpty ?? false)
'features': features?.map((e) => e.toJson()).toList(),
};
}
}
class FeatureToggle {
FeatureToggle({
this.name,
this.description,
this.enabled,
this.strategies,
this.strategy,
});
factory FeatureToggle.fromJson(Map<String, dynamic> json) {
var strategies = <Strategy>[];
if (json['strategies'] != null) {
json['strategies'].forEach((dynamic v) {
strategies.add(Strategy.fromJson(v as Map<String, dynamic>));
});
}
return FeatureToggle(
name: json['name'] as String?,
description: json['description'] as String?,
enabled: json['enabled'] as bool?,
strategies: strategies,
strategy: json['strategy'] as String?,
);
}
final String? name;
final String? description;
final bool? enabled;
final List<Strategy>? strategies;
final String? strategy;
Map<String, dynamic> toJson() {
return <String, dynamic>{
if (name != null) 'name': name,
if (description != null) 'description': description,
if (enabled != null) 'enabled': enabled,
if (strategy != null) 'strategy': strategy,
if (strategies?.isNotEmpty ?? false)
'strategies': strategies?.map((e) => e.toJson()).toList(),
};
}
}
class Strategy {
Strategy({this.name, this.parameters});
factory Strategy.fromJson(Map<String, dynamic> json) {
return Strategy(
name: json['name'] as String?,
parameters: json['parameters'] != null
? json['parameters'] as Map<String, dynamic>?
: null,
);
}
final String? name;
final Map<String, dynamic>? parameters;
Map<String, dynamic> toJson() {
return <String, dynamic>{
if (name != null) 'name': name,
if (parameters?.isNotEmpty ?? true) 'parameters': parameters,
};
}
}