将json解析更改为freezed
parent
7c80f5b5ea
commit
b4f04e5394
@ -1,149 +1,92 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
part 'parse.freezed.dart';
|
||||
part 'parse.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class MWParseCategoryInfo {
|
||||
String sortkey;
|
||||
String category;
|
||||
|
||||
MWParseCategoryInfo({
|
||||
required this.category,
|
||||
this.sortkey = "",
|
||||
});
|
||||
@freezed
|
||||
class MWParseCategoryInfo with _$MWParseCategoryInfo {
|
||||
factory MWParseCategoryInfo({
|
||||
required String category,
|
||||
@Default("") String sortkey,
|
||||
}) = _MWParseCategoryInfo;
|
||||
|
||||
factory MWParseCategoryInfo.fromJson(Map<String, dynamic> json) =>
|
||||
_$MWParseCategoryInfoFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$MWParseCategoryInfoToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class MWParseLangLinkInfo {
|
||||
String lang;
|
||||
String url;
|
||||
String langname;
|
||||
String autonym;
|
||||
String title;
|
||||
|
||||
MWParseLangLinkInfo({
|
||||
required this.lang,
|
||||
this.url = "",
|
||||
this.langname = "",
|
||||
this.autonym = "",
|
||||
required this.title,
|
||||
});
|
||||
@freezed
|
||||
class MWParseLangLinkInfo with _$MWParseLangLinkInfo {
|
||||
factory MWParseLangLinkInfo({
|
||||
required String lang,
|
||||
required String title,
|
||||
@Default("") String url,
|
||||
@Default("") String langname,
|
||||
@Default("") autonym,
|
||||
}) = _MWParseLangLinkInfo;
|
||||
|
||||
factory MWParseLangLinkInfo.fromJson(Map<String, dynamic> json) =>
|
||||
_$MWParseLangLinkInfoFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$MWParseLangLinkInfoToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class MWParsePageLinkInfo {
|
||||
int ns;
|
||||
String title;
|
||||
bool exists;
|
||||
|
||||
MWParsePageLinkInfo({
|
||||
required this.ns,
|
||||
required this.title,
|
||||
this.exists = false,
|
||||
});
|
||||
@freezed
|
||||
class MWParsePageLinkInfo with _$MWParsePageLinkInfo {
|
||||
factory MWParsePageLinkInfo({
|
||||
required int ns,
|
||||
required String title,
|
||||
@Default(false) bool exists,
|
||||
}) = _MWParsePageLinkInfo;
|
||||
|
||||
factory MWParsePageLinkInfo.fromJson(Map<String, dynamic> json) =>
|
||||
_$MWParsePageLinkInfoFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$MWParsePageLinkInfoToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class MWParseSectionInfo {
|
||||
int toclevel;
|
||||
int level;
|
||||
String line;
|
||||
String number;
|
||||
String index;
|
||||
String fromtitle;
|
||||
int? byteoffset;
|
||||
String anchor;
|
||||
|
||||
MWParseSectionInfo({
|
||||
this.toclevel = -1,
|
||||
this.level = -1,
|
||||
this.line = "",
|
||||
this.number = "",
|
||||
this.index = "",
|
||||
this.fromtitle = "",
|
||||
this.byteoffset,
|
||||
this.anchor = "",
|
||||
});
|
||||
@freezed
|
||||
class MWParseSectionInfo with _$MWParseSectionInfo {
|
||||
factory MWParseSectionInfo({
|
||||
required int toclevel,
|
||||
required int level,
|
||||
required String line,
|
||||
@Default("") String number,
|
||||
@Default("") String index,
|
||||
@Default("") String fromtitle,
|
||||
@Default(-1) int byteoffset,
|
||||
@Default("") String anchor,
|
||||
}) = _MWParseSectionInfo;
|
||||
|
||||
factory MWParseSectionInfo.fromJson(Map<String, dynamic> json) =>
|
||||
_$MWParseSectionInfoFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$MWParseSectionInfoToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class MWParseInfo {
|
||||
String title;
|
||||
int pageid;
|
||||
int revid;
|
||||
String text;
|
||||
List<MWParseLangLinkInfo> langlink;
|
||||
List<MWParseCategoryInfo> categories;
|
||||
List<MWParsePageLinkInfo> links;
|
||||
List<MWParsePageLinkInfo> templates;
|
||||
List<String> images;
|
||||
List<String> externallinks;
|
||||
List<MWParseSectionInfo> sections;
|
||||
bool showtoc;
|
||||
String displaytitle;
|
||||
List<String> modules;
|
||||
List<String> modulescripts;
|
||||
List<String> modulestyles;
|
||||
Map<String, dynamic> jsconfigvars;
|
||||
Map<String, dynamic> iwlinks;
|
||||
Map<String, dynamic> properties;
|
||||
|
||||
MWParseInfo({
|
||||
required this.title,
|
||||
required this.pageid,
|
||||
this.revid = -1,
|
||||
this.text = "",
|
||||
this.langlink = const [],
|
||||
this.categories = const [],
|
||||
this.links = const [],
|
||||
this.templates = const [],
|
||||
this.images = const [],
|
||||
this.externallinks = const [],
|
||||
this.sections = const [],
|
||||
this.showtoc = true,
|
||||
this.displaytitle = "",
|
||||
this.modules = const [],
|
||||
this.modulescripts = const [],
|
||||
this.modulestyles = const [],
|
||||
this.jsconfigvars = const {},
|
||||
this.iwlinks = const {},
|
||||
this.properties = const {},
|
||||
});
|
||||
|
||||
factory MWParseInfo.fromJson(Map<String, dynamic> json) =>
|
||||
_$MWParseInfoFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$MWParseInfoToJson(this);
|
||||
@freezed
|
||||
class MWParseInfo with _$MWParseInfo {
|
||||
factory MWParseInfo({
|
||||
required String title,
|
||||
required int pageid,
|
||||
required int revid,
|
||||
required String text,
|
||||
String? displaytitle,
|
||||
@Default([]) List<MWParseLangLinkInfo> langlink,
|
||||
@Default([]) List<MWParseCategoryInfo> categories,
|
||||
@Default([]) List<MWParsePageLinkInfo> links,
|
||||
@Default([]) List<MWParsePageLinkInfo> templates,
|
||||
@Default([]) List<String> images,
|
||||
@Default([]) List<String> externallinks,
|
||||
@Default([]) List<MWParseSectionInfo> sections,
|
||||
@Default(true) bool showtoc,
|
||||
@Default([]) List<String> modules,
|
||||
@Default([]) List<String> modulescripts,
|
||||
@Default([]) List<String> modulestyles,
|
||||
@Default({}) Map<String, dynamic> jsconfigvars,
|
||||
@Default({}) Map<String, dynamic> iwlinks,
|
||||
@Default({}) Map<String, dynamic> properties,
|
||||
}) = _MWParseInfo;
|
||||
|
||||
factory MWParseInfo.fromJson(Map<String, dynamic> json) => _$MWParseInfoFromJson(json);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class MWParseResponse {
|
||||
MWParseInfo parse;
|
||||
|
||||
MWParseResponse({required this.parse});
|
||||
|
||||
factory MWParseResponse.fromJson(Map<String, dynamic> json) =>
|
||||
_$MWParseResponseFromJson(json);
|
||||
@freezed
|
||||
class MWParseResponse with _$MWParseResponse {
|
||||
factory MWParseResponse({required MWParseInfo parse}) = _MWParseResponse;
|
||||
|
||||
Map<String, dynamic> toJson() => _$MWParseResponseToJson(this);
|
||||
factory MWParseResponse.fromJson(Map<String, dynamic> json) => _$MWParseResponseFromJson(json);
|
||||
}
|
||||
|
@ -1,51 +1,32 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
// ignore_for_file: invalid_annotation_target
|
||||
|
||||
part 'recent_changes.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class RecentChangesItem {
|
||||
String? type;
|
||||
|
||||
int ns;
|
||||
|
||||
String title;
|
||||
|
||||
int pageid;
|
||||
|
||||
int revid;
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
@JsonKey(name: 'old_revid')
|
||||
int? oldRevid;
|
||||
|
||||
int? rcid;
|
||||
|
||||
DateTime timestamp;
|
||||
part 'recent_changes.freezed.dart';
|
||||
part 'recent_changes.g.dart';
|
||||
|
||||
RecentChangesItem({
|
||||
this.type,
|
||||
required this.ns,
|
||||
required this.title,
|
||||
required this.pageid,
|
||||
required this.revid,
|
||||
this.oldRevid,
|
||||
this.rcid,
|
||||
required this.timestamp,
|
||||
});
|
||||
@freezed
|
||||
class RecentChangesItem with _$RecentChangesItem {
|
||||
factory RecentChangesItem({
|
||||
String? type,
|
||||
required int ns,
|
||||
required String title,
|
||||
required int pageid,
|
||||
required int revid,
|
||||
required DateTime timestamp,
|
||||
@JsonKey(name: 'old_revid') int? oldRevid,
|
||||
int? rcid,
|
||||
}) = _RecentChangesItem;
|
||||
|
||||
factory RecentChangesItem.fromJson(Map<String, dynamic> json) =>
|
||||
_$RecentChangesItemFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$RecentChangesItemToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class RecentChangesResponse {
|
||||
List<RecentChangesItem> recentchanges;
|
||||
|
||||
RecentChangesResponse({required this.recentchanges});
|
||||
@freezed
|
||||
class RecentChangesResponse with _$RecentChangesResponse {
|
||||
factory RecentChangesResponse({required List<RecentChangesItem> recentchanges}) =
|
||||
_RecentChangesResponse;
|
||||
|
||||
factory RecentChangesResponse.fromJson(Map<String, dynamic> json) =>
|
||||
_$RecentChangesResponseFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$RecentChangesResponseToJson(this);
|
||||
}
|
||||
|
@ -1,101 +1,64 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
// ignore_for_file: invalid_annotation_target
|
||||
|
||||
part 'userinfo.g.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class UserGroupMembership {
|
||||
String group;
|
||||
String expiry;
|
||||
part 'userinfo.freezed.dart';
|
||||
part 'userinfo.g.dart';
|
||||
|
||||
UserGroupMembership({
|
||||
required this.group,
|
||||
required this.expiry,
|
||||
});
|
||||
@freezed
|
||||
class UserGroupMembership with _$UserGroupMembership {
|
||||
factory UserGroupMembership({
|
||||
required String group,
|
||||
required String expiry,
|
||||
}) = _UserGroupMembership;
|
||||
|
||||
factory UserGroupMembership.fromJson(Map<String, dynamic> json) =>
|
||||
_$UserGroupMembershipFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$UserGroupMembershipToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class UserAcceptLang {
|
||||
double q;
|
||||
|
||||
@JsonKey(name: '*')
|
||||
String langCode;
|
||||
|
||||
UserAcceptLang({
|
||||
required this.q,
|
||||
required this.langCode,
|
||||
});
|
||||
|
||||
factory UserAcceptLang.fromJson(Map<String, dynamic> json) =>
|
||||
_$UserAcceptLangFromJson(json);
|
||||
@freezed
|
||||
class UserAcceptLang with _$UserAcceptLang {
|
||||
factory UserAcceptLang({
|
||||
required double q,
|
||||
@JsonKey(name: '*') required String langCode,
|
||||
}) = _UserAcceptLang;
|
||||
|
||||
Map<String, dynamic> toJson() => _$UserAcceptLangToJson(this);
|
||||
factory UserAcceptLang.fromJson(Map<String, dynamic> json) => _$UserAcceptLangFromJson(json);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class MetaUserInfo {
|
||||
int id;
|
||||
String name;
|
||||
List<String>? groups;
|
||||
List<UserGroupMembership>? groupmemberships;
|
||||
List<String>? implicitgroups;
|
||||
List<String>? rights;
|
||||
Map<String, List<String>>? changeablegroups;
|
||||
Map<String, dynamic>? options;
|
||||
int? editcount;
|
||||
String? realname;
|
||||
String? email;
|
||||
DateTime? emailauthenticated;
|
||||
DateTime? registrationdate;
|
||||
List<UserAcceptLang>? acceptlang;
|
||||
int? unreadcount;
|
||||
Map<String, int>? centralids;
|
||||
Map<String, String>? attachedlocal;
|
||||
DateTime? latestcontrib;
|
||||
|
||||
MetaUserInfo({
|
||||
required this.id,
|
||||
required this.name,
|
||||
this.groups,
|
||||
this.groupmemberships,
|
||||
this.implicitgroups,
|
||||
this.rights,
|
||||
this.changeablegroups,
|
||||
this.options,
|
||||
this.editcount,
|
||||
this.realname,
|
||||
this.email,
|
||||
this.emailauthenticated,
|
||||
this.registrationdate,
|
||||
this.acceptlang,
|
||||
this.unreadcount,
|
||||
this.centralids,
|
||||
this.attachedlocal,
|
||||
this.latestcontrib,
|
||||
});
|
||||
|
||||
factory MetaUserInfo.fromJson(Map<String, dynamic> json) =>
|
||||
_$MetaUserInfoFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$MetaUserInfoToJson(this);
|
||||
@freezed
|
||||
class MetaUserInfo with _$MetaUserInfo {
|
||||
factory MetaUserInfo({
|
||||
required int id,
|
||||
required String name,
|
||||
List<String>? groups,
|
||||
List<UserGroupMembership>? groupmemberships,
|
||||
List<String>? implicitgroups,
|
||||
List<String>? rights,
|
||||
Map<String, List<String>>? changeablegroups,
|
||||
Map<String, dynamic>? options,
|
||||
int? editcount,
|
||||
String? realname,
|
||||
String? email,
|
||||
DateTime? emailauthenticated,
|
||||
DateTime? registrationdate,
|
||||
List<UserAcceptLang>? acceptlang,
|
||||
int? unreadcount,
|
||||
Map<String, int>? centralids,
|
||||
Map<String, String>? attachedlocal,
|
||||
DateTime? latestcontrib,
|
||||
}) = _MetaUserInfo;
|
||||
|
||||
factory MetaUserInfo.fromJson(Map<String, dynamic> json) => _$MetaUserInfoFromJson(json);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class MetaUserInfoResponse {
|
||||
MetaUserInfo userinfo;
|
||||
Map<int, String>? useravatar;
|
||||
|
||||
MetaUserInfoResponse({
|
||||
required this.userinfo,
|
||||
this.useravatar,
|
||||
});
|
||||
@freezed
|
||||
class MetaUserInfoResponse with _$MetaUserInfoResponse {
|
||||
factory MetaUserInfoResponse({
|
||||
required MetaUserInfo userinfo,
|
||||
Map<int, String>? useravatar,
|
||||
}) = _MetaUserInfoResponse;
|
||||
|
||||
factory MetaUserInfoResponse.fromJson(Map<String, dynamic> json) =>
|
||||
_$MetaUserInfoResponseFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$MetaUserInfoResponseToJson(this);
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue