mirror of
https://github.com/foss42/apidash.git
synced 2025-07-01 13:37:54 +08:00
added necessary insomnia models
This commit is contained in:
131
packages/insomnia/lib/models/insomnia_collection.dart
Normal file
131
packages/insomnia/lib/models/insomnia_collection.dart
Normal file
@ -0,0 +1,131 @@
|
||||
import 'dart:convert';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
part 'insomnia_collection.freezed.dart';
|
||||
part 'insomnia_collection.g.dart';
|
||||
|
||||
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
|
||||
class InsomniaCollection with _$InsomniaCollection {
|
||||
@JsonSerializable(
|
||||
explicitToJson: true,
|
||||
anyMap: true,
|
||||
includeIfNull: false,
|
||||
)
|
||||
const factory InsomniaCollection({
|
||||
@JsonKey(name: '_type') String? type,
|
||||
@JsonKey(name: '__export_format') num? exportFormat,
|
||||
@JsonKey(name: '__export_date') String? exportDate,
|
||||
@JsonKey(name: '__export_source') String? exportSource,
|
||||
List<Resource>? resources,
|
||||
}) = _InsomniaCollection;
|
||||
|
||||
factory InsomniaCollection.fromJson(Map<String, dynamic> json) =>
|
||||
_$InsomniaCollectionFromJson(json);
|
||||
}
|
||||
|
||||
@freezed
|
||||
class Resource with _$Resource {
|
||||
@JsonSerializable(
|
||||
explicitToJson: true,
|
||||
anyMap: true,
|
||||
includeIfNull: false,
|
||||
)
|
||||
const factory Resource({
|
||||
@JsonKey(name: '_id') String? id,
|
||||
@JsonKey(name: 'parentId') String? parentId,
|
||||
num? modified,
|
||||
num? created,
|
||||
String? url,
|
||||
String? name,
|
||||
String? description,
|
||||
String? method,
|
||||
Body? body,
|
||||
List<Parameter>? parameters,
|
||||
List<Header>? headers,
|
||||
String? preRequestScript,
|
||||
num? metaSortKey,
|
||||
bool? isPrivate,
|
||||
String? afterResponseScript,
|
||||
bool? settingSendCookies,
|
||||
bool? settingStoreCookies,
|
||||
bool? settingDisableRenderRequestBody,
|
||||
bool? settingEncodeUrl,
|
||||
bool? settingRebuildPath,
|
||||
String? settingFollowRedirects,
|
||||
@JsonKey(name: '_type') String? type,
|
||||
}) = _Resource;
|
||||
|
||||
factory Resource.fromJson(Map<String, dynamic> json) =>
|
||||
_$ResourceFromJson(json);
|
||||
}
|
||||
|
||||
@freezed
|
||||
class Body with _$Body {
|
||||
@JsonSerializable(
|
||||
explicitToJson: true,
|
||||
anyMap: true,
|
||||
includeIfNull: false,
|
||||
)
|
||||
const factory Body({
|
||||
String? mimeType,
|
||||
String? text,
|
||||
}) = _Body;
|
||||
|
||||
factory Body.fromJson(Map<String, dynamic> json) => _$BodyFromJson(json);
|
||||
}
|
||||
|
||||
@freezed
|
||||
class Parameter with _$Parameter {
|
||||
@JsonSerializable(
|
||||
explicitToJson: true,
|
||||
anyMap: true,
|
||||
includeIfNull: false,
|
||||
)
|
||||
const factory Parameter({
|
||||
String? id,
|
||||
String? name,
|
||||
String? value,
|
||||
String? description,
|
||||
bool? disabled,
|
||||
}) = _Parameter;
|
||||
|
||||
factory Parameter.fromJson(Map<String, dynamic> json) =>
|
||||
_$ParameterFromJson(json);
|
||||
}
|
||||
|
||||
@freezed
|
||||
class Header with _$Header {
|
||||
@JsonSerializable(
|
||||
explicitToJson: true,
|
||||
anyMap: true,
|
||||
includeIfNull: false,
|
||||
)
|
||||
const factory Header({
|
||||
String? name,
|
||||
String? value,
|
||||
}) = _Header;
|
||||
|
||||
factory Header.fromJson(Map<String, dynamic> json) => _$HeaderFromJson(json);
|
||||
}
|
1497
packages/insomnia/lib/models/insomnia_collection.freezed.dart
Normal file
1497
packages/insomnia/lib/models/insomnia_collection.freezed.dart
Normal file
File diff suppressed because it is too large
Load Diff
137
packages/insomnia/lib/models/insomnia_collection.g.dart
Normal file
137
packages/insomnia/lib/models/insomnia_collection.g.dart
Normal file
@ -0,0 +1,137 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'insomnia_collection.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
_$InsomniaCollectionImpl _$$InsomniaCollectionImplFromJson(Map json) =>
|
||||
_$InsomniaCollectionImpl(
|
||||
type: json['_type'] as String?,
|
||||
exportFormat: json['__export_format'] as num?,
|
||||
exportDate: json['__export_date'] as String?,
|
||||
exportSource: json['__export_source'] as String?,
|
||||
resources: (json['resources'] as List<dynamic>?)
|
||||
?.map((e) => Resource.fromJson(Map<String, dynamic>.from(e as Map)))
|
||||
.toList(),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$InsomniaCollectionImplToJson(
|
||||
_$InsomniaCollectionImpl instance) =>
|
||||
<String, dynamic>{
|
||||
if (instance.type case final value?) '_type': value,
|
||||
if (instance.exportFormat case final value?) '__export_format': value,
|
||||
if (instance.exportDate case final value?) '__export_date': value,
|
||||
if (instance.exportSource case final value?) '__export_source': value,
|
||||
if (instance.resources?.map((e) => e.toJson()).toList() case final value?)
|
||||
'resources': value,
|
||||
};
|
||||
|
||||
_$ResourceImpl _$$ResourceImplFromJson(Map json) => _$ResourceImpl(
|
||||
id: json['_id'] as String?,
|
||||
parentId: json['parentId'] as String?,
|
||||
modified: json['modified'] as num?,
|
||||
created: json['created'] as num?,
|
||||
url: json['url'] as String?,
|
||||
name: json['name'] as String?,
|
||||
description: json['description'] as String?,
|
||||
method: json['method'] as String?,
|
||||
body: json['body'] == null
|
||||
? null
|
||||
: Body.fromJson(Map<String, dynamic>.from(json['body'] as Map)),
|
||||
parameters: (json['parameters'] as List<dynamic>?)
|
||||
?.map((e) => Parameter.fromJson(Map<String, dynamic>.from(e as Map)))
|
||||
.toList(),
|
||||
headers: (json['headers'] as List<dynamic>?)
|
||||
?.map((e) => Header.fromJson(Map<String, dynamic>.from(e as Map)))
|
||||
.toList(),
|
||||
preRequestScript: json['preRequestScript'] as String?,
|
||||
metaSortKey: json['metaSortKey'] as num?,
|
||||
isPrivate: json['isPrivate'] as bool?,
|
||||
afterResponseScript: json['afterResponseScript'] as String?,
|
||||
settingSendCookies: json['settingSendCookies'] as bool?,
|
||||
settingStoreCookies: json['settingStoreCookies'] as bool?,
|
||||
settingDisableRenderRequestBody:
|
||||
json['settingDisableRenderRequestBody'] as bool?,
|
||||
settingEncodeUrl: json['settingEncodeUrl'] as bool?,
|
||||
settingRebuildPath: json['settingRebuildPath'] as bool?,
|
||||
settingFollowRedirects: json['settingFollowRedirects'] as String?,
|
||||
type: json['_type'] as String?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$ResourceImplToJson(_$ResourceImpl instance) =>
|
||||
<String, dynamic>{
|
||||
if (instance.id case final value?) '_id': value,
|
||||
if (instance.parentId case final value?) 'parentId': value,
|
||||
if (instance.modified case final value?) 'modified': value,
|
||||
if (instance.created case final value?) 'created': value,
|
||||
if (instance.url case final value?) 'url': value,
|
||||
if (instance.name case final value?) 'name': value,
|
||||
if (instance.description case final value?) 'description': value,
|
||||
if (instance.method case final value?) 'method': value,
|
||||
if (instance.body?.toJson() case final value?) 'body': value,
|
||||
if (instance.parameters?.map((e) => e.toJson()).toList()
|
||||
case final value?)
|
||||
'parameters': value,
|
||||
if (instance.headers?.map((e) => e.toJson()).toList() case final value?)
|
||||
'headers': value,
|
||||
if (instance.preRequestScript case final value?)
|
||||
'preRequestScript': value,
|
||||
if (instance.metaSortKey case final value?) 'metaSortKey': value,
|
||||
if (instance.isPrivate case final value?) 'isPrivate': value,
|
||||
if (instance.afterResponseScript case final value?)
|
||||
'afterResponseScript': value,
|
||||
if (instance.settingSendCookies case final value?)
|
||||
'settingSendCookies': value,
|
||||
if (instance.settingStoreCookies case final value?)
|
||||
'settingStoreCookies': value,
|
||||
if (instance.settingDisableRenderRequestBody case final value?)
|
||||
'settingDisableRenderRequestBody': value,
|
||||
if (instance.settingEncodeUrl case final value?)
|
||||
'settingEncodeUrl': value,
|
||||
if (instance.settingRebuildPath case final value?)
|
||||
'settingRebuildPath': value,
|
||||
if (instance.settingFollowRedirects case final value?)
|
||||
'settingFollowRedirects': value,
|
||||
if (instance.type case final value?) '_type': value,
|
||||
};
|
||||
|
||||
_$BodyImpl _$$BodyImplFromJson(Map json) => _$BodyImpl(
|
||||
mimeType: json['mimeType'] as String?,
|
||||
text: json['text'] as String?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$BodyImplToJson(_$BodyImpl instance) =>
|
||||
<String, dynamic>{
|
||||
if (instance.mimeType case final value?) 'mimeType': value,
|
||||
if (instance.text case final value?) 'text': value,
|
||||
};
|
||||
|
||||
_$ParameterImpl _$$ParameterImplFromJson(Map json) => _$ParameterImpl(
|
||||
id: json['id'] as String?,
|
||||
name: json['name'] as String?,
|
||||
value: json['value'] as String?,
|
||||
description: json['description'] as String?,
|
||||
disabled: json['disabled'] as bool?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$ParameterImplToJson(_$ParameterImpl 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.description case final value?) 'description': value,
|
||||
if (instance.disabled case final value?) 'disabled': value,
|
||||
};
|
||||
|
||||
_$HeaderImpl _$$HeaderImplFromJson(Map json) => _$HeaderImpl(
|
||||
name: json['name'] as String?,
|
||||
value: json['value'] as String?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$HeaderImplToJson(_$HeaderImpl instance) =>
|
||||
<String, dynamic>{
|
||||
if (instance.name case final value?) 'name': value,
|
||||
if (instance.value case final value?) 'value': value,
|
||||
};
|
1
packages/insomnia/lib/models/models.dart
Normal file
1
packages/insomnia/lib/models/models.dart
Normal file
@ -0,0 +1 @@
|
||||
export 'insomnia_collection.dart';
|
Reference in New Issue
Block a user