You've already forked immich
mirror of
https://github.com/immich-app/immich.git
synced 2025-08-08 23:07:06 +02:00
feat(server,web): migrate oauth settings from env to system config (#1061)
This commit is contained in:
@ -10,36 +10,42 @@
|
||||
|
||||
part of openapi.api;
|
||||
|
||||
class SystemConfigResponseDto {
|
||||
/// Returns a new [SystemConfigResponseDto] instance.
|
||||
SystemConfigResponseDto({
|
||||
this.config = const [],
|
||||
class SystemConfigDto {
|
||||
/// Returns a new [SystemConfigDto] instance.
|
||||
SystemConfigDto({
|
||||
required this.ffmpeg,
|
||||
required this.oauth,
|
||||
});
|
||||
|
||||
List<SystemConfigResponseItem> config;
|
||||
SystemConfigFFmpegDto ffmpeg;
|
||||
|
||||
SystemConfigOAuthDto oauth;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) => identical(this, other) || other is SystemConfigResponseDto &&
|
||||
other.config == config;
|
||||
bool operator ==(Object other) => identical(this, other) || other is SystemConfigDto &&
|
||||
other.ffmpeg == ffmpeg &&
|
||||
other.oauth == oauth;
|
||||
|
||||
@override
|
||||
int get hashCode =>
|
||||
// ignore: unnecessary_parenthesis
|
||||
(config.hashCode);
|
||||
(ffmpeg.hashCode) +
|
||||
(oauth.hashCode);
|
||||
|
||||
@override
|
||||
String toString() => 'SystemConfigResponseDto[config=$config]';
|
||||
String toString() => 'SystemConfigDto[ffmpeg=$ffmpeg, oauth=$oauth]';
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final _json = <String, dynamic>{};
|
||||
_json[r'config'] = config;
|
||||
_json[r'ffmpeg'] = ffmpeg;
|
||||
_json[r'oauth'] = oauth;
|
||||
return _json;
|
||||
}
|
||||
|
||||
/// Returns a new [SystemConfigResponseDto] instance and imports its values from
|
||||
/// Returns a new [SystemConfigDto] instance and imports its values from
|
||||
/// [value] if it's a [Map], null otherwise.
|
||||
// ignore: prefer_constructors_over_static_methods
|
||||
static SystemConfigResponseDto? fromJson(dynamic value) {
|
||||
static SystemConfigDto? fromJson(dynamic value) {
|
||||
if (value is Map) {
|
||||
final json = value.cast<String, dynamic>();
|
||||
|
||||
@ -48,24 +54,25 @@ class SystemConfigResponseDto {
|
||||
// Note 2: this code is stripped in release mode!
|
||||
assert(() {
|
||||
requiredKeys.forEach((key) {
|
||||
assert(json.containsKey(key), 'Required key "SystemConfigResponseDto[$key]" is missing from JSON.');
|
||||
assert(json[key] != null, 'Required key "SystemConfigResponseDto[$key]" has a null value in JSON.');
|
||||
assert(json.containsKey(key), 'Required key "SystemConfigDto[$key]" is missing from JSON.');
|
||||
assert(json[key] != null, 'Required key "SystemConfigDto[$key]" has a null value in JSON.');
|
||||
});
|
||||
return true;
|
||||
}());
|
||||
|
||||
return SystemConfigResponseDto(
|
||||
config: SystemConfigResponseItem.listFromJson(json[r'config'])!,
|
||||
return SystemConfigDto(
|
||||
ffmpeg: SystemConfigFFmpegDto.fromJson(json[r'ffmpeg'])!,
|
||||
oauth: SystemConfigOAuthDto.fromJson(json[r'oauth'])!,
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static List<SystemConfigResponseDto>? listFromJson(dynamic json, {bool growable = false,}) {
|
||||
final result = <SystemConfigResponseDto>[];
|
||||
static List<SystemConfigDto>? listFromJson(dynamic json, {bool growable = false,}) {
|
||||
final result = <SystemConfigDto>[];
|
||||
if (json is List && json.isNotEmpty) {
|
||||
for (final row in json) {
|
||||
final value = SystemConfigResponseDto.fromJson(row);
|
||||
final value = SystemConfigDto.fromJson(row);
|
||||
if (value != null) {
|
||||
result.add(value);
|
||||
}
|
||||
@ -74,12 +81,12 @@ class SystemConfigResponseDto {
|
||||
return result.toList(growable: growable);
|
||||
}
|
||||
|
||||
static Map<String, SystemConfigResponseDto> mapFromJson(dynamic json) {
|
||||
final map = <String, SystemConfigResponseDto>{};
|
||||
static Map<String, SystemConfigDto> mapFromJson(dynamic json) {
|
||||
final map = <String, SystemConfigDto>{};
|
||||
if (json is Map && json.isNotEmpty) {
|
||||
json = json.cast<String, dynamic>(); // ignore: parameter_assignments
|
||||
for (final entry in json.entries) {
|
||||
final value = SystemConfigResponseDto.fromJson(entry.value);
|
||||
final value = SystemConfigDto.fromJson(entry.value);
|
||||
if (value != null) {
|
||||
map[entry.key] = value;
|
||||
}
|
||||
@ -88,13 +95,13 @@ class SystemConfigResponseDto {
|
||||
return map;
|
||||
}
|
||||
|
||||
// maps a json object with a list of SystemConfigResponseDto-objects as value to a dart map
|
||||
static Map<String, List<SystemConfigResponseDto>> mapListFromJson(dynamic json, {bool growable = false,}) {
|
||||
final map = <String, List<SystemConfigResponseDto>>{};
|
||||
// maps a json object with a list of SystemConfigDto-objects as value to a dart map
|
||||
static Map<String, List<SystemConfigDto>> mapListFromJson(dynamic json, {bool growable = false,}) {
|
||||
final map = <String, List<SystemConfigDto>>{};
|
||||
if (json is Map && json.isNotEmpty) {
|
||||
json = json.cast<String, dynamic>(); // ignore: parameter_assignments
|
||||
for (final entry in json.entries) {
|
||||
final value = SystemConfigResponseDto.listFromJson(entry.value, growable: growable,);
|
||||
final value = SystemConfigDto.listFromJson(entry.value, growable: growable,);
|
||||
if (value != null) {
|
||||
map[entry.key] = value;
|
||||
}
|
||||
@ -105,7 +112,8 @@ class SystemConfigResponseDto {
|
||||
|
||||
/// The list of required keys that must be present in a JSON.
|
||||
static const requiredKeys = <String>{
|
||||
'config',
|
||||
'ffmpeg',
|
||||
'oauth',
|
||||
};
|
||||
}
|
||||
|
143
mobile/openapi/lib/model/system_config_f_fmpeg_dto.dart
generated
Normal file
143
mobile/openapi/lib/model/system_config_f_fmpeg_dto.dart
generated
Normal file
@ -0,0 +1,143 @@
|
||||
//
|
||||
// AUTO-GENERATED FILE, DO NOT MODIFY!
|
||||
//
|
||||
// @dart=2.12
|
||||
|
||||
// ignore_for_file: unused_element, unused_import
|
||||
// ignore_for_file: always_put_required_named_parameters_first
|
||||
// ignore_for_file: constant_identifier_names
|
||||
// ignore_for_file: lines_longer_than_80_chars
|
||||
|
||||
part of openapi.api;
|
||||
|
||||
class SystemConfigFFmpegDto {
|
||||
/// Returns a new [SystemConfigFFmpegDto] instance.
|
||||
SystemConfigFFmpegDto({
|
||||
required this.crf,
|
||||
required this.preset,
|
||||
required this.targetVideoCodec,
|
||||
required this.targetAudioCodec,
|
||||
required this.targetScaling,
|
||||
});
|
||||
|
||||
String crf;
|
||||
|
||||
String preset;
|
||||
|
||||
String targetVideoCodec;
|
||||
|
||||
String targetAudioCodec;
|
||||
|
||||
String targetScaling;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) => identical(this, other) || other is SystemConfigFFmpegDto &&
|
||||
other.crf == crf &&
|
||||
other.preset == preset &&
|
||||
other.targetVideoCodec == targetVideoCodec &&
|
||||
other.targetAudioCodec == targetAudioCodec &&
|
||||
other.targetScaling == targetScaling;
|
||||
|
||||
@override
|
||||
int get hashCode =>
|
||||
// ignore: unnecessary_parenthesis
|
||||
(crf.hashCode) +
|
||||
(preset.hashCode) +
|
||||
(targetVideoCodec.hashCode) +
|
||||
(targetAudioCodec.hashCode) +
|
||||
(targetScaling.hashCode);
|
||||
|
||||
@override
|
||||
String toString() => 'SystemConfigFFmpegDto[crf=$crf, preset=$preset, targetVideoCodec=$targetVideoCodec, targetAudioCodec=$targetAudioCodec, targetScaling=$targetScaling]';
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final _json = <String, dynamic>{};
|
||||
_json[r'crf'] = crf;
|
||||
_json[r'preset'] = preset;
|
||||
_json[r'targetVideoCodec'] = targetVideoCodec;
|
||||
_json[r'targetAudioCodec'] = targetAudioCodec;
|
||||
_json[r'targetScaling'] = targetScaling;
|
||||
return _json;
|
||||
}
|
||||
|
||||
/// Returns a new [SystemConfigFFmpegDto] instance and imports its values from
|
||||
/// [value] if it's a [Map], null otherwise.
|
||||
// ignore: prefer_constructors_over_static_methods
|
||||
static SystemConfigFFmpegDto? fromJson(dynamic value) {
|
||||
if (value is Map) {
|
||||
final json = value.cast<String, dynamic>();
|
||||
|
||||
// Ensure that the map contains the required keys.
|
||||
// Note 1: the values aren't checked for validity beyond being non-null.
|
||||
// Note 2: this code is stripped in release mode!
|
||||
assert(() {
|
||||
requiredKeys.forEach((key) {
|
||||
assert(json.containsKey(key), 'Required key "SystemConfigFFmpegDto[$key]" is missing from JSON.');
|
||||
assert(json[key] != null, 'Required key "SystemConfigFFmpegDto[$key]" has a null value in JSON.');
|
||||
});
|
||||
return true;
|
||||
}());
|
||||
|
||||
return SystemConfigFFmpegDto(
|
||||
crf: mapValueOfType<String>(json, r'crf')!,
|
||||
preset: mapValueOfType<String>(json, r'preset')!,
|
||||
targetVideoCodec: mapValueOfType<String>(json, r'targetVideoCodec')!,
|
||||
targetAudioCodec: mapValueOfType<String>(json, r'targetAudioCodec')!,
|
||||
targetScaling: mapValueOfType<String>(json, r'targetScaling')!,
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static List<SystemConfigFFmpegDto>? listFromJson(dynamic json, {bool growable = false,}) {
|
||||
final result = <SystemConfigFFmpegDto>[];
|
||||
if (json is List && json.isNotEmpty) {
|
||||
for (final row in json) {
|
||||
final value = SystemConfigFFmpegDto.fromJson(row);
|
||||
if (value != null) {
|
||||
result.add(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result.toList(growable: growable);
|
||||
}
|
||||
|
||||
static Map<String, SystemConfigFFmpegDto> mapFromJson(dynamic json) {
|
||||
final map = <String, SystemConfigFFmpegDto>{};
|
||||
if (json is Map && json.isNotEmpty) {
|
||||
json = json.cast<String, dynamic>(); // ignore: parameter_assignments
|
||||
for (final entry in json.entries) {
|
||||
final value = SystemConfigFFmpegDto.fromJson(entry.value);
|
||||
if (value != null) {
|
||||
map[entry.key] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
// maps a json object with a list of SystemConfigFFmpegDto-objects as value to a dart map
|
||||
static Map<String, List<SystemConfigFFmpegDto>> mapListFromJson(dynamic json, {bool growable = false,}) {
|
||||
final map = <String, List<SystemConfigFFmpegDto>>{};
|
||||
if (json is Map && json.isNotEmpty) {
|
||||
json = json.cast<String, dynamic>(); // ignore: parameter_assignments
|
||||
for (final entry in json.entries) {
|
||||
final value = SystemConfigFFmpegDto.listFromJson(entry.value, growable: growable,);
|
||||
if (value != null) {
|
||||
map[entry.key] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
/// The list of required keys that must be present in a JSON.
|
||||
static const requiredKeys = <String>{
|
||||
'crf',
|
||||
'preset',
|
||||
'targetVideoCodec',
|
||||
'targetAudioCodec',
|
||||
'targetScaling',
|
||||
};
|
||||
}
|
||||
|
94
mobile/openapi/lib/model/system_config_key.dart
generated
94
mobile/openapi/lib/model/system_config_key.dart
generated
@ -1,94 +0,0 @@
|
||||
//
|
||||
// AUTO-GENERATED FILE, DO NOT MODIFY!
|
||||
//
|
||||
// @dart=2.12
|
||||
|
||||
// ignore_for_file: unused_element, unused_import
|
||||
// ignore_for_file: always_put_required_named_parameters_first
|
||||
// ignore_for_file: constant_identifier_names
|
||||
// ignore_for_file: lines_longer_than_80_chars
|
||||
|
||||
part of openapi.api;
|
||||
|
||||
|
||||
class SystemConfigKey {
|
||||
/// Instantiate a new enum with the provided [value].
|
||||
const SystemConfigKey._(this.value);
|
||||
|
||||
/// The underlying value of this enum member.
|
||||
final String value;
|
||||
|
||||
@override
|
||||
String toString() => value;
|
||||
|
||||
String toJson() => value;
|
||||
|
||||
static const crf = SystemConfigKey._(r'ffmpeg_crf');
|
||||
static const preset = SystemConfigKey._(r'ffmpeg_preset');
|
||||
static const targetVideoCodec = SystemConfigKey._(r'ffmpeg_target_video_codec');
|
||||
static const targetAudioCodec = SystemConfigKey._(r'ffmpeg_target_audio_codec');
|
||||
static const targetScaling = SystemConfigKey._(r'ffmpeg_target_scaling');
|
||||
|
||||
/// List of all possible values in this [enum][SystemConfigKey].
|
||||
static const values = <SystemConfigKey>[
|
||||
crf,
|
||||
preset,
|
||||
targetVideoCodec,
|
||||
targetAudioCodec,
|
||||
targetScaling,
|
||||
];
|
||||
|
||||
static SystemConfigKey? fromJson(dynamic value) => SystemConfigKeyTypeTransformer().decode(value);
|
||||
|
||||
static List<SystemConfigKey>? listFromJson(dynamic json, {bool growable = false,}) {
|
||||
final result = <SystemConfigKey>[];
|
||||
if (json is List && json.isNotEmpty) {
|
||||
for (final row in json) {
|
||||
final value = SystemConfigKey.fromJson(row);
|
||||
if (value != null) {
|
||||
result.add(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result.toList(growable: growable);
|
||||
}
|
||||
}
|
||||
|
||||
/// Transformation class that can [encode] an instance of [SystemConfigKey] to String,
|
||||
/// and [decode] dynamic data back to [SystemConfigKey].
|
||||
class SystemConfigKeyTypeTransformer {
|
||||
factory SystemConfigKeyTypeTransformer() => _instance ??= const SystemConfigKeyTypeTransformer._();
|
||||
|
||||
const SystemConfigKeyTypeTransformer._();
|
||||
|
||||
String encode(SystemConfigKey data) => data.value;
|
||||
|
||||
/// Decodes a [dynamic value][data] to a SystemConfigKey.
|
||||
///
|
||||
/// If [allowNull] is true and the [dynamic value][data] cannot be decoded successfully,
|
||||
/// then null is returned. However, if [allowNull] is false and the [dynamic value][data]
|
||||
/// cannot be decoded successfully, then an [UnimplementedError] is thrown.
|
||||
///
|
||||
/// The [allowNull] is very handy when an API changes and a new enum value is added or removed,
|
||||
/// and users are still using an old app with the old code.
|
||||
SystemConfigKey? decode(dynamic data, {bool allowNull = true}) {
|
||||
if (data != null) {
|
||||
switch (data.toString()) {
|
||||
case r'ffmpeg_crf': return SystemConfigKey.crf;
|
||||
case r'ffmpeg_preset': return SystemConfigKey.preset;
|
||||
case r'ffmpeg_target_video_codec': return SystemConfigKey.targetVideoCodec;
|
||||
case r'ffmpeg_target_audio_codec': return SystemConfigKey.targetAudioCodec;
|
||||
case r'ffmpeg_target_scaling': return SystemConfigKey.targetScaling;
|
||||
default:
|
||||
if (!allowNull) {
|
||||
throw ArgumentError('Unknown enum value to decode: $data');
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// Singleton [SystemConfigKeyTypeTransformer] instance.
|
||||
static SystemConfigKeyTypeTransformer? _instance;
|
||||
}
|
||||
|
159
mobile/openapi/lib/model/system_config_o_auth_dto.dart
generated
Normal file
159
mobile/openapi/lib/model/system_config_o_auth_dto.dart
generated
Normal file
@ -0,0 +1,159 @@
|
||||
//
|
||||
// AUTO-GENERATED FILE, DO NOT MODIFY!
|
||||
//
|
||||
// @dart=2.12
|
||||
|
||||
// ignore_for_file: unused_element, unused_import
|
||||
// ignore_for_file: always_put_required_named_parameters_first
|
||||
// ignore_for_file: constant_identifier_names
|
||||
// ignore_for_file: lines_longer_than_80_chars
|
||||
|
||||
part of openapi.api;
|
||||
|
||||
class SystemConfigOAuthDto {
|
||||
/// Returns a new [SystemConfigOAuthDto] instance.
|
||||
SystemConfigOAuthDto({
|
||||
required this.enabled,
|
||||
required this.issuerUrl,
|
||||
required this.clientId,
|
||||
required this.clientSecret,
|
||||
required this.scope,
|
||||
required this.buttonText,
|
||||
required this.autoRegister,
|
||||
});
|
||||
|
||||
bool enabled;
|
||||
|
||||
String issuerUrl;
|
||||
|
||||
String clientId;
|
||||
|
||||
String clientSecret;
|
||||
|
||||
String scope;
|
||||
|
||||
String buttonText;
|
||||
|
||||
bool autoRegister;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) => identical(this, other) || other is SystemConfigOAuthDto &&
|
||||
other.enabled == enabled &&
|
||||
other.issuerUrl == issuerUrl &&
|
||||
other.clientId == clientId &&
|
||||
other.clientSecret == clientSecret &&
|
||||
other.scope == scope &&
|
||||
other.buttonText == buttonText &&
|
||||
other.autoRegister == autoRegister;
|
||||
|
||||
@override
|
||||
int get hashCode =>
|
||||
// ignore: unnecessary_parenthesis
|
||||
(enabled.hashCode) +
|
||||
(issuerUrl.hashCode) +
|
||||
(clientId.hashCode) +
|
||||
(clientSecret.hashCode) +
|
||||
(scope.hashCode) +
|
||||
(buttonText.hashCode) +
|
||||
(autoRegister.hashCode);
|
||||
|
||||
@override
|
||||
String toString() => 'SystemConfigOAuthDto[enabled=$enabled, issuerUrl=$issuerUrl, clientId=$clientId, clientSecret=$clientSecret, scope=$scope, buttonText=$buttonText, autoRegister=$autoRegister]';
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final _json = <String, dynamic>{};
|
||||
_json[r'enabled'] = enabled;
|
||||
_json[r'issuerUrl'] = issuerUrl;
|
||||
_json[r'clientId'] = clientId;
|
||||
_json[r'clientSecret'] = clientSecret;
|
||||
_json[r'scope'] = scope;
|
||||
_json[r'buttonText'] = buttonText;
|
||||
_json[r'autoRegister'] = autoRegister;
|
||||
return _json;
|
||||
}
|
||||
|
||||
/// Returns a new [SystemConfigOAuthDto] instance and imports its values from
|
||||
/// [value] if it's a [Map], null otherwise.
|
||||
// ignore: prefer_constructors_over_static_methods
|
||||
static SystemConfigOAuthDto? fromJson(dynamic value) {
|
||||
if (value is Map) {
|
||||
final json = value.cast<String, dynamic>();
|
||||
|
||||
// Ensure that the map contains the required keys.
|
||||
// Note 1: the values aren't checked for validity beyond being non-null.
|
||||
// Note 2: this code is stripped in release mode!
|
||||
assert(() {
|
||||
requiredKeys.forEach((key) {
|
||||
assert(json.containsKey(key), 'Required key "SystemConfigOAuthDto[$key]" is missing from JSON.');
|
||||
assert(json[key] != null, 'Required key "SystemConfigOAuthDto[$key]" has a null value in JSON.');
|
||||
});
|
||||
return true;
|
||||
}());
|
||||
|
||||
return SystemConfigOAuthDto(
|
||||
enabled: mapValueOfType<bool>(json, r'enabled')!,
|
||||
issuerUrl: mapValueOfType<String>(json, r'issuerUrl')!,
|
||||
clientId: mapValueOfType<String>(json, r'clientId')!,
|
||||
clientSecret: mapValueOfType<String>(json, r'clientSecret')!,
|
||||
scope: mapValueOfType<String>(json, r'scope')!,
|
||||
buttonText: mapValueOfType<String>(json, r'buttonText')!,
|
||||
autoRegister: mapValueOfType<bool>(json, r'autoRegister')!,
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static List<SystemConfigOAuthDto>? listFromJson(dynamic json, {bool growable = false,}) {
|
||||
final result = <SystemConfigOAuthDto>[];
|
||||
if (json is List && json.isNotEmpty) {
|
||||
for (final row in json) {
|
||||
final value = SystemConfigOAuthDto.fromJson(row);
|
||||
if (value != null) {
|
||||
result.add(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result.toList(growable: growable);
|
||||
}
|
||||
|
||||
static Map<String, SystemConfigOAuthDto> mapFromJson(dynamic json) {
|
||||
final map = <String, SystemConfigOAuthDto>{};
|
||||
if (json is Map && json.isNotEmpty) {
|
||||
json = json.cast<String, dynamic>(); // ignore: parameter_assignments
|
||||
for (final entry in json.entries) {
|
||||
final value = SystemConfigOAuthDto.fromJson(entry.value);
|
||||
if (value != null) {
|
||||
map[entry.key] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
// maps a json object with a list of SystemConfigOAuthDto-objects as value to a dart map
|
||||
static Map<String, List<SystemConfigOAuthDto>> mapListFromJson(dynamic json, {bool growable = false,}) {
|
||||
final map = <String, List<SystemConfigOAuthDto>>{};
|
||||
if (json is Map && json.isNotEmpty) {
|
||||
json = json.cast<String, dynamic>(); // ignore: parameter_assignments
|
||||
for (final entry in json.entries) {
|
||||
final value = SystemConfigOAuthDto.listFromJson(entry.value, growable: growable,);
|
||||
if (value != null) {
|
||||
map[entry.key] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
/// The list of required keys that must be present in a JSON.
|
||||
static const requiredKeys = <String>{
|
||||
'enabled',
|
||||
'issuerUrl',
|
||||
'clientId',
|
||||
'clientSecret',
|
||||
'scope',
|
||||
'buttonText',
|
||||
'autoRegister',
|
||||
};
|
||||
}
|
||||
|
@ -1,135 +0,0 @@
|
||||
//
|
||||
// AUTO-GENERATED FILE, DO NOT MODIFY!
|
||||
//
|
||||
// @dart=2.12
|
||||
|
||||
// ignore_for_file: unused_element, unused_import
|
||||
// ignore_for_file: always_put_required_named_parameters_first
|
||||
// ignore_for_file: constant_identifier_names
|
||||
// ignore_for_file: lines_longer_than_80_chars
|
||||
|
||||
part of openapi.api;
|
||||
|
||||
class SystemConfigResponseItem {
|
||||
/// Returns a new [SystemConfigResponseItem] instance.
|
||||
SystemConfigResponseItem({
|
||||
required this.name,
|
||||
required this.key,
|
||||
required this.value,
|
||||
required this.defaultValue,
|
||||
});
|
||||
|
||||
String name;
|
||||
|
||||
SystemConfigKey key;
|
||||
|
||||
String value;
|
||||
|
||||
String defaultValue;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) => identical(this, other) || other is SystemConfigResponseItem &&
|
||||
other.name == name &&
|
||||
other.key == key &&
|
||||
other.value == value &&
|
||||
other.defaultValue == defaultValue;
|
||||
|
||||
@override
|
||||
int get hashCode =>
|
||||
// ignore: unnecessary_parenthesis
|
||||
(name.hashCode) +
|
||||
(key.hashCode) +
|
||||
(value.hashCode) +
|
||||
(defaultValue.hashCode);
|
||||
|
||||
@override
|
||||
String toString() => 'SystemConfigResponseItem[name=$name, key=$key, value=$value, defaultValue=$defaultValue]';
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final _json = <String, dynamic>{};
|
||||
_json[r'name'] = name;
|
||||
_json[r'key'] = key;
|
||||
_json[r'value'] = value;
|
||||
_json[r'defaultValue'] = defaultValue;
|
||||
return _json;
|
||||
}
|
||||
|
||||
/// Returns a new [SystemConfigResponseItem] instance and imports its values from
|
||||
/// [value] if it's a [Map], null otherwise.
|
||||
// ignore: prefer_constructors_over_static_methods
|
||||
static SystemConfigResponseItem? fromJson(dynamic value) {
|
||||
if (value is Map) {
|
||||
final json = value.cast<String, dynamic>();
|
||||
|
||||
// Ensure that the map contains the required keys.
|
||||
// Note 1: the values aren't checked for validity beyond being non-null.
|
||||
// Note 2: this code is stripped in release mode!
|
||||
assert(() {
|
||||
requiredKeys.forEach((key) {
|
||||
assert(json.containsKey(key), 'Required key "SystemConfigResponseItem[$key]" is missing from JSON.');
|
||||
assert(json[key] != null, 'Required key "SystemConfigResponseItem[$key]" has a null value in JSON.');
|
||||
});
|
||||
return true;
|
||||
}());
|
||||
|
||||
return SystemConfigResponseItem(
|
||||
name: mapValueOfType<String>(json, r'name')!,
|
||||
key: SystemConfigKey.fromJson(json[r'key'])!,
|
||||
value: mapValueOfType<String>(json, r'value')!,
|
||||
defaultValue: mapValueOfType<String>(json, r'defaultValue')!,
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static List<SystemConfigResponseItem>? listFromJson(dynamic json, {bool growable = false,}) {
|
||||
final result = <SystemConfigResponseItem>[];
|
||||
if (json is List && json.isNotEmpty) {
|
||||
for (final row in json) {
|
||||
final value = SystemConfigResponseItem.fromJson(row);
|
||||
if (value != null) {
|
||||
result.add(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result.toList(growable: growable);
|
||||
}
|
||||
|
||||
static Map<String, SystemConfigResponseItem> mapFromJson(dynamic json) {
|
||||
final map = <String, SystemConfigResponseItem>{};
|
||||
if (json is Map && json.isNotEmpty) {
|
||||
json = json.cast<String, dynamic>(); // ignore: parameter_assignments
|
||||
for (final entry in json.entries) {
|
||||
final value = SystemConfigResponseItem.fromJson(entry.value);
|
||||
if (value != null) {
|
||||
map[entry.key] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
// maps a json object with a list of SystemConfigResponseItem-objects as value to a dart map
|
||||
static Map<String, List<SystemConfigResponseItem>> mapListFromJson(dynamic json, {bool growable = false,}) {
|
||||
final map = <String, List<SystemConfigResponseItem>>{};
|
||||
if (json is Map && json.isNotEmpty) {
|
||||
json = json.cast<String, dynamic>(); // ignore: parameter_assignments
|
||||
for (final entry in json.entries) {
|
||||
final value = SystemConfigResponseItem.listFromJson(entry.value, growable: growable,);
|
||||
if (value != null) {
|
||||
map[entry.key] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
/// The list of required keys that must be present in a JSON.
|
||||
static const requiredKeys = <String>{
|
||||
'name',
|
||||
'key',
|
||||
'value',
|
||||
'defaultValue',
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user