refactor: better typings for integrity API

This commit is contained in:
izzy
2025-11-24 14:53:52 +00:00
parent f84bdc14d5
commit e2ca0c6f67
12 changed files with 334 additions and 73 deletions

View File

@@ -13,32 +13,26 @@ part of openapi.api;
class MaintenanceIntegrityResponseDto {
/// Returns a new [MaintenanceIntegrityResponseDto] instance.
MaintenanceIntegrityResponseDto({
required this.storageHeuristics,
required this.storageIntegrity,
this.storage = const [],
});
Object storageHeuristics;
Object storageIntegrity;
List<MaintenanceStorageFolderIntegrityDto> storage;
@override
bool operator ==(Object other) => identical(this, other) || other is MaintenanceIntegrityResponseDto &&
other.storageHeuristics == storageHeuristics &&
other.storageIntegrity == storageIntegrity;
_deepEquality.equals(other.storage, storage);
@override
int get hashCode =>
// ignore: unnecessary_parenthesis
(storageHeuristics.hashCode) +
(storageIntegrity.hashCode);
(storage.hashCode);
@override
String toString() => 'MaintenanceIntegrityResponseDto[storageHeuristics=$storageHeuristics, storageIntegrity=$storageIntegrity]';
String toString() => 'MaintenanceIntegrityResponseDto[storage=$storage]';
Map<String, dynamic> toJson() {
final json = <String, dynamic>{};
json[r'storageHeuristics'] = this.storageHeuristics;
json[r'storageIntegrity'] = this.storageIntegrity;
json[r'storage'] = this.storage;
return json;
}
@@ -51,8 +45,7 @@ class MaintenanceIntegrityResponseDto {
final json = value.cast<String, dynamic>();
return MaintenanceIntegrityResponseDto(
storageHeuristics: mapValueOfType<Object>(json, r'storageHeuristics')!,
storageIntegrity: mapValueOfType<Object>(json, r'storageIntegrity')!,
storage: MaintenanceStorageFolderIntegrityDto.listFromJson(json[r'storage']),
);
}
return null;
@@ -100,8 +93,7 @@ class MaintenanceIntegrityResponseDto {
/// The list of required keys that must be present in a JSON.
static const requiredKeys = <String>{
'storageHeuristics',
'storageIntegrity',
'storage',
};
}

View File

@@ -0,0 +1,123 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
// @dart=2.18
// 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 MaintenanceStorageFolderIntegrityDto {
/// Returns a new [MaintenanceStorageFolderIntegrityDto] instance.
MaintenanceStorageFolderIntegrityDto({
required this.files,
required this.folder,
required this.readable,
required this.writable,
});
num files;
StorageFolder folder;
bool readable;
bool writable;
@override
bool operator ==(Object other) => identical(this, other) || other is MaintenanceStorageFolderIntegrityDto &&
other.files == files &&
other.folder == folder &&
other.readable == readable &&
other.writable == writable;
@override
int get hashCode =>
// ignore: unnecessary_parenthesis
(files.hashCode) +
(folder.hashCode) +
(readable.hashCode) +
(writable.hashCode);
@override
String toString() => 'MaintenanceStorageFolderIntegrityDto[files=$files, folder=$folder, readable=$readable, writable=$writable]';
Map<String, dynamic> toJson() {
final json = <String, dynamic>{};
json[r'files'] = this.files;
json[r'folder'] = this.folder;
json[r'readable'] = this.readable;
json[r'writable'] = this.writable;
return json;
}
/// Returns a new [MaintenanceStorageFolderIntegrityDto] instance and imports its values from
/// [value] if it's a [Map], null otherwise.
// ignore: prefer_constructors_over_static_methods
static MaintenanceStorageFolderIntegrityDto? fromJson(dynamic value) {
upgradeDto(value, "MaintenanceStorageFolderIntegrityDto");
if (value is Map) {
final json = value.cast<String, dynamic>();
return MaintenanceStorageFolderIntegrityDto(
files: num.parse('${json[r'files']}'),
folder: StorageFolder.fromJson(json[r'folder'])!,
readable: mapValueOfType<bool>(json, r'readable')!,
writable: mapValueOfType<bool>(json, r'writable')!,
);
}
return null;
}
static List<MaintenanceStorageFolderIntegrityDto> listFromJson(dynamic json, {bool growable = false,}) {
final result = <MaintenanceStorageFolderIntegrityDto>[];
if (json is List && json.isNotEmpty) {
for (final row in json) {
final value = MaintenanceStorageFolderIntegrityDto.fromJson(row);
if (value != null) {
result.add(value);
}
}
}
return result.toList(growable: growable);
}
static Map<String, MaintenanceStorageFolderIntegrityDto> mapFromJson(dynamic json) {
final map = <String, MaintenanceStorageFolderIntegrityDto>{};
if (json is Map && json.isNotEmpty) {
json = json.cast<String, dynamic>(); // ignore: parameter_assignments
for (final entry in json.entries) {
final value = MaintenanceStorageFolderIntegrityDto.fromJson(entry.value);
if (value != null) {
map[entry.key] = value;
}
}
}
return map;
}
// maps a json object with a list of MaintenanceStorageFolderIntegrityDto-objects as value to a dart map
static Map<String, List<MaintenanceStorageFolderIntegrityDto>> mapListFromJson(dynamic json, {bool growable = false,}) {
final map = <String, List<MaintenanceStorageFolderIntegrityDto>>{};
if (json is Map && json.isNotEmpty) {
// ignore: parameter_assignments
json = json.cast<String, dynamic>();
for (final entry in json.entries) {
map[entry.key] = MaintenanceStorageFolderIntegrityDto.listFromJson(entry.value, growable: growable,);
}
}
return map;
}
/// The list of required keys that must be present in a JSON.
static const requiredKeys = <String>{
'files',
'folder',
'readable',
'writable',
};
}

