mirror of
https://github.com/foss42/apidash.git
synced 2025-07-01 13:37:54 +08:00
Update InsomniaCollection model
This commit is contained in:
@ -1,50 +1,14 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||||
import 'package:insomnia_collection/models/insomnia_environment.dart';
|
|
||||||
|
|
||||||
part 'insomnia_collection.freezed.dart';
|
part 'insomnia_collection.freezed.dart';
|
||||||
part 'insomnia_collection.g.dart';
|
part 'insomnia_collection.g.dart';
|
||||||
|
|
||||||
InsomniaEnvironment insomniaEnvironmentFromJsonStr(String str) {
|
InsomniaCollection insomniaCollectionFromJsonStr(String str) =>
|
||||||
var InsomniaEnvjson = json.decode(str);
|
InsomniaCollection.fromJson(json.decode(str));
|
||||||
print(InsomniaEnvjson.toString());
|
|
||||||
InsomniaEnvjson['resources'] = (InsomniaEnvjson['resources'] as List)
|
|
||||||
.where((resource) => resource['_type'] == 'environment')
|
|
||||||
.toList();
|
|
||||||
print(InsomniaEnvjson['resources'].toString());
|
|
||||||
|
|
||||||
return InsomniaEnvironment.fromJson(InsomniaEnvjson['resources'][0]);
|
String insomniaCollectionToJsonStr(InsomniaCollection data) =>
|
||||||
}
|
JsonEncoder.withIndent(' ').convert(data);
|
||||||
|
|
||||||
InsomniaEnvironment insomniaEnvironmentFromJson(Map<String, dynamic> json) {
|
|
||||||
// Remove all resources which are not requests
|
|
||||||
json['resources'] = (json['resources'] as List)
|
|
||||||
.where((resource) => resource['_type'] == 'environment')
|
|
||||||
.toList();
|
|
||||||
|
|
||||||
return InsomniaEnvironment.fromJson(json['resources'][0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
InsomniaCollection insomniaCollectionFromJsonStr(String str) {
|
|
||||||
var Insomniajson = json.decode(str);
|
|
||||||
// Remove all resources which are not requests
|
|
||||||
Insomniajson['resources'] = (Insomniajson['resources'] as List)
|
|
||||||
.where((resource) => resource['_type'] == 'request')
|
|
||||||
.toList();
|
|
||||||
|
|
||||||
return InsomniaCollection.fromJson(Insomniajson);
|
|
||||||
}
|
|
||||||
|
|
||||||
InsomniaCollection insomniaCollectionFromJson(Map<String, dynamic> json) {
|
|
||||||
// Remove all resources which are not requests
|
|
||||||
json['resources'] = (json['resources'] as List)
|
|
||||||
.where((resource) => resource['_type'] == 'request')
|
|
||||||
.toList();
|
|
||||||
|
|
||||||
return InsomniaCollection.fromJson(json);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// TODO: functions to convert to json and json string
|
|
||||||
|
|
||||||
@freezed
|
@freezed
|
||||||
class InsomniaCollection with _$InsomniaCollection {
|
class InsomniaCollection with _$InsomniaCollection {
|
||||||
@ -74,7 +38,7 @@ class Resource with _$Resource {
|
|||||||
)
|
)
|
||||||
const factory Resource({
|
const factory Resource({
|
||||||
@JsonKey(name: '_id') String? id,
|
@JsonKey(name: '_id') String? id,
|
||||||
@JsonKey(name: 'parentId') String? parentId,
|
String? parentId,
|
||||||
num? modified,
|
num? modified,
|
||||||
num? created,
|
num? created,
|
||||||
String? url,
|
String? url,
|
||||||
@ -82,18 +46,32 @@ class Resource with _$Resource {
|
|||||||
String? description,
|
String? description,
|
||||||
String? method,
|
String? method,
|
||||||
Body? body,
|
Body? body,
|
||||||
|
String? preRequestScript,
|
||||||
List<Parameter>? parameters,
|
List<Parameter>? parameters,
|
||||||
List<Header>? headers,
|
List<Header>? headers,
|
||||||
String? preRequestScript,
|
dynamic authentication,
|
||||||
num? metaSortKey,
|
num? metaSortKey,
|
||||||
bool? isPrivate,
|
bool? isPrivate,
|
||||||
|
List<dynamic>? pathParameters,
|
||||||
String? afterResponseScript,
|
String? afterResponseScript,
|
||||||
bool? settingSendCookies,
|
|
||||||
bool? settingStoreCookies,
|
bool? settingStoreCookies,
|
||||||
|
bool? settingSendCookies,
|
||||||
bool? settingDisableRenderRequestBody,
|
bool? settingDisableRenderRequestBody,
|
||||||
bool? settingEncodeUrl,
|
bool? settingEncodeUrl,
|
||||||
bool? settingRebuildPath,
|
bool? settingRebuildPath,
|
||||||
String? settingFollowRedirects,
|
String? settingFollowRedirects,
|
||||||
|
dynamic environment,
|
||||||
|
dynamic environmentPropertyOrder,
|
||||||
|
String? scope,
|
||||||
|
dynamic data,
|
||||||
|
dynamic dataPropertyOrder,
|
||||||
|
dynamic color,
|
||||||
|
List<Cookie>? cookies,
|
||||||
|
String? fileName,
|
||||||
|
String? contents,
|
||||||
|
String? contentType,
|
||||||
|
String? environmentType,
|
||||||
|
List<KVPairDatum>? kvPairData,
|
||||||
@JsonKey(name: '_type') String? type,
|
@JsonKey(name: '_type') String? type,
|
||||||
}) = _Resource;
|
}) = _Resource;
|
||||||
|
|
||||||
@ -169,3 +147,46 @@ class Header with _$Header {
|
|||||||
|
|
||||||
factory Header.fromJson(Map<String, dynamic> json) => _$HeaderFromJson(json);
|
factory Header.fromJson(Map<String, dynamic> json) => _$HeaderFromJson(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@freezed
|
||||||
|
class Cookie with _$Cookie {
|
||||||
|
@JsonSerializable(
|
||||||
|
explicitToJson: true,
|
||||||
|
anyMap: true,
|
||||||
|
includeIfNull: false,
|
||||||
|
)
|
||||||
|
const factory Cookie({
|
||||||
|
String? key,
|
||||||
|
String? value,
|
||||||
|
String? domain,
|
||||||
|
String? path,
|
||||||
|
bool? secure,
|
||||||
|
bool? httpOnly,
|
||||||
|
bool? hostOnly,
|
||||||
|
DateTime? creation,
|
||||||
|
DateTime? lastAccessed,
|
||||||
|
String? sameSite,
|
||||||
|
String? id,
|
||||||
|
}) = _Cookie;
|
||||||
|
|
||||||
|
factory Cookie.fromJson(Map<String, dynamic> json) => _$CookieFromJson(json);
|
||||||
|
}
|
||||||
|
|
||||||
|
@freezed
|
||||||
|
class KVPairDatum with _$KVPairDatum {
|
||||||
|
@JsonSerializable(
|
||||||
|
explicitToJson: true,
|
||||||
|
anyMap: true,
|
||||||
|
includeIfNull: false,
|
||||||
|
)
|
||||||
|
const factory KVPairDatum({
|
||||||
|
String? id,
|
||||||
|
String? name,
|
||||||
|
String? value,
|
||||||
|
String? type,
|
||||||
|
bool? enabled,
|
||||||
|
}) = _KVPairDatum;
|
||||||
|
|
||||||
|
factory KVPairDatum.fromJson(Map<String, dynamic> json) =>
|
||||||
|
_$KVPairDatumFromJson(json);
|
||||||
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -40,23 +40,42 @@ _$ResourceImpl _$$ResourceImplFromJson(Map json) => _$ResourceImpl(
|
|||||||
body: json['body'] == null
|
body: json['body'] == null
|
||||||
? null
|
? null
|
||||||
: Body.fromJson(Map<String, dynamic>.from(json['body'] as Map)),
|
: Body.fromJson(Map<String, dynamic>.from(json['body'] as Map)),
|
||||||
|
preRequestScript: json['preRequestScript'] as String?,
|
||||||
parameters: (json['parameters'] as List<dynamic>?)
|
parameters: (json['parameters'] as List<dynamic>?)
|
||||||
?.map((e) => Parameter.fromJson(Map<String, dynamic>.from(e as Map)))
|
?.map((e) => Parameter.fromJson(Map<String, dynamic>.from(e as Map)))
|
||||||
.toList(),
|
.toList(),
|
||||||
headers: (json['headers'] as List<dynamic>?)
|
headers: (json['headers'] as List<dynamic>?)
|
||||||
?.map((e) => Header.fromJson(Map<String, dynamic>.from(e as Map)))
|
?.map((e) => Header.fromJson(Map<String, dynamic>.from(e as Map)))
|
||||||
.toList(),
|
.toList(),
|
||||||
preRequestScript: json['preRequestScript'] as String?,
|
authentication: json['authentication'],
|
||||||
metaSortKey: json['metaSortKey'] as num?,
|
metaSortKey: json['metaSortKey'] as num?,
|
||||||
isPrivate: json['isPrivate'] as bool?,
|
isPrivate: json['isPrivate'] as bool?,
|
||||||
|
pathParameters: json['pathParameters'] as List<dynamic>?,
|
||||||
afterResponseScript: json['afterResponseScript'] as String?,
|
afterResponseScript: json['afterResponseScript'] as String?,
|
||||||
settingSendCookies: json['settingSendCookies'] as bool?,
|
|
||||||
settingStoreCookies: json['settingStoreCookies'] as bool?,
|
settingStoreCookies: json['settingStoreCookies'] as bool?,
|
||||||
|
settingSendCookies: json['settingSendCookies'] as bool?,
|
||||||
settingDisableRenderRequestBody:
|
settingDisableRenderRequestBody:
|
||||||
json['settingDisableRenderRequestBody'] as bool?,
|
json['settingDisableRenderRequestBody'] as bool?,
|
||||||
settingEncodeUrl: json['settingEncodeUrl'] as bool?,
|
settingEncodeUrl: json['settingEncodeUrl'] as bool?,
|
||||||
settingRebuildPath: json['settingRebuildPath'] as bool?,
|
settingRebuildPath: json['settingRebuildPath'] as bool?,
|
||||||
settingFollowRedirects: json['settingFollowRedirects'] as String?,
|
settingFollowRedirects: json['settingFollowRedirects'] as String?,
|
||||||
|
environment: json['environment'],
|
||||||
|
environmentPropertyOrder: json['environmentPropertyOrder'],
|
||||||
|
scope: json['scope'] as String?,
|
||||||
|
data: json['data'],
|
||||||
|
dataPropertyOrder: json['dataPropertyOrder'],
|
||||||
|
color: json['color'],
|
||||||
|
cookies: (json['cookies'] as List<dynamic>?)
|
||||||
|
?.map((e) => Cookie.fromJson(Map<String, dynamic>.from(e as Map)))
|
||||||
|
.toList(),
|
||||||
|
fileName: json['fileName'] as String?,
|
||||||
|
contents: json['contents'] as String?,
|
||||||
|
contentType: json['contentType'] as String?,
|
||||||
|
environmentType: json['environmentType'] as String?,
|
||||||
|
kvPairData: (json['kvPairData'] as List<dynamic>?)
|
||||||
|
?.map(
|
||||||
|
(e) => KVPairDatum.fromJson(Map<String, dynamic>.from(e as Map)))
|
||||||
|
.toList(),
|
||||||
type: json['_type'] as String?,
|
type: json['_type'] as String?,
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -71,21 +90,23 @@ Map<String, dynamic> _$$ResourceImplToJson(_$ResourceImpl instance) =>
|
|||||||
if (instance.description case final value?) 'description': value,
|
if (instance.description case final value?) 'description': value,
|
||||||
if (instance.method case final value?) 'method': value,
|
if (instance.method case final value?) 'method': value,
|
||||||
if (instance.body?.toJson() case final value?) 'body': value,
|
if (instance.body?.toJson() case final value?) 'body': value,
|
||||||
|
if (instance.preRequestScript case final value?)
|
||||||
|
'preRequestScript': value,
|
||||||
if (instance.parameters?.map((e) => e.toJson()).toList()
|
if (instance.parameters?.map((e) => e.toJson()).toList()
|
||||||
case final value?)
|
case final value?)
|
||||||
'parameters': value,
|
'parameters': value,
|
||||||
if (instance.headers?.map((e) => e.toJson()).toList() case final value?)
|
if (instance.headers?.map((e) => e.toJson()).toList() case final value?)
|
||||||
'headers': value,
|
'headers': value,
|
||||||
if (instance.preRequestScript case final value?)
|
if (instance.authentication case final value?) 'authentication': value,
|
||||||
'preRequestScript': value,
|
|
||||||
if (instance.metaSortKey case final value?) 'metaSortKey': value,
|
if (instance.metaSortKey case final value?) 'metaSortKey': value,
|
||||||
if (instance.isPrivate case final value?) 'isPrivate': value,
|
if (instance.isPrivate case final value?) 'isPrivate': value,
|
||||||
|
if (instance.pathParameters case final value?) 'pathParameters': value,
|
||||||
if (instance.afterResponseScript case final value?)
|
if (instance.afterResponseScript case final value?)
|
||||||
'afterResponseScript': value,
|
'afterResponseScript': value,
|
||||||
if (instance.settingSendCookies case final value?)
|
|
||||||
'settingSendCookies': value,
|
|
||||||
if (instance.settingStoreCookies case final value?)
|
if (instance.settingStoreCookies case final value?)
|
||||||
'settingStoreCookies': value,
|
'settingStoreCookies': value,
|
||||||
|
if (instance.settingSendCookies case final value?)
|
||||||
|
'settingSendCookies': value,
|
||||||
if (instance.settingDisableRenderRequestBody case final value?)
|
if (instance.settingDisableRenderRequestBody case final value?)
|
||||||
'settingDisableRenderRequestBody': value,
|
'settingDisableRenderRequestBody': value,
|
||||||
if (instance.settingEncodeUrl case final value?)
|
if (instance.settingEncodeUrl case final value?)
|
||||||
@ -94,6 +115,23 @@ Map<String, dynamic> _$$ResourceImplToJson(_$ResourceImpl instance) =>
|
|||||||
'settingRebuildPath': value,
|
'settingRebuildPath': value,
|
||||||
if (instance.settingFollowRedirects case final value?)
|
if (instance.settingFollowRedirects case final value?)
|
||||||
'settingFollowRedirects': value,
|
'settingFollowRedirects': value,
|
||||||
|
if (instance.environment case final value?) 'environment': value,
|
||||||
|
if (instance.environmentPropertyOrder case final value?)
|
||||||
|
'environmentPropertyOrder': value,
|
||||||
|
if (instance.scope case final value?) 'scope': value,
|
||||||
|
if (instance.data case final value?) 'data': value,
|
||||||
|
if (instance.dataPropertyOrder case final value?)
|
||||||
|
'dataPropertyOrder': value,
|
||||||
|
if (instance.color case final value?) 'color': value,
|
||||||
|
if (instance.cookies?.map((e) => e.toJson()).toList() case final value?)
|
||||||
|
'cookies': value,
|
||||||
|
if (instance.fileName case final value?) 'fileName': value,
|
||||||
|
if (instance.contents case final value?) 'contents': value,
|
||||||
|
if (instance.contentType case final value?) 'contentType': value,
|
||||||
|
if (instance.environmentType case final value?) 'environmentType': value,
|
||||||
|
if (instance.kvPairData?.map((e) => e.toJson()).toList()
|
||||||
|
case final value?)
|
||||||
|
'kvPairData': value,
|
||||||
if (instance.type case final value?) '_type': value,
|
if (instance.type case final value?) '_type': value,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -157,3 +195,55 @@ Map<String, dynamic> _$$HeaderImplToJson(_$HeaderImpl instance) =>
|
|||||||
if (instance.value case final value?) 'value': value,
|
if (instance.value case final value?) 'value': value,
|
||||||
if (instance.disabled case final value?) 'disabled': value,
|
if (instance.disabled case final value?) 'disabled': value,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
_$CookieImpl _$$CookieImplFromJson(Map json) => _$CookieImpl(
|
||||||
|
key: json['key'] as String?,
|
||||||
|
value: json['value'] as String?,
|
||||||
|
domain: json['domain'] as String?,
|
||||||
|
path: json['path'] as String?,
|
||||||
|
secure: json['secure'] as bool?,
|
||||||
|
httpOnly: json['httpOnly'] as bool?,
|
||||||
|
hostOnly: json['hostOnly'] as bool?,
|
||||||
|
creation: json['creation'] == null
|
||||||
|
? null
|
||||||
|
: DateTime.parse(json['creation'] as String),
|
||||||
|
lastAccessed: json['lastAccessed'] == null
|
||||||
|
? null
|
||||||
|
: DateTime.parse(json['lastAccessed'] as String),
|
||||||
|
sameSite: json['sameSite'] as String?,
|
||||||
|
id: json['id'] as String?,
|
||||||
|
);
|
||||||
|
|
||||||
|
Map<String, dynamic> _$$CookieImplToJson(_$CookieImpl instance) =>
|
||||||
|
<String, dynamic>{
|
||||||
|
if (instance.key case final value?) 'key': value,
|
||||||
|
if (instance.value case final value?) 'value': value,
|
||||||
|
if (instance.domain case final value?) 'domain': value,
|
||||||
|
if (instance.path case final value?) 'path': value,
|
||||||
|
if (instance.secure case final value?) 'secure': value,
|
||||||
|
if (instance.httpOnly case final value?) 'httpOnly': value,
|
||||||
|
if (instance.hostOnly case final value?) 'hostOnly': value,
|
||||||
|
if (instance.creation?.toIso8601String() case final value?)
|
||||||
|
'creation': value,
|
||||||
|
if (instance.lastAccessed?.toIso8601String() case final value?)
|
||||||
|
'lastAccessed': value,
|
||||||
|
if (instance.sameSite case final value?) 'sameSite': value,
|
||||||
|
if (instance.id case final value?) 'id': value,
|
||||||
|
};
|
||||||
|
|
||||||
|
_$KVPairDatumImpl _$$KVPairDatumImplFromJson(Map json) => _$KVPairDatumImpl(
|
||||||
|
id: json['id'] as String?,
|
||||||
|
name: json['name'] as String?,
|
||||||
|
value: json['value'] as String?,
|
||||||
|
type: json['type'] as String?,
|
||||||
|
enabled: json['enabled'] as bool?,
|
||||||
|
);
|
||||||
|
|
||||||
|
Map<String, dynamic> _$$KVPairDatumImplToJson(_$KVPairDatumImpl instance) =>
|
||||||
|
<String, dynamic>{
|
||||||
|
if (instance.id case final value?) 'id': value,
|
||||||
|
if (instance.name case final value?) 'name': value,
|
||||||
|
if (instance.value case final value?) 'value': value,
|
||||||
|
if (instance.type case final value?) 'type': value,
|
||||||
|
if (instance.enabled case final value?) 'enabled': value,
|
||||||
|
};
|
||||||
|
Reference in New Issue
Block a user