View File

@@ -0,0 +1,97 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
// @dart=2.18
// 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 StorageFolder {
/// Instantiate a new enum with the provided [value].
const StorageFolder._(this.value);
/// The underlying value of this enum member.
final String value;
@override
String toString() => value;
String toJson() => value;
static const encodedVideo = StorageFolder._(r'encoded-video');
static const library_ = StorageFolder._(r'library');
static const upload = StorageFolder._(r'upload');
static const profile = StorageFolder._(r'profile');
static const thumbs = StorageFolder._(r'thumbs');
static const backups = StorageFolder._(r'backups');
/// List of all possible values in this [enum][StorageFolder].
static const values = <StorageFolder>[
encodedVideo,
library_,
upload,
profile,
thumbs,
backups,
];
static StorageFolder? fromJson(dynamic value) => StorageFolderTypeTransformer().decode(value);
static List<StorageFolder> listFromJson(dynamic json, {bool growable = false,}) {
final result = <StorageFolder>[];
if (json is List && json.isNotEmpty) {
for (final row in json) {
final value = StorageFolder.fromJson(row);
if (value != null) {
result.add(value);
}
}
}
return result.toList(growable: growable);
}
}
/// Transformation class that can [encode] an instance of [StorageFolder] to String,
/// and [decode] dynamic data back to [StorageFolder].
class StorageFolderTypeTransformer {
factory StorageFolderTypeTransformer() => _instance ??= const StorageFolderTypeTransformer._();
const StorageFolderTypeTransformer._();
String encode(StorageFolder data) => data.value;
/// Decodes a [dynamic value][data] to a StorageFolder.
///
/// 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.
StorageFolder? decode(dynamic data, {bool allowNull = true}) {
if (data != null) {
switch (data) {
case r'encoded-video': return StorageFolder.encodedVideo;
case r'library': return StorageFolder.library_;
case r'upload': return StorageFolder.upload;
case r'profile': return StorageFolder.profile;
case r'thumbs': return StorageFolder.thumbs;
case r'backups': return StorageFolder.backups;
default:
if (!allowNull) {
throw ArgumentError('Unknown enum value to decode: $data');
}
}
}
return null;
}
/// Singleton [StorageFolderTypeTransformer] instance.
static StorageFolderTypeTransformer? _instance;
}