From d1e591675b396001be751accff999946a8bbe1e5 Mon Sep 17 00:00:00 2001 From: StormGear Date: Mon, 6 Jan 2025 15:02:39 +0000 Subject: [PATCH 01/42] using fvm for flutter versioning ignore .fvm folder --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 9a64d7c0..06d603f8 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,8 @@ .history .svn/ migrate_working_dir/ +.fvm +.fvmrc # IntelliJ related *.iml From be7954ddd90d610ce764a8faf548246dba086bbf Mon Sep 17 00:00:00 2001 From: StormGear Date: Mon, 6 Jan 2025 15:03:56 +0000 Subject: [PATCH 02/42] added necessary insomnia enums and exports --- lib/consts.dart | 3 +- lib/importer/importer.dart | 1 + .../lib/import_export/import_export.dart | 1 + packages/apidash_core/pubspec.yaml | 2 ++ packages/insomnia/.gitignore | 29 +++++++++++++++++++ packages/insomnia/analysis_options.yaml | 6 ++++ 6 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 packages/insomnia/.gitignore create mode 100644 packages/insomnia/analysis_options.yaml diff --git a/lib/consts.dart b/lib/consts.dart index 89fe61fb..c267a471 100644 --- a/lib/consts.dart +++ b/lib/consts.dart @@ -141,7 +141,8 @@ enum CodegenLanguage { enum ImportFormat { curl("cURL"), - postman("Postman Collection v2.1"); + postman("Postman Collection v2.1"), + insomia("Insomnia v4"); const ImportFormat(this.label); final String label; diff --git a/lib/importer/importer.dart b/lib/importer/importer.dart index 96d33091..3f5125a6 100644 --- a/lib/importer/importer.dart +++ b/lib/importer/importer.dart @@ -12,6 +12,7 @@ class Importer { ?.map((t) => (null, t)) .toList(), ImportFormat.postman => PostmanIO().getHttpRequestModelList(content), + ImportFormat.insomia => InsomiaIO().getHttpRequestModelList(content), }; } } diff --git a/packages/apidash_core/lib/import_export/import_export.dart b/packages/apidash_core/lib/import_export/import_export.dart index c61e96a9..bfa4964f 100644 --- a/packages/apidash_core/lib/import_export/import_export.dart +++ b/packages/apidash_core/lib/import_export/import_export.dart @@ -1,2 +1,3 @@ export 'curl_io.dart'; export 'postman_io.dart'; +export 'insomia_io.dart'; diff --git a/packages/apidash_core/pubspec.yaml b/packages/apidash_core/pubspec.yaml index f6f72beb..4b4dc38d 100644 --- a/packages/apidash_core/pubspec.yaml +++ b/packages/apidash_core/pubspec.yaml @@ -19,6 +19,8 @@ dependencies: http_parser: ^4.0.2 postman: path: ../postman + insomnia: + path: ../insomnia seed: ^0.0.2 xml: ^6.3.0 diff --git a/packages/insomnia/.gitignore b/packages/insomnia/.gitignore new file mode 100644 index 00000000..ac5aa989 --- /dev/null +++ b/packages/insomnia/.gitignore @@ -0,0 +1,29 @@ +# Miscellaneous +*.class +*.log +*.pyc +*.swp +.DS_Store +.atom/ +.buildlog/ +.history +.svn/ +migrate_working_dir/ + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ + +# The .vscode folder contains launch configuration and tasks you configure in +# VS Code which you may wish to be included in version control, so this line +# is commented out by default. +#.vscode/ + +# Flutter/Dart/Pub related +# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. +/pubspec.lock +**/doc/api/ +.dart_tool/ +build/ diff --git a/packages/insomnia/analysis_options.yaml b/packages/insomnia/analysis_options.yaml new file mode 100644 index 00000000..1dea9522 --- /dev/null +++ b/packages/insomnia/analysis_options.yaml @@ -0,0 +1,6 @@ +analyzer: + exclude: + - "**/*.g.dart" + - "**/*.freezed.dart" + errors: + invalid_annotation_target: ignore From a247c6c1ef87e169da98fb42b6dfed9cc34c5e88 Mon Sep 17 00:00:00 2001 From: StormGear Date: Mon, 6 Jan 2025 15:04:48 +0000 Subject: [PATCH 03/42] added necessary insomnia models --- .../lib/models/insomnia_collection.dart | 131 ++ .../models/insomnia_collection.freezed.dart | 1497 +++++++++++++++++ .../lib/models/insomnia_collection.g.dart | 137 ++ packages/insomnia/lib/models/models.dart | 1 + 4 files changed, 1766 insertions(+) create mode 100644 packages/insomnia/lib/models/insomnia_collection.dart create mode 100644 packages/insomnia/lib/models/insomnia_collection.freezed.dart create mode 100644 packages/insomnia/lib/models/insomnia_collection.g.dart create mode 100644 packages/insomnia/lib/models/models.dart diff --git a/packages/insomnia/lib/models/insomnia_collection.dart b/packages/insomnia/lib/models/insomnia_collection.dart new file mode 100644 index 00000000..f5236a00 --- /dev/null +++ b/packages/insomnia/lib/models/insomnia_collection.dart @@ -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 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? resources, + }) = _InsomniaCollection; + + factory InsomniaCollection.fromJson(Map 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? parameters, + List
? 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 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 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 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 json) => _$HeaderFromJson(json); +} diff --git a/packages/insomnia/lib/models/insomnia_collection.freezed.dart b/packages/insomnia/lib/models/insomnia_collection.freezed.dart new file mode 100644 index 00000000..d2085f88 --- /dev/null +++ b/packages/insomnia/lib/models/insomnia_collection.freezed.dart @@ -0,0 +1,1497 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'insomnia_collection.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models'); + +InsomniaCollection _$InsomniaCollectionFromJson(Map json) { + return _InsomniaCollection.fromJson(json); +} + +/// @nodoc +mixin _$InsomniaCollection { + @JsonKey(name: '_type') + String? get type => throw _privateConstructorUsedError; + @JsonKey(name: '__export_format') + num? get exportFormat => throw _privateConstructorUsedError; + @JsonKey(name: '__export_date') + String? get exportDate => throw _privateConstructorUsedError; + @JsonKey(name: '__export_source') + String? get exportSource => throw _privateConstructorUsedError; + List? get resources => throw _privateConstructorUsedError; + + /// Serializes this InsomniaCollection to a JSON map. + Map toJson() => throw _privateConstructorUsedError; + + /// Create a copy of InsomniaCollection + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + $InsomniaCollectionCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $InsomniaCollectionCopyWith<$Res> { + factory $InsomniaCollectionCopyWith( + InsomniaCollection value, $Res Function(InsomniaCollection) then) = + _$InsomniaCollectionCopyWithImpl<$Res, InsomniaCollection>; + @useResult + $Res call( + {@JsonKey(name: '_type') String? type, + @JsonKey(name: '__export_format') num? exportFormat, + @JsonKey(name: '__export_date') String? exportDate, + @JsonKey(name: '__export_source') String? exportSource, + List? resources}); +} + +/// @nodoc +class _$InsomniaCollectionCopyWithImpl<$Res, $Val extends InsomniaCollection> + implements $InsomniaCollectionCopyWith<$Res> { + _$InsomniaCollectionCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of InsomniaCollection + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? type = freezed, + Object? exportFormat = freezed, + Object? exportDate = freezed, + Object? exportSource = freezed, + Object? resources = freezed, + }) { + return _then(_value.copyWith( + type: freezed == type + ? _value.type + : type // ignore: cast_nullable_to_non_nullable + as String?, + exportFormat: freezed == exportFormat + ? _value.exportFormat + : exportFormat // ignore: cast_nullable_to_non_nullable + as num?, + exportDate: freezed == exportDate + ? _value.exportDate + : exportDate // ignore: cast_nullable_to_non_nullable + as String?, + exportSource: freezed == exportSource + ? _value.exportSource + : exportSource // ignore: cast_nullable_to_non_nullable + as String?, + resources: freezed == resources + ? _value.resources + : resources // ignore: cast_nullable_to_non_nullable + as List?, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$InsomniaCollectionImplCopyWith<$Res> + implements $InsomniaCollectionCopyWith<$Res> { + factory _$$InsomniaCollectionImplCopyWith(_$InsomniaCollectionImpl value, + $Res Function(_$InsomniaCollectionImpl) then) = + __$$InsomniaCollectionImplCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {@JsonKey(name: '_type') String? type, + @JsonKey(name: '__export_format') num? exportFormat, + @JsonKey(name: '__export_date') String? exportDate, + @JsonKey(name: '__export_source') String? exportSource, + List? resources}); +} + +/// @nodoc +class __$$InsomniaCollectionImplCopyWithImpl<$Res> + extends _$InsomniaCollectionCopyWithImpl<$Res, _$InsomniaCollectionImpl> + implements _$$InsomniaCollectionImplCopyWith<$Res> { + __$$InsomniaCollectionImplCopyWithImpl(_$InsomniaCollectionImpl _value, + $Res Function(_$InsomniaCollectionImpl) _then) + : super(_value, _then); + + /// Create a copy of InsomniaCollection + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? type = freezed, + Object? exportFormat = freezed, + Object? exportDate = freezed, + Object? exportSource = freezed, + Object? resources = freezed, + }) { + return _then(_$InsomniaCollectionImpl( + type: freezed == type + ? _value.type + : type // ignore: cast_nullable_to_non_nullable + as String?, + exportFormat: freezed == exportFormat + ? _value.exportFormat + : exportFormat // ignore: cast_nullable_to_non_nullable + as num?, + exportDate: freezed == exportDate + ? _value.exportDate + : exportDate // ignore: cast_nullable_to_non_nullable + as String?, + exportSource: freezed == exportSource + ? _value.exportSource + : exportSource // ignore: cast_nullable_to_non_nullable + as String?, + resources: freezed == resources + ? _value._resources + : resources // ignore: cast_nullable_to_non_nullable + as List?, + )); + } +} + +/// @nodoc + +@JsonSerializable(explicitToJson: true, anyMap: true, includeIfNull: false) +class _$InsomniaCollectionImpl implements _InsomniaCollection { + const _$InsomniaCollectionImpl( + {@JsonKey(name: '_type') this.type, + @JsonKey(name: '__export_format') this.exportFormat, + @JsonKey(name: '__export_date') this.exportDate, + @JsonKey(name: '__export_source') this.exportSource, + final List? resources}) + : _resources = resources; + + factory _$InsomniaCollectionImpl.fromJson(Map json) => + _$$InsomniaCollectionImplFromJson(json); + + @override + @JsonKey(name: '_type') + final String? type; + @override + @JsonKey(name: '__export_format') + final num? exportFormat; + @override + @JsonKey(name: '__export_date') + final String? exportDate; + @override + @JsonKey(name: '__export_source') + final String? exportSource; + final List? _resources; + @override + List? get resources { + final value = _resources; + if (value == null) return null; + if (_resources is EqualUnmodifiableListView) return _resources; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(value); + } + + @override + String toString() { + return 'InsomniaCollection(type: $type, exportFormat: $exportFormat, exportDate: $exportDate, exportSource: $exportSource, resources: $resources)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$InsomniaCollectionImpl && + (identical(other.type, type) || other.type == type) && + (identical(other.exportFormat, exportFormat) || + other.exportFormat == exportFormat) && + (identical(other.exportDate, exportDate) || + other.exportDate == exportDate) && + (identical(other.exportSource, exportSource) || + other.exportSource == exportSource) && + const DeepCollectionEquality() + .equals(other._resources, _resources)); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => Object.hash(runtimeType, type, exportFormat, exportDate, + exportSource, const DeepCollectionEquality().hash(_resources)); + + /// Create a copy of InsomniaCollection + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$InsomniaCollectionImplCopyWith<_$InsomniaCollectionImpl> get copyWith => + __$$InsomniaCollectionImplCopyWithImpl<_$InsomniaCollectionImpl>( + this, _$identity); + + @override + Map toJson() { + return _$$InsomniaCollectionImplToJson( + this, + ); + } +} + +abstract class _InsomniaCollection implements InsomniaCollection { + const factory _InsomniaCollection( + {@JsonKey(name: '_type') final String? type, + @JsonKey(name: '__export_format') final num? exportFormat, + @JsonKey(name: '__export_date') final String? exportDate, + @JsonKey(name: '__export_source') final String? exportSource, + final List? resources}) = _$InsomniaCollectionImpl; + + factory _InsomniaCollection.fromJson(Map json) = + _$InsomniaCollectionImpl.fromJson; + + @override + @JsonKey(name: '_type') + String? get type; + @override + @JsonKey(name: '__export_format') + num? get exportFormat; + @override + @JsonKey(name: '__export_date') + String? get exportDate; + @override + @JsonKey(name: '__export_source') + String? get exportSource; + @override + List? get resources; + + /// Create a copy of InsomniaCollection + /// with the given fields replaced by the non-null parameter values. + @override + @JsonKey(includeFromJson: false, includeToJson: false) + _$$InsomniaCollectionImplCopyWith<_$InsomniaCollectionImpl> get copyWith => + throw _privateConstructorUsedError; +} + +Resource _$ResourceFromJson(Map json) { + return _Resource.fromJson(json); +} + +/// @nodoc +mixin _$Resource { + @JsonKey(name: '_id') + String? get id => throw _privateConstructorUsedError; + @JsonKey(name: 'parentId') + String? get parentId => throw _privateConstructorUsedError; + num? get modified => throw _privateConstructorUsedError; + num? get created => throw _privateConstructorUsedError; + String? get url => throw _privateConstructorUsedError; + String? get name => throw _privateConstructorUsedError; + String? get description => throw _privateConstructorUsedError; + String? get method => throw _privateConstructorUsedError; + Body? get body => throw _privateConstructorUsedError; + List? get parameters => throw _privateConstructorUsedError; + List
? get headers => + throw _privateConstructorUsedError; // List? authentication, + String? get preRequestScript => throw _privateConstructorUsedError; + num? get metaSortKey => throw _privateConstructorUsedError; + bool? get isPrivate => throw _privateConstructorUsedError; + String? get afterResponseScript => throw _privateConstructorUsedError; + bool? get settingSendCookies => throw _privateConstructorUsedError; + bool? get settingStoreCookies => throw _privateConstructorUsedError; + bool? get settingDisableRenderRequestBody => + throw _privateConstructorUsedError; + bool? get settingEncodeUrl => throw _privateConstructorUsedError; + bool? get settingRebuildPath => throw _privateConstructorUsedError; + String? get settingFollowRedirects => throw _privateConstructorUsedError; + @JsonKey(name: '_type') + String? get type => throw _privateConstructorUsedError; + + /// Serializes this Resource to a JSON map. + Map toJson() => throw _privateConstructorUsedError; + + /// Create a copy of Resource + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + $ResourceCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $ResourceCopyWith<$Res> { + factory $ResourceCopyWith(Resource value, $Res Function(Resource) then) = + _$ResourceCopyWithImpl<$Res, Resource>; + @useResult + $Res call( + {@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? parameters, + List
? 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}); + + $BodyCopyWith<$Res>? get body; +} + +/// @nodoc +class _$ResourceCopyWithImpl<$Res, $Val extends Resource> + implements $ResourceCopyWith<$Res> { + _$ResourceCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of Resource + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = freezed, + Object? parentId = freezed, + Object? modified = freezed, + Object? created = freezed, + Object? url = freezed, + Object? name = freezed, + Object? description = freezed, + Object? method = freezed, + Object? body = freezed, + Object? parameters = freezed, + Object? headers = freezed, + Object? preRequestScript = freezed, + Object? metaSortKey = freezed, + Object? isPrivate = freezed, + Object? afterResponseScript = freezed, + Object? settingSendCookies = freezed, + Object? settingStoreCookies = freezed, + Object? settingDisableRenderRequestBody = freezed, + Object? settingEncodeUrl = freezed, + Object? settingRebuildPath = freezed, + Object? settingFollowRedirects = freezed, + Object? type = freezed, + }) { + return _then(_value.copyWith( + id: freezed == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as String?, + parentId: freezed == parentId + ? _value.parentId + : parentId // ignore: cast_nullable_to_non_nullable + as String?, + modified: freezed == modified + ? _value.modified + : modified // ignore: cast_nullable_to_non_nullable + as num?, + created: freezed == created + ? _value.created + : created // ignore: cast_nullable_to_non_nullable + as num?, + url: freezed == url + ? _value.url + : url // ignore: cast_nullable_to_non_nullable + as String?, + name: freezed == name + ? _value.name + : name // ignore: cast_nullable_to_non_nullable + as String?, + description: freezed == description + ? _value.description + : description // ignore: cast_nullable_to_non_nullable + as String?, + method: freezed == method + ? _value.method + : method // ignore: cast_nullable_to_non_nullable + as String?, + body: freezed == body + ? _value.body + : body // ignore: cast_nullable_to_non_nullable + as Body?, + parameters: freezed == parameters + ? _value.parameters + : parameters // ignore: cast_nullable_to_non_nullable + as List?, + headers: freezed == headers + ? _value.headers + : headers // ignore: cast_nullable_to_non_nullable + as List
?, + preRequestScript: freezed == preRequestScript + ? _value.preRequestScript + : preRequestScript // ignore: cast_nullable_to_non_nullable + as String?, + metaSortKey: freezed == metaSortKey + ? _value.metaSortKey + : metaSortKey // ignore: cast_nullable_to_non_nullable + as num?, + isPrivate: freezed == isPrivate + ? _value.isPrivate + : isPrivate // ignore: cast_nullable_to_non_nullable + as bool?, + afterResponseScript: freezed == afterResponseScript + ? _value.afterResponseScript + : afterResponseScript // ignore: cast_nullable_to_non_nullable + as String?, + settingSendCookies: freezed == settingSendCookies + ? _value.settingSendCookies + : settingSendCookies // ignore: cast_nullable_to_non_nullable + as bool?, + settingStoreCookies: freezed == settingStoreCookies + ? _value.settingStoreCookies + : settingStoreCookies // ignore: cast_nullable_to_non_nullable + as bool?, + settingDisableRenderRequestBody: freezed == + settingDisableRenderRequestBody + ? _value.settingDisableRenderRequestBody + : settingDisableRenderRequestBody // ignore: cast_nullable_to_non_nullable + as bool?, + settingEncodeUrl: freezed == settingEncodeUrl + ? _value.settingEncodeUrl + : settingEncodeUrl // ignore: cast_nullable_to_non_nullable + as bool?, + settingRebuildPath: freezed == settingRebuildPath + ? _value.settingRebuildPath + : settingRebuildPath // ignore: cast_nullable_to_non_nullable + as bool?, + settingFollowRedirects: freezed == settingFollowRedirects + ? _value.settingFollowRedirects + : settingFollowRedirects // ignore: cast_nullable_to_non_nullable + as String?, + type: freezed == type + ? _value.type + : type // ignore: cast_nullable_to_non_nullable + as String?, + ) as $Val); + } + + /// Create a copy of Resource + /// with the given fields replaced by the non-null parameter values. + @override + @pragma('vm:prefer-inline') + $BodyCopyWith<$Res>? get body { + if (_value.body == null) { + return null; + } + + return $BodyCopyWith<$Res>(_value.body!, (value) { + return _then(_value.copyWith(body: value) as $Val); + }); + } +} + +/// @nodoc +abstract class _$$ResourceImplCopyWith<$Res> + implements $ResourceCopyWith<$Res> { + factory _$$ResourceImplCopyWith( + _$ResourceImpl value, $Res Function(_$ResourceImpl) then) = + __$$ResourceImplCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {@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? parameters, + List
? 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}); + + @override + $BodyCopyWith<$Res>? get body; +} + +/// @nodoc +class __$$ResourceImplCopyWithImpl<$Res> + extends _$ResourceCopyWithImpl<$Res, _$ResourceImpl> + implements _$$ResourceImplCopyWith<$Res> { + __$$ResourceImplCopyWithImpl( + _$ResourceImpl _value, $Res Function(_$ResourceImpl) _then) + : super(_value, _then); + + /// Create a copy of Resource + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = freezed, + Object? parentId = freezed, + Object? modified = freezed, + Object? created = freezed, + Object? url = freezed, + Object? name = freezed, + Object? description = freezed, + Object? method = freezed, + Object? body = freezed, + Object? parameters = freezed, + Object? headers = freezed, + Object? preRequestScript = freezed, + Object? metaSortKey = freezed, + Object? isPrivate = freezed, + Object? afterResponseScript = freezed, + Object? settingSendCookies = freezed, + Object? settingStoreCookies = freezed, + Object? settingDisableRenderRequestBody = freezed, + Object? settingEncodeUrl = freezed, + Object? settingRebuildPath = freezed, + Object? settingFollowRedirects = freezed, + Object? type = freezed, + }) { + return _then(_$ResourceImpl( + id: freezed == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as String?, + parentId: freezed == parentId + ? _value.parentId + : parentId // ignore: cast_nullable_to_non_nullable + as String?, + modified: freezed == modified + ? _value.modified + : modified // ignore: cast_nullable_to_non_nullable + as num?, + created: freezed == created + ? _value.created + : created // ignore: cast_nullable_to_non_nullable + as num?, + url: freezed == url + ? _value.url + : url // ignore: cast_nullable_to_non_nullable + as String?, + name: freezed == name + ? _value.name + : name // ignore: cast_nullable_to_non_nullable + as String?, + description: freezed == description + ? _value.description + : description // ignore: cast_nullable_to_non_nullable + as String?, + method: freezed == method + ? _value.method + : method // ignore: cast_nullable_to_non_nullable + as String?, + body: freezed == body + ? _value.body + : body // ignore: cast_nullable_to_non_nullable + as Body?, + parameters: freezed == parameters + ? _value._parameters + : parameters // ignore: cast_nullable_to_non_nullable + as List?, + headers: freezed == headers + ? _value._headers + : headers // ignore: cast_nullable_to_non_nullable + as List
?, + preRequestScript: freezed == preRequestScript + ? _value.preRequestScript + : preRequestScript // ignore: cast_nullable_to_non_nullable + as String?, + metaSortKey: freezed == metaSortKey + ? _value.metaSortKey + : metaSortKey // ignore: cast_nullable_to_non_nullable + as num?, + isPrivate: freezed == isPrivate + ? _value.isPrivate + : isPrivate // ignore: cast_nullable_to_non_nullable + as bool?, + afterResponseScript: freezed == afterResponseScript + ? _value.afterResponseScript + : afterResponseScript // ignore: cast_nullable_to_non_nullable + as String?, + settingSendCookies: freezed == settingSendCookies + ? _value.settingSendCookies + : settingSendCookies // ignore: cast_nullable_to_non_nullable + as bool?, + settingStoreCookies: freezed == settingStoreCookies + ? _value.settingStoreCookies + : settingStoreCookies // ignore: cast_nullable_to_non_nullable + as bool?, + settingDisableRenderRequestBody: freezed == + settingDisableRenderRequestBody + ? _value.settingDisableRenderRequestBody + : settingDisableRenderRequestBody // ignore: cast_nullable_to_non_nullable + as bool?, + settingEncodeUrl: freezed == settingEncodeUrl + ? _value.settingEncodeUrl + : settingEncodeUrl // ignore: cast_nullable_to_non_nullable + as bool?, + settingRebuildPath: freezed == settingRebuildPath + ? _value.settingRebuildPath + : settingRebuildPath // ignore: cast_nullable_to_non_nullable + as bool?, + settingFollowRedirects: freezed == settingFollowRedirects + ? _value.settingFollowRedirects + : settingFollowRedirects // ignore: cast_nullable_to_non_nullable + as String?, + type: freezed == type + ? _value.type + : type // ignore: cast_nullable_to_non_nullable + as String?, + )); + } +} + +/// @nodoc + +@JsonSerializable(explicitToJson: true, anyMap: true, includeIfNull: false) +class _$ResourceImpl implements _Resource { + const _$ResourceImpl( + {@JsonKey(name: '_id') this.id, + @JsonKey(name: 'parentId') this.parentId, + this.modified, + this.created, + this.url, + this.name, + this.description, + this.method, + this.body, + final List? parameters, + final List
? headers, + this.preRequestScript, + this.metaSortKey, + this.isPrivate, + this.afterResponseScript, + this.settingSendCookies, + this.settingStoreCookies, + this.settingDisableRenderRequestBody, + this.settingEncodeUrl, + this.settingRebuildPath, + this.settingFollowRedirects, + @JsonKey(name: '_type') this.type}) + : _parameters = parameters, + _headers = headers; + + factory _$ResourceImpl.fromJson(Map json) => + _$$ResourceImplFromJson(json); + + @override + @JsonKey(name: '_id') + final String? id; + @override + @JsonKey(name: 'parentId') + final String? parentId; + @override + final num? modified; + @override + final num? created; + @override + final String? url; + @override + final String? name; + @override + final String? description; + @override + final String? method; + @override + final Body? body; + final List? _parameters; + @override + List? get parameters { + final value = _parameters; + if (value == null) return null; + if (_parameters is EqualUnmodifiableListView) return _parameters; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(value); + } + + final List
? _headers; + @override + List
? get headers { + final value = _headers; + if (value == null) return null; + if (_headers is EqualUnmodifiableListView) return _headers; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(value); + } + +// List? authentication, + @override + final String? preRequestScript; + @override + final num? metaSortKey; + @override + final bool? isPrivate; + @override + final String? afterResponseScript; + @override + final bool? settingSendCookies; + @override + final bool? settingStoreCookies; + @override + final bool? settingDisableRenderRequestBody; + @override + final bool? settingEncodeUrl; + @override + final bool? settingRebuildPath; + @override + final String? settingFollowRedirects; + @override + @JsonKey(name: '_type') + final String? type; + + @override + String toString() { + return 'Resource(id: $id, parentId: $parentId, modified: $modified, created: $created, url: $url, name: $name, description: $description, method: $method, body: $body, parameters: $parameters, headers: $headers, preRequestScript: $preRequestScript, metaSortKey: $metaSortKey, isPrivate: $isPrivate, afterResponseScript: $afterResponseScript, settingSendCookies: $settingSendCookies, settingStoreCookies: $settingStoreCookies, settingDisableRenderRequestBody: $settingDisableRenderRequestBody, settingEncodeUrl: $settingEncodeUrl, settingRebuildPath: $settingRebuildPath, settingFollowRedirects: $settingFollowRedirects, type: $type)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$ResourceImpl && + (identical(other.id, id) || other.id == id) && + (identical(other.parentId, parentId) || + other.parentId == parentId) && + (identical(other.modified, modified) || + other.modified == modified) && + (identical(other.created, created) || other.created == created) && + (identical(other.url, url) || other.url == url) && + (identical(other.name, name) || other.name == name) && + (identical(other.description, description) || + other.description == description) && + (identical(other.method, method) || other.method == method) && + (identical(other.body, body) || other.body == body) && + const DeepCollectionEquality() + .equals(other._parameters, _parameters) && + const DeepCollectionEquality().equals(other._headers, _headers) && + (identical(other.preRequestScript, preRequestScript) || + other.preRequestScript == preRequestScript) && + (identical(other.metaSortKey, metaSortKey) || + other.metaSortKey == metaSortKey) && + (identical(other.isPrivate, isPrivate) || + other.isPrivate == isPrivate) && + (identical(other.afterResponseScript, afterResponseScript) || + other.afterResponseScript == afterResponseScript) && + (identical(other.settingSendCookies, settingSendCookies) || + other.settingSendCookies == settingSendCookies) && + (identical(other.settingStoreCookies, settingStoreCookies) || + other.settingStoreCookies == settingStoreCookies) && + (identical(other.settingDisableRenderRequestBody, + settingDisableRenderRequestBody) || + other.settingDisableRenderRequestBody == + settingDisableRenderRequestBody) && + (identical(other.settingEncodeUrl, settingEncodeUrl) || + other.settingEncodeUrl == settingEncodeUrl) && + (identical(other.settingRebuildPath, settingRebuildPath) || + other.settingRebuildPath == settingRebuildPath) && + (identical(other.settingFollowRedirects, settingFollowRedirects) || + other.settingFollowRedirects == settingFollowRedirects) && + (identical(other.type, type) || other.type == type)); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => Object.hashAll([ + runtimeType, + id, + parentId, + modified, + created, + url, + name, + description, + method, + body, + const DeepCollectionEquality().hash(_parameters), + const DeepCollectionEquality().hash(_headers), + preRequestScript, + metaSortKey, + isPrivate, + afterResponseScript, + settingSendCookies, + settingStoreCookies, + settingDisableRenderRequestBody, + settingEncodeUrl, + settingRebuildPath, + settingFollowRedirects, + type + ]); + + /// Create a copy of Resource + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$ResourceImplCopyWith<_$ResourceImpl> get copyWith => + __$$ResourceImplCopyWithImpl<_$ResourceImpl>(this, _$identity); + + @override + Map toJson() { + return _$$ResourceImplToJson( + this, + ); + } +} + +abstract class _Resource implements Resource { + const factory _Resource( + {@JsonKey(name: '_id') final String? id, + @JsonKey(name: 'parentId') final String? parentId, + final num? modified, + final num? created, + final String? url, + final String? name, + final String? description, + final String? method, + final Body? body, + final List? parameters, + final List
? headers, + final String? preRequestScript, + final num? metaSortKey, + final bool? isPrivate, + final String? afterResponseScript, + final bool? settingSendCookies, + final bool? settingStoreCookies, + final bool? settingDisableRenderRequestBody, + final bool? settingEncodeUrl, + final bool? settingRebuildPath, + final String? settingFollowRedirects, + @JsonKey(name: '_type') final String? type}) = _$ResourceImpl; + + factory _Resource.fromJson(Map json) = + _$ResourceImpl.fromJson; + + @override + @JsonKey(name: '_id') + String? get id; + @override + @JsonKey(name: 'parentId') + String? get parentId; + @override + num? get modified; + @override + num? get created; + @override + String? get url; + @override + String? get name; + @override + String? get description; + @override + String? get method; + @override + Body? get body; + @override + List? get parameters; + @override + List
? get headers; // List? authentication, + @override + String? get preRequestScript; + @override + num? get metaSortKey; + @override + bool? get isPrivate; + @override + String? get afterResponseScript; + @override + bool? get settingSendCookies; + @override + bool? get settingStoreCookies; + @override + bool? get settingDisableRenderRequestBody; + @override + bool? get settingEncodeUrl; + @override + bool? get settingRebuildPath; + @override + String? get settingFollowRedirects; + @override + @JsonKey(name: '_type') + String? get type; + + /// Create a copy of Resource + /// with the given fields replaced by the non-null parameter values. + @override + @JsonKey(includeFromJson: false, includeToJson: false) + _$$ResourceImplCopyWith<_$ResourceImpl> get copyWith => + throw _privateConstructorUsedError; +} + +Body _$BodyFromJson(Map json) { + return _Body.fromJson(json); +} + +/// @nodoc +mixin _$Body { + String? get mimeType => throw _privateConstructorUsedError; + String? get text => throw _privateConstructorUsedError; + + /// Serializes this Body to a JSON map. + Map toJson() => throw _privateConstructorUsedError; + + /// Create a copy of Body + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + $BodyCopyWith get copyWith => throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $BodyCopyWith<$Res> { + factory $BodyCopyWith(Body value, $Res Function(Body) then) = + _$BodyCopyWithImpl<$Res, Body>; + @useResult + $Res call({String? mimeType, String? text}); +} + +/// @nodoc +class _$BodyCopyWithImpl<$Res, $Val extends Body> + implements $BodyCopyWith<$Res> { + _$BodyCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of Body + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? mimeType = freezed, + Object? text = freezed, + }) { + return _then(_value.copyWith( + mimeType: freezed == mimeType + ? _value.mimeType + : mimeType // ignore: cast_nullable_to_non_nullable + as String?, + text: freezed == text + ? _value.text + : text // ignore: cast_nullable_to_non_nullable + as String?, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$BodyImplCopyWith<$Res> implements $BodyCopyWith<$Res> { + factory _$$BodyImplCopyWith( + _$BodyImpl value, $Res Function(_$BodyImpl) then) = + __$$BodyImplCopyWithImpl<$Res>; + @override + @useResult + $Res call({String? mimeType, String? text}); +} + +/// @nodoc +class __$$BodyImplCopyWithImpl<$Res> + extends _$BodyCopyWithImpl<$Res, _$BodyImpl> + implements _$$BodyImplCopyWith<$Res> { + __$$BodyImplCopyWithImpl(_$BodyImpl _value, $Res Function(_$BodyImpl) _then) + : super(_value, _then); + + /// Create a copy of Body + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? mimeType = freezed, + Object? text = freezed, + }) { + return _then(_$BodyImpl( + mimeType: freezed == mimeType + ? _value.mimeType + : mimeType // ignore: cast_nullable_to_non_nullable + as String?, + text: freezed == text + ? _value.text + : text // ignore: cast_nullable_to_non_nullable + as String?, + )); + } +} + +/// @nodoc + +@JsonSerializable(explicitToJson: true, anyMap: true, includeIfNull: false) +class _$BodyImpl implements _Body { + const _$BodyImpl({this.mimeType, this.text}); + + factory _$BodyImpl.fromJson(Map json) => + _$$BodyImplFromJson(json); + + @override + final String? mimeType; + @override + final String? text; + + @override + String toString() { + return 'Body(mimeType: $mimeType, text: $text)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$BodyImpl && + (identical(other.mimeType, mimeType) || + other.mimeType == mimeType) && + (identical(other.text, text) || other.text == text)); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => Object.hash(runtimeType, mimeType, text); + + /// Create a copy of Body + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$BodyImplCopyWith<_$BodyImpl> get copyWith => + __$$BodyImplCopyWithImpl<_$BodyImpl>(this, _$identity); + + @override + Map toJson() { + return _$$BodyImplToJson( + this, + ); + } +} + +abstract class _Body implements Body { + const factory _Body({final String? mimeType, final String? text}) = + _$BodyImpl; + + factory _Body.fromJson(Map json) = _$BodyImpl.fromJson; + + @override + String? get mimeType; + @override + String? get text; + + /// Create a copy of Body + /// with the given fields replaced by the non-null parameter values. + @override + @JsonKey(includeFromJson: false, includeToJson: false) + _$$BodyImplCopyWith<_$BodyImpl> get copyWith => + throw _privateConstructorUsedError; +} + +Parameter _$ParameterFromJson(Map json) { + return _Parameter.fromJson(json); +} + +/// @nodoc +mixin _$Parameter { + String? get id => throw _privateConstructorUsedError; + String? get name => throw _privateConstructorUsedError; + String? get value => throw _privateConstructorUsedError; + String? get description => throw _privateConstructorUsedError; + bool? get disabled => throw _privateConstructorUsedError; + + /// Serializes this Parameter to a JSON map. + Map toJson() => throw _privateConstructorUsedError; + + /// Create a copy of Parameter + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + $ParameterCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $ParameterCopyWith<$Res> { + factory $ParameterCopyWith(Parameter value, $Res Function(Parameter) then) = + _$ParameterCopyWithImpl<$Res, Parameter>; + @useResult + $Res call( + {String? id, + String? name, + String? value, + String? description, + bool? disabled}); +} + +/// @nodoc +class _$ParameterCopyWithImpl<$Res, $Val extends Parameter> + implements $ParameterCopyWith<$Res> { + _$ParameterCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of Parameter + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = freezed, + Object? name = freezed, + Object? value = freezed, + Object? description = freezed, + Object? disabled = freezed, + }) { + return _then(_value.copyWith( + id: freezed == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as String?, + name: freezed == name + ? _value.name + : name // ignore: cast_nullable_to_non_nullable + as String?, + value: freezed == value + ? _value.value + : value // ignore: cast_nullable_to_non_nullable + as String?, + description: freezed == description + ? _value.description + : description // ignore: cast_nullable_to_non_nullable + as String?, + disabled: freezed == disabled + ? _value.disabled + : disabled // ignore: cast_nullable_to_non_nullable + as bool?, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$ParameterImplCopyWith<$Res> + implements $ParameterCopyWith<$Res> { + factory _$$ParameterImplCopyWith( + _$ParameterImpl value, $Res Function(_$ParameterImpl) then) = + __$$ParameterImplCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {String? id, + String? name, + String? value, + String? description, + bool? disabled}); +} + +/// @nodoc +class __$$ParameterImplCopyWithImpl<$Res> + extends _$ParameterCopyWithImpl<$Res, _$ParameterImpl> + implements _$$ParameterImplCopyWith<$Res> { + __$$ParameterImplCopyWithImpl( + _$ParameterImpl _value, $Res Function(_$ParameterImpl) _then) + : super(_value, _then); + + /// Create a copy of Parameter + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = freezed, + Object? name = freezed, + Object? value = freezed, + Object? description = freezed, + Object? disabled = freezed, + }) { + return _then(_$ParameterImpl( + id: freezed == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as String?, + name: freezed == name + ? _value.name + : name // ignore: cast_nullable_to_non_nullable + as String?, + value: freezed == value + ? _value.value + : value // ignore: cast_nullable_to_non_nullable + as String?, + description: freezed == description + ? _value.description + : description // ignore: cast_nullable_to_non_nullable + as String?, + disabled: freezed == disabled + ? _value.disabled + : disabled // ignore: cast_nullable_to_non_nullable + as bool?, + )); + } +} + +/// @nodoc + +@JsonSerializable(explicitToJson: true, anyMap: true, includeIfNull: false) +class _$ParameterImpl implements _Parameter { + const _$ParameterImpl( + {this.id, this.name, this.value, this.description, this.disabled}); + + factory _$ParameterImpl.fromJson(Map json) => + _$$ParameterImplFromJson(json); + + @override + final String? id; + @override + final String? name; + @override + final String? value; + @override + final String? description; + @override + final bool? disabled; + + @override + String toString() { + return 'Parameter(id: $id, name: $name, value: $value, description: $description, disabled: $disabled)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$ParameterImpl && + (identical(other.id, id) || other.id == id) && + (identical(other.name, name) || other.name == name) && + (identical(other.value, value) || other.value == value) && + (identical(other.description, description) || + other.description == description) && + (identical(other.disabled, disabled) || + other.disabled == disabled)); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => + Object.hash(runtimeType, id, name, value, description, disabled); + + /// Create a copy of Parameter + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$ParameterImplCopyWith<_$ParameterImpl> get copyWith => + __$$ParameterImplCopyWithImpl<_$ParameterImpl>(this, _$identity); + + @override + Map toJson() { + return _$$ParameterImplToJson( + this, + ); + } +} + +abstract class _Parameter implements Parameter { + const factory _Parameter( + {final String? id, + final String? name, + final String? value, + final String? description, + final bool? disabled}) = _$ParameterImpl; + + factory _Parameter.fromJson(Map json) = + _$ParameterImpl.fromJson; + + @override + String? get id; + @override + String? get name; + @override + String? get value; + @override + String? get description; + @override + bool? get disabled; + + /// Create a copy of Parameter + /// with the given fields replaced by the non-null parameter values. + @override + @JsonKey(includeFromJson: false, includeToJson: false) + _$$ParameterImplCopyWith<_$ParameterImpl> get copyWith => + throw _privateConstructorUsedError; +} + +Header _$HeaderFromJson(Map json) { + return _Header.fromJson(json); +} + +/// @nodoc +mixin _$Header { + String? get name => throw _privateConstructorUsedError; + String? get value => throw _privateConstructorUsedError; + + /// Serializes this Header to a JSON map. + Map toJson() => throw _privateConstructorUsedError; + + /// Create a copy of Header + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + $HeaderCopyWith
get copyWith => throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $HeaderCopyWith<$Res> { + factory $HeaderCopyWith(Header value, $Res Function(Header) then) = + _$HeaderCopyWithImpl<$Res, Header>; + @useResult + $Res call({String? name, String? value}); +} + +/// @nodoc +class _$HeaderCopyWithImpl<$Res, $Val extends Header> + implements $HeaderCopyWith<$Res> { + _$HeaderCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of Header + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? name = freezed, + Object? value = freezed, + }) { + return _then(_value.copyWith( + name: freezed == name + ? _value.name + : name // ignore: cast_nullable_to_non_nullable + as String?, + value: freezed == value + ? _value.value + : value // ignore: cast_nullable_to_non_nullable + as String?, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$HeaderImplCopyWith<$Res> implements $HeaderCopyWith<$Res> { + factory _$$HeaderImplCopyWith( + _$HeaderImpl value, $Res Function(_$HeaderImpl) then) = + __$$HeaderImplCopyWithImpl<$Res>; + @override + @useResult + $Res call({String? name, String? value}); +} + +/// @nodoc +class __$$HeaderImplCopyWithImpl<$Res> + extends _$HeaderCopyWithImpl<$Res, _$HeaderImpl> + implements _$$HeaderImplCopyWith<$Res> { + __$$HeaderImplCopyWithImpl( + _$HeaderImpl _value, $Res Function(_$HeaderImpl) _then) + : super(_value, _then); + + /// Create a copy of Header + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? name = freezed, + Object? value = freezed, + }) { + return _then(_$HeaderImpl( + name: freezed == name + ? _value.name + : name // ignore: cast_nullable_to_non_nullable + as String?, + value: freezed == value + ? _value.value + : value // ignore: cast_nullable_to_non_nullable + as String?, + )); + } +} + +/// @nodoc + +@JsonSerializable(explicitToJson: true, anyMap: true, includeIfNull: false) +class _$HeaderImpl implements _Header { + const _$HeaderImpl({this.name, this.value}); + + factory _$HeaderImpl.fromJson(Map json) => + _$$HeaderImplFromJson(json); + + @override + final String? name; + @override + final String? value; + + @override + String toString() { + return 'Header(name: $name, value: $value)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$HeaderImpl && + (identical(other.name, name) || other.name == name) && + (identical(other.value, value) || other.value == value)); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => Object.hash(runtimeType, name, value); + + /// Create a copy of Header + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$HeaderImplCopyWith<_$HeaderImpl> get copyWith => + __$$HeaderImplCopyWithImpl<_$HeaderImpl>(this, _$identity); + + @override + Map toJson() { + return _$$HeaderImplToJson( + this, + ); + } +} + +abstract class _Header implements Header { + const factory _Header({final String? name, final String? value}) = + _$HeaderImpl; + + factory _Header.fromJson(Map json) = _$HeaderImpl.fromJson; + + @override + String? get name; + @override + String? get value; + + /// Create a copy of Header + /// with the given fields replaced by the non-null parameter values. + @override + @JsonKey(includeFromJson: false, includeToJson: false) + _$$HeaderImplCopyWith<_$HeaderImpl> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/packages/insomnia/lib/models/insomnia_collection.g.dart b/packages/insomnia/lib/models/insomnia_collection.g.dart new file mode 100644 index 00000000..531f0c16 --- /dev/null +++ b/packages/insomnia/lib/models/insomnia_collection.g.dart @@ -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?) + ?.map((e) => Resource.fromJson(Map.from(e as Map))) + .toList(), + ); + +Map _$$InsomniaCollectionImplToJson( + _$InsomniaCollectionImpl instance) => + { + 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.from(json['body'] as Map)), + parameters: (json['parameters'] as List?) + ?.map((e) => Parameter.fromJson(Map.from(e as Map))) + .toList(), + headers: (json['headers'] as List?) + ?.map((e) => Header.fromJson(Map.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 _$$ResourceImplToJson(_$ResourceImpl instance) => + { + 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 _$$BodyImplToJson(_$BodyImpl instance) => + { + 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 _$$ParameterImplToJson(_$ParameterImpl instance) => + { + 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 _$$HeaderImplToJson(_$HeaderImpl instance) => + { + if (instance.name case final value?) 'name': value, + if (instance.value case final value?) 'value': value, + }; diff --git a/packages/insomnia/lib/models/models.dart b/packages/insomnia/lib/models/models.dart new file mode 100644 index 00000000..881e622e --- /dev/null +++ b/packages/insomnia/lib/models/models.dart @@ -0,0 +1 @@ +export 'insomnia_collection.dart'; \ No newline at end of file From 756c11853b6329e376901972244d186b58c28ed0 Mon Sep 17 00:00:00 2001 From: StormGear Date: Mon, 6 Jan 2025 15:05:38 +0000 Subject: [PATCH 04/42] use the insomnia collect to get the actual requests --- packages/insomnia/lib/insomnia.dart | 4 +++ .../insomnia/lib/utils/insomnia_utils.dart | 30 +++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 packages/insomnia/lib/insomnia.dart create mode 100644 packages/insomnia/lib/utils/insomnia_utils.dart diff --git a/packages/insomnia/lib/insomnia.dart b/packages/insomnia/lib/insomnia.dart new file mode 100644 index 00000000..f51712ff --- /dev/null +++ b/packages/insomnia/lib/insomnia.dart @@ -0,0 +1,4 @@ +library insomnia; + +export 'models/models.dart'; +export 'utils/insomnia_utils.dart'; diff --git a/packages/insomnia/lib/utils/insomnia_utils.dart b/packages/insomnia/lib/utils/insomnia_utils.dart new file mode 100644 index 00000000..295a13ec --- /dev/null +++ b/packages/insomnia/lib/utils/insomnia_utils.dart @@ -0,0 +1,30 @@ + + +import 'package:insomnia/insomnia.dart'; + +List<(String?, Resource)> getRequestsFromInsomniaCollection( + InsomniaCollection? ic) { + if (ic == null || ic.resources == null) { + return []; + } + List<(String?, Resource)> requests = []; + if (ic.resources!.length > 0) { + for (var i in ic.resources!) { + requests.addAll(getRequestsFromInsomniaResource(i)); + } + } + return requests; +} + +List<(String?, Resource)> getRequestsFromInsomniaResource(Resource? resource) { + if (resource == null) { + return []; + } + List<(String?, Resource)> requests = []; + if (resource.type != null || resource.type == 'request') { + requests.add((resource.name, resource)); + } else { + print('Resource type is not request'); + } + return requests; +} \ No newline at end of file From 92c559d15e38accc01c740a5547760861f16ef23 Mon Sep 17 00:00:00 2001 From: StormGear Date: Mon, 6 Jan 2025 15:06:47 +0000 Subject: [PATCH 05/42] map insomnia resources to HttpRequestModel --- .../lib/import_export/insomia_io.dart | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 packages/apidash_core/lib/import_export/insomia_io.dart diff --git a/packages/apidash_core/lib/import_export/insomia_io.dart b/packages/apidash_core/lib/import_export/insomia_io.dart new file mode 100644 index 00000000..571ba468 --- /dev/null +++ b/packages/apidash_core/lib/import_export/insomia_io.dart @@ -0,0 +1,81 @@ +import 'package:insomnia/insomnia.dart' as ins; +import 'package:seed/seed.dart'; +import '../consts.dart'; +import '../models/models.dart'; +import '../utils/utils.dart'; + +class InsomiaIO { + List<(String?, HttpRequestModel)>? getHttpRequestModelList(String content) { + content = content.trim(); + try { + final ic = ins.insomniaCollectionFromJsonStr(content); + final requests = ins.getRequestsFromInsomniaCollection(ic); + return requests + .map((req) => (req.$1, insomniaRequestToHttpRequestModel(req.$2))) + .toList(); + } catch (e) { + return null; + } + } + + HttpRequestModel insomniaRequestToHttpRequestModel(ins.Resource request) { + HTTPVerb method; + + try { + method = HTTPVerb.values.byName((request.method ?? "").toLowerCase()); + } catch (e) { + method = kDefaultHttpMethod; + } + String url = stripUrlParams(request.url ?? ""); + List headers = []; + List isHeaderEnabledList = []; + + List params = []; + List isParamEnabledList = []; + + for (var header in request.headers ?? []) { + var name = header.name ?? ""; + var value = header.value; + var activeHeader = header.name?.isNotEmpty ?? false; + headers.add(NameValueModel(name: name, value: value)); + isHeaderEnabledList.add(!activeHeader); + } + + for (var query in request.parameters ?? []) { + var name = query.name ?? ""; + var value = query.value; + var activeQuery = query.name?.isNotEmpty ?? false; + params.add(NameValueModel(name: name, value: value)); + isParamEnabledList.add(!activeQuery); + } + + ContentType bodyContentType = kDefaultContentType; + String? body; + List? formData; + if (request.body != null) { + if (request.body?.mimeType != null) { + try { + bodyContentType = ContentType.values + .byName(request.body?.mimeType ?? ""); + } catch (e) { + bodyContentType = kDefaultContentType; + } + body = request.body?.text; + } + /// TODO: Handle formdata and text + } + + return HttpRequestModel( + method: method, + url: url, + headers: headers, + params: params, + isHeaderEnabledList: isHeaderEnabledList, + isParamEnabledList: isParamEnabledList, + body: body, + bodyContentType: bodyContentType, + formData: formData, + ); + } + +} \ No newline at end of file From 16e6fc5969425086d08228451d5c5bfa6bd80243 Mon Sep 17 00:00:00 2001 From: StormGear Date: Mon, 6 Jan 2025 15:07:41 +0000 Subject: [PATCH 06/42] added CHANGELOG, LICENSE, and README to the insomnia package --- packages/insomnia/CHANGELOG.md | 3 + packages/insomnia/LICENSE | 201 +++++++++++++++++ packages/insomnia/README.md | 396 +++++++++++++++++++++++++++++++++ packages/insomnia/pubspec.yaml | 29 +++ pubspec.lock | 15 ++ 5 files changed, 644 insertions(+) create mode 100644 packages/insomnia/CHANGELOG.md create mode 100644 packages/insomnia/LICENSE create mode 100644 packages/insomnia/README.md create mode 100644 packages/insomnia/pubspec.yaml diff --git a/packages/insomnia/CHANGELOG.md b/packages/insomnia/CHANGELOG.md new file mode 100644 index 00000000..a0ba62dd --- /dev/null +++ b/packages/insomnia/CHANGELOG.md @@ -0,0 +1,3 @@ +## 0.0.1 + +- Implement fromJson object and fromJson String for Insomnia v4 json format diff --git a/packages/insomnia/LICENSE b/packages/insomnia/LICENSE new file mode 100644 index 00000000..498fbbb0 --- /dev/null +++ b/packages/insomnia/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2023 Ashita Prasad, Ankit Mahato + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/packages/insomnia/README.md b/packages/insomnia/README.md new file mode 100644 index 00000000..7681aa56 --- /dev/null +++ b/packages/insomnia/README.md @@ -0,0 +1,396 @@ +# insomnia + +Seamlessly convert Insomnia Collection Format v4 to Dart. + +Helps you bring your APIs stored in Insomnia to Dart and work with them. + +Currently, this package is being used by [API Dash](https://github.com/foss42/apidash), a beautiful open-source cross-platform (macOS, Windows, Linux, Android & iOS) API Client built using Flutter which can help you easily create & customize your API requests, visually inspect responses and generate API integration code. A lightweight alternative to postman & insomnia. + +## Usage + +### Example 1: Insomnia collection JSON string to Insomnia model + +```dart +import 'package:insomnia/insomnia.dart'; + +void main() { + // Example 1: Insomnia collection JSON string to Insomnia model + var collectionJsonStr = r''' +{ + "_type": "export", + "__export_format": 4, + "__export_date": "2025-01-05T13:05:11.752Z", + "__export_source": "insomnia.desktop.app:v10.3.0", + "resources": [ + { + "_id":"req_15f4d64ca3084a92a0680e29a958c9da", + "parentId":"fld_a2e9704c49034e36a05cdb3a233f6ebd", + "modified":1736112258432, + "created":1736111908438, + "url":"https://food-service-backend.onrender.com/api/users/", + "name":"get-with-params", + "description":"", + "method":"GET", + "body":{}, + "parameters": [ + {"id":"pair_bf0ae4f4280e440a8a591b64fd4ec4f4","name":"user_id","value":"34","description":"","disabled":false} + ], + "headers":[{"name":"User-Agent","value":"insomnia/10.3.0"}], + "authentication":{}, + "metaSortKey":-1736111908438, + "isPrivate":false, + "pathParameters":[], + "settingStoreCookies":true, + "settingSendCookies":true, + "settingDisableRenderRequestBody":false, + "settingEncodeUrl":true, + "settingRebuildPath":true, + "settingFollowRedirects": "global", + "_type":"request" + }, + { + "_id":"fld_a2e9704c49034e36a05cdb3a233f6ebd", + "parentId":"wrk_fde7dcc4f5064b74b0fd749cbf8f684a", + "modified":1736082089076, + "created":1736082089076, + "name":"APIDash-APItests", + "description":"These are test endpoints for API Dash", + "environment":{},"environmentPropertyOrder":null, + "metaSortKey":-1736082080559, + "preRequestScript":"", + "afterResponseScript":"", + "authentication":{}, + "_type":"request_group" + }, + {"_id":"wrk_fde7dcc4f5064b74b0fd749cbf8f684a", + "parentId":null, + "modified":1736082089075, + "created":1736082089075, + "name":"APIDash-APItests","description":"", + "scope":"collection","_type":"workspace"}, + { + "_id":"req_db3c393084f14369bb409afe857e390c", + "parentId":"fld_a2e9704c49034e36a05cdb3a233f6ebd", + "modified":1736082089077, + "created":1736082089077, + "url":"https://api.apidash.dev/country/codes", + "name":"test-get", + "description":"", + "method":"GET", + "body":{}, + "parameters":[], + "headers":[], + "authentication":{}, + "preRequestScript":"", + "metaSortKey":-1736082080558, + "isPrivate":false, + "afterResponseScript":"", + "settingStoreCookies":true, + "settingSendCookies":true, + "settingDisableRenderRequestBody":false, + "settingEncodeUrl":true, + "settingRebuildPath":true, + "settingFollowRedirects":"global", + "_type":"request"}, + {"_id":"req_ba718bbacd094e95a30ef3f07baa4e42", + "parentId":"fld_a2e9704c49034e36a05cdb3a233f6ebd", + "modified":1736082089078,"created":1736082089078, + "url":"https://api.apidash.dev/case/lower", + "name":"test-post", + "description":"", + "method":"POST", + "body":{"mimeType":"application/json","text":"{\n \"text\": \"Grass is green\"\n}"}, + "parameters":[], + "headers":[{"name":"Content-Type","value":"application/json"}], + "authentication":{}, + "preRequestScript":"", + "metaSortKey":-1736082080557, + "isPrivate":false, + "afterResponseScript":"", + "settingStoreCookies":true, + "settingSendCookies":true, + "settingDisableRenderRequestBody":false, + "settingEncodeUrl":true, + "settingRebuildPath":true, + "settingFollowRedirects":"global", + "_type":"request"}, + {"_id":"req_24cff90fc3c74e71a567f61d3f8e8cc1", + "parentId":"fld_a2e9704c49034e36a05cdb3a233f6ebd", + "modified":1736082089078, + "created":1736082089078, + "url":"https://reqres.in/api/users/2", + "name":"test-put", + "description":"", + "method":"PUT", + "body":{"mimeType":"application/json", + "text":"{\n \"name\": \"morpheus\",\n \"job\": \"zion resident\"\n}"}, + "parameters":[], + "headers":[{"name":"Content-Type","value":"application/json"}], + "authentication":{}, + "preRequestScript":"", + "metaSortKey":-1736082080556, + "isPrivate":false, + "afterResponseScript":"", + "settingStoreCookies":true, + "settingSendCookies":true, + "settingDisableRenderRequestBody":false, + "settingEncodeUrl":true, + "settingRebuildPath":true, + "settingFollowRedirects":"global", + "_type":"request"}, + { + "_id":"env_9d818b2866dffc9831640d91a516ea3986e16bda", + "parentId":"wrk_fde7dcc4f5064b74b0fd749cbf8f684a", + "modified":1736082095630,"created":1736082095630, + "name":"Base Environment", + "data":{},"dataPropertyOrder":null, + "color":null, + "isPrivate":false, + "metaSortKey":1736082095630, + "environmentType":"kv", + "_type":"environment" + }, + { + "_id":"jar_9d818b2866dffc9831640d91a516ea3986e16bda", + "parentId":"wrk_fde7dcc4f5064b74b0fd749cbf8f684a", + "modified":1736082095688, + "created":1736082095688, + "name":"Default Jar", + "cookies":[], + "_type":"cookie_jar" + } + ] +} +'''; + + + + var collection; + try { + collection = insomniaCollectionFromJsonStr(collectionJsonStr); + + + + print(collection.exportSource); + // insomnia.desktop.app:v10.3.0 + print(collection.resources?[3].name); + // test-get + print(collection.resources?[3].method); + // GET + print(collection.resources?[3].url); + // https://api.apidash.dev/country/codes + } catch (e) { + print(e.toString() + 'error from collection'); + } +} +``` + +### Example 2: Insomnia collection from JSON + +```dart +import 'package:insomnia/insomnia.dart'; + +void main() { + // Example 2: Insomnia collection from JSON + var collectionJson = { + "_type": "export", + "__export_format": 4, + "__export_date": "2025-01-05T13:05:11.752Z", + "__export_source": "insomnia.desktop.app:v10.3.0", + "resources": [ + { + "_id": "req_15f4d64ca3084a92a0680e29a958c9da", + "parentId": "fld_a2e9704c49034e36a05cdb3a233f6ebd", + "modified": 1736112258432, + "created": 1736111908438, + "url": "https://food-service-backend.onrender.com/api/users/", + "name": "get-with-params", + "description": "", + "method": "GET", + "body": {}, + "parameters": [ + { + "id": "pair_bf0ae4f4280e440a8a591b64fd4ec4f4", + "name": "user_id", + "value": "34", + "description": "", + "disabled": false + } + ], + "headers": [ + {"name": "User-Agent", "value": "insomnia/10.3.0"} + ], + "authentication": {}, + "metaSortKey": -1736111908438, + "isPrivate": false, + "pathParameters": [], + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, + { + "_id": "fld_a2e9704c49034e36a05cdb3a233f6ebd", + "parentId": "wrk_fde7dcc4f5064b74b0fd749cbf8f684a", + "modified": 1736082089076, + "created": 1736082089076, + "name": "APIDash-APItests", + "description": "These are test endpoints for API Dash", + "environment": {}, + "environmentPropertyOrder": null, + "metaSortKey": -1736082080559, + "preRequestScript": "", + "afterResponseScript": "", + "authentication": {}, + "_type": "request_group" + }, + { + "_id": "wrk_fde7dcc4f5064b74b0fd749cbf8f684a", + "parentId": null, + "modified": 1736082089075, + "created": 1736082089075, + "name": "APIDash-APItests", + "description": "", + "scope": "collection", + "_type": "workspace" + }, + { + "_id": "req_db3c393084f14369bb409afe857e390c", + "parentId": "fld_a2e9704c49034e36a05cdb3a233f6ebd", + "modified": 1736082089077, + "created": 1736082089077, + "url": "https://api.apidash.dev/country/codes", + "name": "test-get", + "description": "", + "method": "GET", + "body": {}, + "parameters": [], + "headers": [], + "authentication": {}, + "preRequestScript": "", + "metaSortKey": -1736082080558, + "isPrivate": false, + "afterResponseScript": "", + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, + { + "_id": "req_ba718bbacd094e95a30ef3f07baa4e42", + "parentId": "fld_a2e9704c49034e36a05cdb3a233f6ebd", + "modified": 1736082089078, + "created": 1736082089078, + "url": "https://api.apidash.dev/case/lower", + "name": "test-post", + "description": "", + "method": "POST", + "body": { + "mimeType": "application/json", + "text": "{\n \"text\": \"Grass is green\"\n}" + }, + "parameters": [], + "headers": [ + {"name": "Content-Type", "value": "application/json"} + ], + "authentication": {}, + "preRequestScript": "", + "metaSortKey": -1736082080557, + "isPrivate": false, + "afterResponseScript": "", + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, + { + "_id": "req_24cff90fc3c74e71a567f61d3f8e8cc1", + "parentId": "fld_a2e9704c49034e36a05cdb3a233f6ebd", + "modified": 1736082089078, + "created": 1736082089078, + "url": "https://reqres.in/api/users/2", + "name": "test-put", + "description": "", + "method": "PUT", + "body": { + "mimeType": "application/json", + "text": + "{\n \"name\": \"morpheus\",\n \"job\": \"zion resident\"\n}" + }, + "parameters": [], + "headers": [ + {"name": "Content-Type", "value": "application/json"} + ], + "authentication": {}, + "preRequestScript": "", + "metaSortKey": -1736082080556, + "isPrivate": false, + "afterResponseScript": "", + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, + { + "_id": "env_9d818b2866dffc9831640d91a516ea3986e16bda", + "parentId": "wrk_fde7dcc4f5064b74b0fd749cbf8f684a", + "modified": 1736082095630, + "created": 1736082095630, + "name": "Base Environment", + "data": {}, + "dataPropertyOrder": null, + "color": null, + "isPrivate": false, + "metaSortKey": 1736082095630, + "environmentType": "kv", + "_type": "environment" + }, + { + "_id": "jar_9d818b2866dffc9831640d91a516ea3986e16bda", + "parentId": "wrk_fde7dcc4f5064b74b0fd749cbf8f684a", + "modified": 1736082095688, + "created": 1736082095688, + "name": "Default Jar", + "cookies": [], + "_type": "cookie_jar" + } + ] + }; + + var collection2; + try { + collection2 = InsomniaCollection.fromJson(collectionJson); + print(collection2.exportSource); + // insomnia.desktop.app:v10.3.0 + print(collection2.resources?[3].name); + // test-get + print(collection2.resources?[3].method); + // GET + print(collection2.resources?[3].url); + // https://api.apidash.dev/country/codes + } catch (e) { + print(e.toString() + 'error from collection2'); + } +} +``` + +## Maintainer + +- Ashita Prasad ([GitHub](https://github.com/ashitaprasad), [LinkedIn](https://www.linkedin.com/in/ashitaprasad/), [X](https://x.com/ashitaprasad)) +- Papa Kofi (contributor) ([GitHub](https://github.com/StormGear), [LinkedIn](https://www.linkedin.com/in/papakofiboahen)) + +## License + +This project is licensed under the [Apache License 2.0](https://github.com/foss42/apidash/blob/main/packages/postman/LICENSE). diff --git a/packages/insomnia/pubspec.yaml b/packages/insomnia/pubspec.yaml new file mode 100644 index 00000000..e6bdceef --- /dev/null +++ b/packages/insomnia/pubspec.yaml @@ -0,0 +1,29 @@ +name: insomnia +description: Seamlessly convert Insomnia Collection Format v4 to Dart and vice versa. +version: 0.0.1 +homepage: https://github.com/foss42/apidash + +topics: + - insomnia + - api + - rest + - http + - network + +environment: + sdk: ">=3.0.0 <4.0.0" + +dependencies: + diff_match_patch: ^0.4.1 + equatable: ^2.0.7 + freezed_annotation: ^2.4.4 + json_annotation: ^4.9.0 + +dev_dependencies: + build_runner: ^2.4.13 + freezed: ^2.5.7 + json_serializable: ^6.9.0 + lints: ^4.0.0 + test: ^1.24.0 + + diff --git a/pubspec.lock b/pubspec.lock index ed80a941..9685fca8 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -339,6 +339,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.4.4" + diff_match_patch: + dependency: transitive + description: + name: diff_match_patch + sha256: "2efc9e6e8f449d0abe15be240e2c2a3bcd977c8d126cfd70598aee60af35c0a4" + url: "https://pub.dev" + source: hosted + version: "0.4.1" equatable: dependency: transitive description: @@ -764,6 +772,13 @@ packages: url: "https://pub.dev" source: hosted version: "4.3.0" + insomnia: + dependency: transitive + description: + path: "packages/insomnia" + relative: true + source: path + version: "0.0.1" integration_test: dependency: "direct dev" description: flutter From 072919aa3365123f1a7b2f496c3e097f73f169cb Mon Sep 17 00:00:00 2001 From: StormGear Date: Mon, 6 Jan 2025 15:08:01 +0000 Subject: [PATCH 07/42] example usage of the insomnia package --- .../insomnia/example/insomnia_example.dart | 365 ++++++++++++++++++ .../collection_apidash.dart | 326 ++++++++++++++++ .../test/models/collection_apidash_model.dart | 133 +++++++ 3 files changed, 824 insertions(+) create mode 100644 packages/insomnia/example/insomnia_example.dart create mode 100644 packages/insomnia/test/collection_examples.dart/collection_apidash.dart create mode 100644 packages/insomnia/test/models/collection_apidash_model.dart diff --git a/packages/insomnia/example/insomnia_example.dart b/packages/insomnia/example/insomnia_example.dart new file mode 100644 index 00000000..2947bc4c --- /dev/null +++ b/packages/insomnia/example/insomnia_example.dart @@ -0,0 +1,365 @@ +import 'package:insomnia/insomnia.dart'; + +void main() { + // Example 1: Insomnia collection JSON string to Insomnia model + var collectionJsonStr = r''' +{ + "_type": "export", + "__export_format": 4, + "__export_date": "2025-01-05T13:05:11.752Z", + "__export_source": "insomnia.desktop.app:v10.3.0", + "resources": [ + { + "_id":"req_15f4d64ca3084a92a0680e29a958c9da", + "parentId":"fld_a2e9704c49034e36a05cdb3a233f6ebd", + "modified":1736112258432, + "created":1736111908438, + "url":"https://food-service-backend.onrender.com/api/users/", + "name":"get-with-params", + "description":"", + "method":"GET", + "body":{}, + "parameters": [ + {"id":"pair_bf0ae4f4280e440a8a591b64fd4ec4f4","name":"user_id","value":"34","description":"","disabled":false} + ], + "headers":[{"name":"User-Agent","value":"insomnia/10.3.0"}], + "authentication":{}, + "metaSortKey":-1736111908438, + "isPrivate":false, + "pathParameters":[], + "settingStoreCookies":true, + "settingSendCookies":true, + "settingDisableRenderRequestBody":false, + "settingEncodeUrl":true, + "settingRebuildPath":true, + "settingFollowRedirects": "global", + "_type":"request" + }, + { + "_id":"fld_a2e9704c49034e36a05cdb3a233f6ebd", + "parentId":"wrk_fde7dcc4f5064b74b0fd749cbf8f684a", + "modified":1736082089076, + "created":1736082089076, + "name":"APIDash-APItests", + "description":"These are test endpoints for API Dash", + "environment":{},"environmentPropertyOrder":null, + "metaSortKey":-1736082080559, + "preRequestScript":"", + "afterResponseScript":"", + "authentication":{}, + "_type":"request_group" + }, +{"_id":"wrk_fde7dcc4f5064b74b0fd749cbf8f684a", +"parentId":null, +"modified":1736082089075, +"created":1736082089075, +"name":"APIDash-APItests","description":"", +"scope":"collection","_type":"workspace"}, +{ +"_id":"req_db3c393084f14369bb409afe857e390c", +"parentId":"fld_a2e9704c49034e36a05cdb3a233f6ebd", +"modified":1736082089077, +"created":1736082089077, +"url":"https://api.apidash.dev/country/codes", +"name":"test-get", +"description":"", +"method":"GET", +"body":{}, +"parameters":[], +"headers":[], +"authentication":{}, +"preRequestScript":"", +"metaSortKey":-1736082080558, +"isPrivate":false, +"afterResponseScript":"", +"settingStoreCookies":true, +"settingSendCookies":true, +"settingDisableRenderRequestBody":false, +"settingEncodeUrl":true, +"settingRebuildPath":true, +"settingFollowRedirects":"global", +"_type":"request"}, +{"_id":"req_ba718bbacd094e95a30ef3f07baa4e42", +"parentId":"fld_a2e9704c49034e36a05cdb3a233f6ebd", +"modified":1736082089078,"created":1736082089078, +"url":"https://api.apidash.dev/case/lower", +"name":"test-post", +"description":"", +"method":"POST", +"body":{"mimeType":"application/json","text":"{\n \"text\": \"Grass is green\"\n}"}, +"parameters":[], +"headers":[{"name":"Content-Type","value":"application/json"}], +"authentication":{}, +"preRequestScript":"", +"metaSortKey":-1736082080557, +"isPrivate":false, +"afterResponseScript":"", +"settingStoreCookies":true, +"settingSendCookies":true, +"settingDisableRenderRequestBody":false, +"settingEncodeUrl":true, +"settingRebuildPath":true, +"settingFollowRedirects":"global", +"_type":"request"}, +{"_id":"req_24cff90fc3c74e71a567f61d3f8e8cc1", +"parentId":"fld_a2e9704c49034e36a05cdb3a233f6ebd", +"modified":1736082089078, +"created":1736082089078, +"url":"https://reqres.in/api/users/2", +"name":"test-put", +"description":"", +"method":"PUT", +"body":{"mimeType":"application/json", +"text":"{\n \"name\": \"morpheus\",\n \"job\": \"zion resident\"\n}"}, +"parameters":[], +"headers":[{"name":"Content-Type","value":"application/json"}], +"authentication":{}, +"preRequestScript":"", +"metaSortKey":-1736082080556, +"isPrivate":false, +"afterResponseScript":"", +"settingStoreCookies":true, +"settingSendCookies":true, +"settingDisableRenderRequestBody":false, +"settingEncodeUrl":true, +"settingRebuildPath":true, +"settingFollowRedirects":"global", +"_type":"request"}, +{"_id":"env_9d818b2866dffc9831640d91a516ea3986e16bda", +"parentId":"wrk_fde7dcc4f5064b74b0fd749cbf8f684a", +"modified":1736082095630,"created":1736082095630, +"name":"Base Environment", +"data":{},"dataPropertyOrder":null, +"color":null, +"isPrivate":false, +"metaSortKey":1736082095630, +"environmentType":"kv", +"_type":"environment" +}, +{ +"_id":"jar_9d818b2866dffc9831640d91a516ea3986e16bda", +"parentId":"wrk_fde7dcc4f5064b74b0fd749cbf8f684a", +"modified":1736082095688, +"created":1736082095688, +"name":"Default Jar", +"cookies":[], +"_type":"cookie_jar" +} +] +} +'''; + + + + var collection; + try { + collection = insomniaCollectionFromJsonStr(collectionJsonStr); + + + + print(collection.exportSource); + // insomnia.desktop.app:v10.3.0 + print(collection.resources?[3].name); + // test-get + print(collection.resources?[3].method); + // GET + print(collection.resources?[3].url); + // https://api.apidash.dev/country/codes + } catch (e) { + print(e.toString() + 'error from collection'); + } + + + // Example 2: Insomnia collection from JSON + var collectionJson = { + "_type": "export", + "__export_format": 4, + "__export_date": "2025-01-05T13:05:11.752Z", + "__export_source": "insomnia.desktop.app:v10.3.0", + "resources": [ + { + "_id": "req_15f4d64ca3084a92a0680e29a958c9da", + "parentId": "fld_a2e9704c49034e36a05cdb3a233f6ebd", + "modified": 1736112258432, + "created": 1736111908438, + "url": "https://food-service-backend.onrender.com/api/users/", + "name": "get-with-params", + "description": "", + "method": "GET", + "body": {}, + "parameters": [ + { + "id": "pair_bf0ae4f4280e440a8a591b64fd4ec4f4", + "name": "user_id", + "value": "34", + "description": "", + "disabled": false + } + ], + "headers": [ + {"name": "User-Agent", "value": "insomnia/10.3.0"} + ], + "authentication": {}, + "metaSortKey": -1736111908438, + "isPrivate": false, + "pathParameters": [], + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, + { + "_id": "fld_a2e9704c49034e36a05cdb3a233f6ebd", + "parentId": "wrk_fde7dcc4f5064b74b0fd749cbf8f684a", + "modified": 1736082089076, + "created": 1736082089076, + "name": "APIDash-APItests", + "description": "These are test endpoints for API Dash", + "environment": {}, + "environmentPropertyOrder": null, + "metaSortKey": -1736082080559, + "preRequestScript": "", + "afterResponseScript": "", + "authentication": {}, + "_type": "request_group" + }, + { + "_id": "wrk_fde7dcc4f5064b74b0fd749cbf8f684a", + "parentId": null, + "modified": 1736082089075, + "created": 1736082089075, + "name": "APIDash-APItests", + "description": "", + "scope": "collection", + "_type": "workspace" + }, + { + "_id": "req_db3c393084f14369bb409afe857e390c", + "parentId": "fld_a2e9704c49034e36a05cdb3a233f6ebd", + "modified": 1736082089077, + "created": 1736082089077, + "url": "https://api.apidash.dev/country/codes", + "name": "test-get", + "description": "", + "method": "GET", + "body": {}, + "parameters": [], + "headers": [], + "authentication": {}, + "preRequestScript": "", + "metaSortKey": -1736082080558, + "isPrivate": false, + "afterResponseScript": "", + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, + { + "_id": "req_ba718bbacd094e95a30ef3f07baa4e42", + "parentId": "fld_a2e9704c49034e36a05cdb3a233f6ebd", + "modified": 1736082089078, + "created": 1736082089078, + "url": "https://api.apidash.dev/case/lower", + "name": "test-post", + "description": "", + "method": "POST", + "body": { + "mimeType": "application/json", + "text": "{\n \"text\": \"Grass is green\"\n}" + }, + "parameters": [], + "headers": [ + {"name": "Content-Type", "value": "application/json"} + ], + "authentication": {}, + "preRequestScript": "", + "metaSortKey": -1736082080557, + "isPrivate": false, + "afterResponseScript": "", + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, + { + "_id": "req_24cff90fc3c74e71a567f61d3f8e8cc1", + "parentId": "fld_a2e9704c49034e36a05cdb3a233f6ebd", + "modified": 1736082089078, + "created": 1736082089078, + "url": "https://reqres.in/api/users/2", + "name": "test-put", + "description": "", + "method": "PUT", + "body": { + "mimeType": "application/json", + "text": + "{\n \"name\": \"morpheus\",\n \"job\": \"zion resident\"\n}" + }, + "parameters": [], + "headers": [ + {"name": "Content-Type", "value": "application/json"} + ], + "authentication": {}, + "preRequestScript": "", + "metaSortKey": -1736082080556, + "isPrivate": false, + "afterResponseScript": "", + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, + { + "_id": "env_9d818b2866dffc9831640d91a516ea3986e16bda", + "parentId": "wrk_fde7dcc4f5064b74b0fd749cbf8f684a", + "modified": 1736082095630, + "created": 1736082095630, + "name": "Base Environment", + "data": {}, + "dataPropertyOrder": null, + "color": null, + "isPrivate": false, + "metaSortKey": 1736082095630, + "environmentType": "kv", + "_type": "environment" + }, + { + "_id": "jar_9d818b2866dffc9831640d91a516ea3986e16bda", + "parentId": "wrk_fde7dcc4f5064b74b0fd749cbf8f684a", + "modified": 1736082095688, + "created": 1736082095688, + "name": "Default Jar", + "cookies": [], + "_type": "cookie_jar" + } + ] + }; + + var collection2; + try { + collection2 = InsomniaCollection.fromJson(collectionJson); + print(collection2.exportSource); + // insomnia.desktop.app:v10.3.0 + print(collection2.resources?[3].name); + // test-get + print(collection2.resources?[3].method); + // GET + print(collection2.resources?[3].url); + // https://api.apidash.dev/country/codes + } catch (e) { + print(e.toString() + 'error from collection2'); + } +} diff --git a/packages/insomnia/test/collection_examples.dart/collection_apidash.dart b/packages/insomnia/test/collection_examples.dart/collection_apidash.dart new file mode 100644 index 00000000..918dcf39 --- /dev/null +++ b/packages/insomnia/test/collection_examples.dart/collection_apidash.dart @@ -0,0 +1,326 @@ +var collectionApiDashJsonStr = r''' +{ + "_type": "export", + "__export_format": 4, + "__export_date": "2025-01-05T13:05:11.752Z", + "__export_source": "insomnia.desktop.app:v10.3.0", + "resources": [ + { + "_id":"req_15f4d64ca3084a92a0680e29a958c9da", + "parentId":"fld_a2e9704c49034e36a05cdb3a233f6ebd", + "modified":1736112258432, + "created":1736111908438, + "url":"https://food-service-backend.onrender.com/api/users/", + "name":"get-with-params", + "description":"", + "method":"GET", + "body":{}, + "parameters": [{"id":"pair_bf0ae4f4280e440a8a591b64fd4ec4f4","name":"user_id","value":"34","description":"","disabled":false} + ], + "headers":[{"name":"User-Agent","value":"insomnia/10.3.0"}], + "authentication":{}, + "metaSortKey":-1736111908438, + "isPrivate":false, + "pathParameters":[], + "settingStoreCookies":true, + "settingSendCookies":true, + "settingDisableRenderRequestBody":false, + "settingEncodeUrl":true, + "settingRebuildPath":true, + "settingFollowRedirects": "global", + "_type":"request" + }, + { + "_id":"fld_a2e9704c49034e36a05cdb3a233f6ebd", + "parentId":"wrk_fde7dcc4f5064b74b0fd749cbf8f684a", + "modified":1736082089076, + "created":1736082089076, + "name":"APIDash-APItests", + "description":"These are test endpoints for API Dash", + "environment":{}, + "environmentPropertyOrder":null, + "metaSortKey":-1736082080559, + "preRequestScript":"", + "afterResponseScript":"", + "authentication":{}, + "_type":"request_group" + }, +{ +"_id":"wrk_fde7dcc4f5064b74b0fd749cbf8f684a", +"parentId":null, +"modified":1736082089075, +"created":1736082089075, +"name":"APIDash-APItests","description":"", +"scope":"collection","_type":"workspace"}, +{ +"_id":"req_db3c393084f14369bb409afe857e390c", +"parentId":"fld_a2e9704c49034e36a05cdb3a233f6ebd", +"modified":1736082089077, +"created":1736082089077, +"url":"https://api.apidash.dev/country/codes", +"name":"test-get", +"description":"", +"method":"GET", +"body":{}, +"parameters":[], +"headers":[], +"authentication":{}, +"preRequestScript":"", +"metaSortKey":-1736082080558, +"isPrivate":false, +"afterResponseScript":"", +"settingStoreCookies":true, +"settingSendCookies":true, +"settingDisableRenderRequestBody":false, +"settingEncodeUrl":true, +"settingRebuildPath":true, +"settingFollowRedirects":"global", +"_type":"request"}, +{ +"_id":"req_ba718bbacd094e95a30ef3f07baa4e42", +"parentId":"fld_a2e9704c49034e36a05cdb3a233f6ebd", +"modified":1736082089078,"created":1736082089078, +"url":"https://api.apidash.dev/case/lower", +"name":"test-post", +"description":"", +"method":"POST", +"body":{"mimeType":"application/json","text":"{\n \"text\": \"Grass is green\"\n}"}, +"parameters":[], +"headers":[{"name":"Content-Type","value":"application/json"}], +"authentication":{}, +"preRequestScript":"", +"metaSortKey":-1736082080557, +"isPrivate":false, +"afterResponseScript":"", +"settingStoreCookies":true, +"settingSendCookies":true, +"settingDisableRenderRequestBody":false, +"settingEncodeUrl":true, +"settingRebuildPath":true, +"settingFollowRedirects":"global", +"_type":"request"}, +{"_id":"req_24cff90fc3c74e71a567f61d3f8e8cc1", +"parentId":"fld_a2e9704c49034e36a05cdb3a233f6ebd", +"modified":1736082089078, +"created":1736082089078, +"url":"https://reqres.in/api/users/2", +"name":"test-put", +"description":"", +"method":"PUT", +"body":{"mimeType":"application/json", +"text":"{\n \"name\": \"morpheus\",\n \"job\": \"zion resident\"\n}"}, +"parameters":[], +"headers":[{"name":"Content-Type","value":"application/json"}], +"authentication":{}, +"preRequestScript":"", +"metaSortKey":-1736082080556, +"isPrivate":false, +"afterResponseScript":"", +"settingStoreCookies":true, +"settingSendCookies":true, +"settingDisableRenderRequestBody":false, +"settingEncodeUrl":true, +"settingRebuildPath":true, +"settingFollowRedirects":"global", +"_type":"request"}, +{ +"_id":"env_9d818b2866dffc9831640d91a516ea3986e16bda", +"parentId":"wrk_fde7dcc4f5064b74b0fd749cbf8f684a", +"modified":1736082095630,"created":1736082095630, +"name":"Base Environment", +"data":{},"dataPropertyOrder":null, +"color":null, +"isPrivate":false, +"metaSortKey":1736082095630, +"environmentType":"kv", +"_type":"environment" +}, +{ +"_id":"jar_9d818b2866dffc9831640d91a516ea3986e16bda", +"parentId":"wrk_fde7dcc4f5064b74b0fd749cbf8f684a", +"modified":1736082095688, +"created":1736082095688, +"name":"Default Jar", +"cookies":[], +"_type":"cookie_jar" +} +] +} +'''; + +var collectionApiDashJson = { + "_type": "export", + "__export_format": 4, + "__export_date": "2025-01-05T13:05:11.752Z", + "__export_source": "insomnia.desktop.app:v10.3.0", + "resources": [ + { + "_id": "req_15f4d64ca3084a92a0680e29a958c9da", + "parentId": "fld_a2e9704c49034e36a05cdb3a233f6ebd", + "modified": 1736112258432, + "created": 1736111908438, + "url": "https://food-service-backend.onrender.com/api/users/", + "name": "get-with-params", + "description": "", + "method": "GET", + "body": {}, + "parameters": [ + { + "id": "pair_bf0ae4f4280e440a8a591b64fd4ec4f4", + "name": "user_id", + "value": "34", + "description": "", + "disabled": false + } + ], + "headers": [ + {"name": "User-Agent", "value": "insomnia/10.3.0"} + ], + "authentication": {}, + "metaSortKey": -1736111908438, + "isPrivate": false, + "pathParameters": [], + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, + { + "_id": "fld_a2e9704c49034e36a05cdb3a233f6ebd", + "parentId": "wrk_fde7dcc4f5064b74b0fd749cbf8f684a", + "modified": 1736082089076, + "created": 1736082089076, + "name": "APIDash-APItests", + "description": "These are test endpoints for API Dash", + "environment": {}, + "environmentPropertyOrder": null, + "metaSortKey": -1736082080559, + "preRequestScript": "", + "afterResponseScript": "", + "authentication": {}, + "_type": "request_group" + }, + { + "_id": "wrk_fde7dcc4f5064b74b0fd749cbf8f684a", + "parentId": null, + "modified": 1736082089075, + "created": 1736082089075, + "name": "APIDash-APItests", + "description": "", + "scope": "collection", + "_type": "workspace" + }, + { + "_id": "req_db3c393084f14369bb409afe857e390c", + "parentId": "fld_a2e9704c49034e36a05cdb3a233f6ebd", + "modified": 1736082089077, + "created": 1736082089077, + "url": "https://api.apidash.dev/country/codes", + "name": "test-get", + "description": "", + "method": "GET", + "body": {}, + "parameters": [], + "headers": [], + "authentication": {}, + "preRequestScript": "", + "metaSortKey": -1736082080558, + "isPrivate": false, + "afterResponseScript": "", + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, + { + "_id": "req_ba718bbacd094e95a30ef3f07baa4e42", + "parentId": "fld_a2e9704c49034e36a05cdb3a233f6ebd", + "modified": 1736082089078, + "created": 1736082089078, + "url": "https://api.apidash.dev/case/lower", + "name": "test-post", + "description": "", + "method": "POST", + "body": { + "mimeType": "application/json", + "text": "{\n \"text\": \"Grass is green\"\n}" + }, + "parameters": [], + "headers": [ + {"name": "Content-Type", "value": "application/json"} + ], + "authentication": {}, + "preRequestScript": "", + "metaSortKey": -1736082080557, + "isPrivate": false, + "afterResponseScript": "", + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, + { + "_id": "req_24cff90fc3c74e71a567f61d3f8e8cc1", + "parentId": "fld_a2e9704c49034e36a05cdb3a233f6ebd", + "modified": 1736082089078, + "created": 1736082089078, + "url": "https://reqres.in/api/users/2", + "name": "test-put", + "description": "", + "method": "PUT", + "body": { + "mimeType": "application/json", + "text": + "{\n \"name\": \"morpheus\",\n \"job\": \"zion resident\"\n}" + }, + "parameters": [], + "headers": [ + {"name": "Content-Type", "value": "application/json"} + ], + "authentication": {}, + "preRequestScript": "", + "metaSortKey": -1736082080556, + "isPrivate": false, + "afterResponseScript": "", + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, + { + "_id": "env_9d818b2866dffc9831640d91a516ea3986e16bda", + "parentId": "wrk_fde7dcc4f5064b74b0fd749cbf8f684a", + "modified": 1736082095630, + "created": 1736082095630, + "name": "Base Environment", + "data": {}, + "dataPropertyOrder": null, + "color": null, + "isPrivate": false, + "metaSortKey": 1736082095630, + "environmentType": "kv", + "_type": "environment" + }, + { + "_id": "jar_9d818b2866dffc9831640d91a516ea3986e16bda", + "parentId": "wrk_fde7dcc4f5064b74b0fd749cbf8f684a", + "modified": 1736082095688, + "created": 1736082095688, + "name": "Default Jar", + "cookies": [], + "_type": "cookie_jar" + } + ] +}; diff --git a/packages/insomnia/test/models/collection_apidash_model.dart b/packages/insomnia/test/models/collection_apidash_model.dart new file mode 100644 index 00000000..ba792f08 --- /dev/null +++ b/packages/insomnia/test/models/collection_apidash_model.dart @@ -0,0 +1,133 @@ +import 'package:insomnia/models/models.dart'; + +var collectionApiDashModel = InsomniaCollection( + type: "export", + exportDate: "2025-01-05T13:05:11.752Z", + exportFormat: 4, + exportSource: "insomnia.desktop.app:v10.3.0", + resources: [ + Resource( + id: "req_15f4d64ca3084a92a0680e29a958c9da", + parentId: "fld_a2e9704c49034e36a05cdb3a233f6ebd", + modified: 1736112258432, + created: 1736111908438, + url: "https://food-service-backend.onrender.com/api/users/", + name: "get-with-params", + description: "", + method: "GET", + body: Body(), + parameters: [Parameter( + id: "pair_bf0ae4f4280e440a8a591b64fd4ec4f4", + name: "user_id", + value: "34", + description: "", + disabled: false, + ) + ], + headers: [ + Header( + name: "User-Agent", + value: "insomnia/10.3.0", + ) + ], + metaSortKey: -1736111908438, + isPrivate: false, + afterResponseScript: null, + settingSendCookies: true, + settingStoreCookies: true, + settingDisableRenderRequestBody: false, + settingEncodeUrl: true, + settingRebuildPath: true, + settingFollowRedirects: "global", + type: "request", + ), + Resource( + id: "req_db3c393084f14369bb409afe857e390c", + parentId: "fld_a2e9704c49034e36a05cdb3a233f6ebd", + modified: 1736082089077, + created: 1736082089077, + url: "https://api.apidash.dev/country/codes", + name: "test-get", + description: "", + method: "GET", + body: Body(), + parameters: [], + headers: [], + preRequestScript: "", + metaSortKey: -1736082080558, + isPrivate: false, + afterResponseScript: "", + settingSendCookies: true, + settingStoreCookies: true, + settingDisableRenderRequestBody: false, + settingEncodeUrl: true, + settingRebuildPath: true, + settingFollowRedirects: "global", + type: "request", + ), + Resource( + id: "req_ba718bbacd094e95a30ef3f07baa4e42", + parentId: "fld_a2e9704c49034e36a05cdb3a233f6ebd", + modified: 1736082089078, + created: 1736082089078, + url: "https://api.apidash.dev/case/lower", + name: "test-post", + description: "", + method: "POST", + body: Body( + mimeType: "application/json", + text: "{\n \"text\": \"Grass is green\"\n}", + ), + parameters: [], + headers: [ + Header( + name: "Content-Type", + value: "application/json", + ) + ], + preRequestScript: "", + metaSortKey: -1736082080557, + isPrivate: false, + afterResponseScript: "", + settingSendCookies: true, + settingStoreCookies: true, + settingDisableRenderRequestBody: false, + settingEncodeUrl: true, + settingRebuildPath: true, + settingFollowRedirects: "global", + type: "request", + ), + Resource( + id: "req_24cff90fc3c74e71a567f61d3f8e8cc1", + parentId: "fld_a2e9704c49034e36a05cdb3a233f6ebd", + modified: 1736082089078, + created: 1736082089078, + url: "https://reqres.in/api/users/2", + name: "test-put", + description: "", + method: "PUT", + body: Body( + mimeType: "application/json", + text: "{\n \"name\": \"morpheus\",\n \"job\": \"zion resident\"\n}" + ), + parameters: [], + headers: [ + Header( + name: "Content-Type", + value: "application/json", + ) + ], + preRequestScript: "", + metaSortKey: -1736082080556, + isPrivate: false, + afterResponseScript: "", + settingSendCookies: true, + settingStoreCookies: true, + settingDisableRenderRequestBody: false, + settingEncodeUrl: true, + settingRebuildPath: true, + settingFollowRedirects: "global", + type: "request", + ), + ] +); From ac29e312a8a8dc8240b7270f792a9215e40f424c Mon Sep 17 00:00:00 2001 From: StormGear Date: Mon, 6 Jan 2025 15:08:23 +0000 Subject: [PATCH 08/42] unit tests for the insomnia package --- packages/insomnia/test/insomnia_test.dart | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 packages/insomnia/test/insomnia_test.dart diff --git a/packages/insomnia/test/insomnia_test.dart b/packages/insomnia/test/insomnia_test.dart new file mode 100644 index 00000000..18617656 --- /dev/null +++ b/packages/insomnia/test/insomnia_test.dart @@ -0,0 +1,18 @@ +import 'package:insomnia/insomnia.dart'; +import 'collection_examples.dart/collection_apidash.dart'; +import 'models/collection_apidash_model.dart'; +import 'package:test/test.dart'; + +void main() { + group('Insomnia tests', () { + test('API Dash Insomnia collection from Json String', () { + expect(insomniaCollectionFromJsonStr(collectionApiDashJsonStr), collectionApiDashModel); + }); + + test('API Dash Insomnia collection from Json', () { + expect(insomniaCollectionFromJson(collectionApiDashJson), + collectionApiDashModel); + }); + + }); +} From f4eaf94de32a6eb24a6cc92e4d0206bef88410fa Mon Sep 17 00:00:00 2001 From: StormGear Date: Sun, 12 Jan 2025 13:09:22 +0000 Subject: [PATCH 09/42] made necessary name and typo corrections --- lib/consts.dart | 2 +- lib/importer/importer.dart | 2 +- packages/apidash_core/lib/import_export/import_export.dart | 2 +- .../import_export/{insomia_io.dart => insomnia_io.dart} | 7 +++++-- packages/apidash_core/pubspec.yaml | 4 ++-- packages/{insomnia => insomnia_collection}/.gitignore | 0 packages/{insomnia => insomnia_collection}/CHANGELOG.md | 0 packages/{insomnia => insomnia_collection}/LICENSE | 0 packages/{insomnia => insomnia_collection}/README.md | 4 ++-- .../analysis_options.yaml | 0 .../example/insomnia_example.dart | 3 ++- .../lib/insomnia_collection.dart} | 2 +- .../lib/models/insomnia_collection.dart | 0 .../lib/models/insomnia_collection.freezed.dart | 0 .../lib/models/insomnia_collection.g.dart | 0 .../lib/models/models.dart | 0 .../lib/utils/insomnia_utils.dart | 3 ++- packages/{insomnia => insomnia_collection}/pubspec.yaml | 4 ++-- .../test/collection_examples}/collection_apidash.dart | 0 .../test/insomnia_test.dart | 4 ++-- .../test/models/collection_apidash_model.dart | 2 +- pubspec.lock | 4 ++-- 22 files changed, 24 insertions(+), 19 deletions(-) rename packages/apidash_core/lib/import_export/{insomia_io.dart => insomnia_io.dart} (96%) rename packages/{insomnia => insomnia_collection}/.gitignore (100%) rename packages/{insomnia => insomnia_collection}/CHANGELOG.md (100%) rename packages/{insomnia => insomnia_collection}/LICENSE (100%) rename packages/{insomnia => insomnia_collection}/README.md (99%) rename packages/{insomnia => insomnia_collection}/analysis_options.yaml (100%) rename packages/{insomnia => insomnia_collection}/example/insomnia_example.dart (99%) rename packages/{insomnia/lib/insomnia.dart => insomnia_collection/lib/insomnia_collection.dart} (69%) rename packages/{insomnia => insomnia_collection}/lib/models/insomnia_collection.dart (100%) rename packages/{insomnia => insomnia_collection}/lib/models/insomnia_collection.freezed.dart (100%) rename packages/{insomnia => insomnia_collection}/lib/models/insomnia_collection.g.dart (100%) rename packages/{insomnia => insomnia_collection}/lib/models/models.dart (100%) rename packages/{insomnia => insomnia_collection}/lib/utils/insomnia_utils.dart (90%) rename packages/{insomnia => insomnia_collection}/pubspec.yaml (92%) rename packages/{insomnia/test/collection_examples.dart => insomnia_collection/test/collection_examples}/collection_apidash.dart (100%) rename packages/{insomnia => insomnia_collection}/test/insomnia_test.dart (79%) rename packages/{insomnia => insomnia_collection}/test/models/collection_apidash_model.dart (98%) diff --git a/lib/consts.dart b/lib/consts.dart index c267a471..ec042f85 100644 --- a/lib/consts.dart +++ b/lib/consts.dart @@ -142,7 +142,7 @@ enum CodegenLanguage { enum ImportFormat { curl("cURL"), postman("Postman Collection v2.1"), - insomia("Insomnia v4"); + insomnia("Insomnia v4"); const ImportFormat(this.label); final String label; diff --git a/lib/importer/importer.dart b/lib/importer/importer.dart index 3f5125a6..4d93d9be 100644 --- a/lib/importer/importer.dart +++ b/lib/importer/importer.dart @@ -12,7 +12,7 @@ class Importer { ?.map((t) => (null, t)) .toList(), ImportFormat.postman => PostmanIO().getHttpRequestModelList(content), - ImportFormat.insomia => InsomiaIO().getHttpRequestModelList(content), + ImportFormat.insomnia => InsomniaIO().getHttpRequestModelList(content), }; } } diff --git a/packages/apidash_core/lib/import_export/import_export.dart b/packages/apidash_core/lib/import_export/import_export.dart index bfa4964f..33762e50 100644 --- a/packages/apidash_core/lib/import_export/import_export.dart +++ b/packages/apidash_core/lib/import_export/import_export.dart @@ -1,3 +1,3 @@ export 'curl_io.dart'; export 'postman_io.dart'; -export 'insomia_io.dart'; +export 'insomnia_io.dart'; diff --git a/packages/apidash_core/lib/import_export/insomia_io.dart b/packages/apidash_core/lib/import_export/insomnia_io.dart similarity index 96% rename from packages/apidash_core/lib/import_export/insomia_io.dart rename to packages/apidash_core/lib/import_export/insomnia_io.dart index 571ba468..b87eeec9 100644 --- a/packages/apidash_core/lib/import_export/insomia_io.dart +++ b/packages/apidash_core/lib/import_export/insomnia_io.dart @@ -1,10 +1,13 @@ -import 'package:insomnia/insomnia.dart' as ins; import 'package:seed/seed.dart'; import '../consts.dart'; import '../models/models.dart'; import '../utils/utils.dart'; +import 'package:insomnia_collection/insomnia_collection.dart' as ins; -class InsomiaIO { + + + +class InsomniaIO { List<(String?, HttpRequestModel)>? getHttpRequestModelList(String content) { content = content.trim(); try { diff --git a/packages/apidash_core/pubspec.yaml b/packages/apidash_core/pubspec.yaml index 4b4dc38d..78c5bfb2 100644 --- a/packages/apidash_core/pubspec.yaml +++ b/packages/apidash_core/pubspec.yaml @@ -19,8 +19,8 @@ dependencies: http_parser: ^4.0.2 postman: path: ../postman - insomnia: - path: ../insomnia + insomnia_collection: + path: ../insomnia_collection seed: ^0.0.2 xml: ^6.3.0 diff --git a/packages/insomnia/.gitignore b/packages/insomnia_collection/.gitignore similarity index 100% rename from packages/insomnia/.gitignore rename to packages/insomnia_collection/.gitignore diff --git a/packages/insomnia/CHANGELOG.md b/packages/insomnia_collection/CHANGELOG.md similarity index 100% rename from packages/insomnia/CHANGELOG.md rename to packages/insomnia_collection/CHANGELOG.md diff --git a/packages/insomnia/LICENSE b/packages/insomnia_collection/LICENSE similarity index 100% rename from packages/insomnia/LICENSE rename to packages/insomnia_collection/LICENSE diff --git a/packages/insomnia/README.md b/packages/insomnia_collection/README.md similarity index 99% rename from packages/insomnia/README.md rename to packages/insomnia_collection/README.md index 7681aa56..255d890a 100644 --- a/packages/insomnia/README.md +++ b/packages/insomnia_collection/README.md @@ -11,7 +11,7 @@ Currently, this package is being used by [API Dash](https://github.com/foss42/ap ### Example 1: Insomnia collection JSON string to Insomnia model ```dart -import 'package:insomnia/insomnia.dart'; +import 'package:insomnia_collection/insomnia_collection.dart'; void main() { // Example 1: Insomnia collection JSON string to Insomnia model @@ -188,7 +188,7 @@ void main() { ### Example 2: Insomnia collection from JSON ```dart -import 'package:insomnia/insomnia.dart'; +import 'package:insomnia_collection/insomnia_collection.dart'; void main() { // Example 2: Insomnia collection from JSON diff --git a/packages/insomnia/analysis_options.yaml b/packages/insomnia_collection/analysis_options.yaml similarity index 100% rename from packages/insomnia/analysis_options.yaml rename to packages/insomnia_collection/analysis_options.yaml diff --git a/packages/insomnia/example/insomnia_example.dart b/packages/insomnia_collection/example/insomnia_example.dart similarity index 99% rename from packages/insomnia/example/insomnia_example.dart rename to packages/insomnia_collection/example/insomnia_example.dart index 2947bc4c..f9301346 100644 --- a/packages/insomnia/example/insomnia_example.dart +++ b/packages/insomnia_collection/example/insomnia_example.dart @@ -1,4 +1,5 @@ -import 'package:insomnia/insomnia.dart'; + +import 'package:insomnia_collection/insomnia_collection.dart'; void main() { // Example 1: Insomnia collection JSON string to Insomnia model diff --git a/packages/insomnia/lib/insomnia.dart b/packages/insomnia_collection/lib/insomnia_collection.dart similarity index 69% rename from packages/insomnia/lib/insomnia.dart rename to packages/insomnia_collection/lib/insomnia_collection.dart index f51712ff..66c1cef9 100644 --- a/packages/insomnia/lib/insomnia.dart +++ b/packages/insomnia_collection/lib/insomnia_collection.dart @@ -1,4 +1,4 @@ -library insomnia; +library insomnia_collection; export 'models/models.dart'; export 'utils/insomnia_utils.dart'; diff --git a/packages/insomnia/lib/models/insomnia_collection.dart b/packages/insomnia_collection/lib/models/insomnia_collection.dart similarity index 100% rename from packages/insomnia/lib/models/insomnia_collection.dart rename to packages/insomnia_collection/lib/models/insomnia_collection.dart diff --git a/packages/insomnia/lib/models/insomnia_collection.freezed.dart b/packages/insomnia_collection/lib/models/insomnia_collection.freezed.dart similarity index 100% rename from packages/insomnia/lib/models/insomnia_collection.freezed.dart rename to packages/insomnia_collection/lib/models/insomnia_collection.freezed.dart diff --git a/packages/insomnia/lib/models/insomnia_collection.g.dart b/packages/insomnia_collection/lib/models/insomnia_collection.g.dart similarity index 100% rename from packages/insomnia/lib/models/insomnia_collection.g.dart rename to packages/insomnia_collection/lib/models/insomnia_collection.g.dart diff --git a/packages/insomnia/lib/models/models.dart b/packages/insomnia_collection/lib/models/models.dart similarity index 100% rename from packages/insomnia/lib/models/models.dart rename to packages/insomnia_collection/lib/models/models.dart diff --git a/packages/insomnia/lib/utils/insomnia_utils.dart b/packages/insomnia_collection/lib/utils/insomnia_utils.dart similarity index 90% rename from packages/insomnia/lib/utils/insomnia_utils.dart rename to packages/insomnia_collection/lib/utils/insomnia_utils.dart index 295a13ec..ca3d9810 100644 --- a/packages/insomnia/lib/utils/insomnia_utils.dart +++ b/packages/insomnia_collection/lib/utils/insomnia_utils.dart @@ -1,6 +1,7 @@ -import 'package:insomnia/insomnia.dart'; + +import 'package:insomnia_collection/models/insomnia_collection.dart'; List<(String?, Resource)> getRequestsFromInsomniaCollection( InsomniaCollection? ic) { diff --git a/packages/insomnia/pubspec.yaml b/packages/insomnia_collection/pubspec.yaml similarity index 92% rename from packages/insomnia/pubspec.yaml rename to packages/insomnia_collection/pubspec.yaml index e6bdceef..5504badd 100644 --- a/packages/insomnia/pubspec.yaml +++ b/packages/insomnia_collection/pubspec.yaml @@ -1,5 +1,5 @@ -name: insomnia -description: Seamlessly convert Insomnia Collection Format v4 to Dart and vice versa. +name: insomnia_collection +description: Seamlessly convert Insomnia Collection Format v4 to Dart. version: 0.0.1 homepage: https://github.com/foss42/apidash diff --git a/packages/insomnia/test/collection_examples.dart/collection_apidash.dart b/packages/insomnia_collection/test/collection_examples/collection_apidash.dart similarity index 100% rename from packages/insomnia/test/collection_examples.dart/collection_apidash.dart rename to packages/insomnia_collection/test/collection_examples/collection_apidash.dart diff --git a/packages/insomnia/test/insomnia_test.dart b/packages/insomnia_collection/test/insomnia_test.dart similarity index 79% rename from packages/insomnia/test/insomnia_test.dart rename to packages/insomnia_collection/test/insomnia_test.dart index 18617656..808fe906 100644 --- a/packages/insomnia/test/insomnia_test.dart +++ b/packages/insomnia_collection/test/insomnia_test.dart @@ -1,5 +1,5 @@ -import 'package:insomnia/insomnia.dart'; -import 'collection_examples.dart/collection_apidash.dart'; +import 'package:insomnia_collection/insomnia_collection.dart'; +import 'collection_examples/collection_apidash.dart'; import 'models/collection_apidash_model.dart'; import 'package:test/test.dart'; diff --git a/packages/insomnia/test/models/collection_apidash_model.dart b/packages/insomnia_collection/test/models/collection_apidash_model.dart similarity index 98% rename from packages/insomnia/test/models/collection_apidash_model.dart rename to packages/insomnia_collection/test/models/collection_apidash_model.dart index ba792f08..f9816028 100644 --- a/packages/insomnia/test/models/collection_apidash_model.dart +++ b/packages/insomnia_collection/test/models/collection_apidash_model.dart @@ -1,4 +1,4 @@ -import 'package:insomnia/models/models.dart'; +import 'package:insomnia_collection/models/models.dart'; var collectionApiDashModel = InsomniaCollection( type: "export", diff --git a/pubspec.lock b/pubspec.lock index 9685fca8..5d3b2a79 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -772,10 +772,10 @@ packages: url: "https://pub.dev" source: hosted version: "4.3.0" - insomnia: + insomnia_collection: dependency: transitive description: - path: "packages/insomnia" + path: "packages/insomnia_collection" relative: true source: path version: "0.0.1" From f241fc5ffc0ac605826456a8d7deb90898039146 Mon Sep 17 00:00:00 2001 From: StormGear Date: Sun, 12 Jan 2025 13:30:46 +0000 Subject: [PATCH 10/42] Included a field which can help determine the values of isHeaderEnabledList and isParamEnabledList to the Header and Parameter Model --- .../lib/import_export/insomnia_io.dart | 6 +-- .../lib/models/insomnia_collection.dart | 1 + .../models/insomnia_collection.freezed.dart | 41 +++++++++++++------ .../lib/models/insomnia_collection.g.dart | 2 + 4 files changed, 35 insertions(+), 15 deletions(-) diff --git a/packages/apidash_core/lib/import_export/insomnia_io.dart b/packages/apidash_core/lib/import_export/insomnia_io.dart index b87eeec9..bbbce1a1 100644 --- a/packages/apidash_core/lib/import_export/insomnia_io.dart +++ b/packages/apidash_core/lib/import_export/insomnia_io.dart @@ -38,8 +38,8 @@ class InsomniaIO { for (var header in request.headers ?? []) { var name = header.name ?? ""; - var value = header.value; - var activeHeader = header.name?.isNotEmpty ?? false; + var value = header.value ?? ""; + var activeHeader = header.disabled ?? false; headers.add(NameValueModel(name: name, value: value)); isHeaderEnabledList.add(!activeHeader); } @@ -47,7 +47,7 @@ class InsomniaIO { for (var query in request.parameters ?? []) { var name = query.name ?? ""; var value = query.value; - var activeQuery = query.name?.isNotEmpty ?? false; + var activeQuery = query.disabled ?? false; params.add(NameValueModel(name: name, value: value)); isParamEnabledList.add(!activeQuery); } diff --git a/packages/insomnia_collection/lib/models/insomnia_collection.dart b/packages/insomnia_collection/lib/models/insomnia_collection.dart index f5236a00..d35797b2 100644 --- a/packages/insomnia_collection/lib/models/insomnia_collection.dart +++ b/packages/insomnia_collection/lib/models/insomnia_collection.dart @@ -125,6 +125,7 @@ class Header with _$Header { const factory Header({ String? name, String? value, + bool? disabled, }) = _Header; factory Header.fromJson(Map json) => _$HeaderFromJson(json); diff --git a/packages/insomnia_collection/lib/models/insomnia_collection.freezed.dart b/packages/insomnia_collection/lib/models/insomnia_collection.freezed.dart index d2085f88..ffde31d4 100644 --- a/packages/insomnia_collection/lib/models/insomnia_collection.freezed.dart +++ b/packages/insomnia_collection/lib/models/insomnia_collection.freezed.dart @@ -292,8 +292,7 @@ mixin _$Resource { String? get method => throw _privateConstructorUsedError; Body? get body => throw _privateConstructorUsedError; List? get parameters => throw _privateConstructorUsedError; - List
? get headers => - throw _privateConstructorUsedError; // List? authentication, + List
? get headers => throw _privateConstructorUsedError; String? get preRequestScript => throw _privateConstructorUsedError; num? get metaSortKey => throw _privateConstructorUsedError; bool? get isPrivate => throw _privateConstructorUsedError; @@ -735,7 +734,6 @@ class _$ResourceImpl implements _Resource { return EqualUnmodifiableListView(value); } -// List? authentication, @override final String? preRequestScript; @override @@ -905,7 +903,7 @@ abstract class _Resource implements Resource { @override List? get parameters; @override - List
? get headers; // List? authentication, + List
? get headers; @override String? get preRequestScript; @override @@ -1341,6 +1339,7 @@ Header _$HeaderFromJson(Map json) { mixin _$Header { String? get name => throw _privateConstructorUsedError; String? get value => throw _privateConstructorUsedError; + bool? get disabled => throw _privateConstructorUsedError; /// Serializes this Header to a JSON map. Map toJson() => throw _privateConstructorUsedError; @@ -1356,7 +1355,7 @@ abstract class $HeaderCopyWith<$Res> { factory $HeaderCopyWith(Header value, $Res Function(Header) then) = _$HeaderCopyWithImpl<$Res, Header>; @useResult - $Res call({String? name, String? value}); + $Res call({String? name, String? value, bool? disabled}); } /// @nodoc @@ -1376,6 +1375,7 @@ class _$HeaderCopyWithImpl<$Res, $Val extends Header> $Res call({ Object? name = freezed, Object? value = freezed, + Object? disabled = freezed, }) { return _then(_value.copyWith( name: freezed == name @@ -1386,6 +1386,10 @@ class _$HeaderCopyWithImpl<$Res, $Val extends Header> ? _value.value : value // ignore: cast_nullable_to_non_nullable as String?, + disabled: freezed == disabled + ? _value.disabled + : disabled // ignore: cast_nullable_to_non_nullable + as bool?, ) as $Val); } } @@ -1397,7 +1401,7 @@ abstract class _$$HeaderImplCopyWith<$Res> implements $HeaderCopyWith<$Res> { __$$HeaderImplCopyWithImpl<$Res>; @override @useResult - $Res call({String? name, String? value}); + $Res call({String? name, String? value, bool? disabled}); } /// @nodoc @@ -1415,6 +1419,7 @@ class __$$HeaderImplCopyWithImpl<$Res> $Res call({ Object? name = freezed, Object? value = freezed, + Object? disabled = freezed, }) { return _then(_$HeaderImpl( name: freezed == name @@ -1425,6 +1430,10 @@ class __$$HeaderImplCopyWithImpl<$Res> ? _value.value : value // ignore: cast_nullable_to_non_nullable as String?, + disabled: freezed == disabled + ? _value.disabled + : disabled // ignore: cast_nullable_to_non_nullable + as bool?, )); } } @@ -1433,7 +1442,7 @@ class __$$HeaderImplCopyWithImpl<$Res> @JsonSerializable(explicitToJson: true, anyMap: true, includeIfNull: false) class _$HeaderImpl implements _Header { - const _$HeaderImpl({this.name, this.value}); + const _$HeaderImpl({this.name, this.value, this.disabled}); factory _$HeaderImpl.fromJson(Map json) => _$$HeaderImplFromJson(json); @@ -1442,10 +1451,12 @@ class _$HeaderImpl implements _Header { final String? name; @override final String? value; + @override + final bool? disabled; @override String toString() { - return 'Header(name: $name, value: $value)'; + return 'Header(name: $name, value: $value, disabled: $disabled)'; } @override @@ -1454,12 +1465,14 @@ class _$HeaderImpl implements _Header { (other.runtimeType == runtimeType && other is _$HeaderImpl && (identical(other.name, name) || other.name == name) && - (identical(other.value, value) || other.value == value)); + (identical(other.value, value) || other.value == value) && + (identical(other.disabled, disabled) || + other.disabled == disabled)); } @JsonKey(includeFromJson: false, includeToJson: false) @override - int get hashCode => Object.hash(runtimeType, name, value); + int get hashCode => Object.hash(runtimeType, name, value, disabled); /// Create a copy of Header /// with the given fields replaced by the non-null parameter values. @@ -1478,8 +1491,10 @@ class _$HeaderImpl implements _Header { } abstract class _Header implements Header { - const factory _Header({final String? name, final String? value}) = - _$HeaderImpl; + const factory _Header( + {final String? name, + final String? value, + final bool? disabled}) = _$HeaderImpl; factory _Header.fromJson(Map json) = _$HeaderImpl.fromJson; @@ -1487,6 +1502,8 @@ abstract class _Header implements Header { String? get name; @override String? get value; + @override + bool? get disabled; /// Create a copy of Header /// with the given fields replaced by the non-null parameter values. diff --git a/packages/insomnia_collection/lib/models/insomnia_collection.g.dart b/packages/insomnia_collection/lib/models/insomnia_collection.g.dart index 531f0c16..947de2bc 100644 --- a/packages/insomnia_collection/lib/models/insomnia_collection.g.dart +++ b/packages/insomnia_collection/lib/models/insomnia_collection.g.dart @@ -128,10 +128,12 @@ Map _$$ParameterImplToJson(_$ParameterImpl instance) => _$HeaderImpl _$$HeaderImplFromJson(Map json) => _$HeaderImpl( name: json['name'] as String?, value: json['value'] as String?, + disabled: json['disabled'] as bool?, ); Map _$$HeaderImplToJson(_$HeaderImpl instance) => { if (instance.name case final value?) 'name': value, if (instance.value case final value?) 'value': value, + if (instance.disabled case final value?) 'disabled': value, }; From 7bc8fddf2fe8eb9031688f2951fa2a62865d8f18 Mon Sep 17 00:00:00 2001 From: StormGear Date: Sun, 12 Jan 2025 18:51:05 +0000 Subject: [PATCH 11/42] added support for formdata and text --- .../lib/import_export/insomnia_io.dart | 38 ++- .../lib/models/insomnia_collection.dart | 19 ++ .../models/insomnia_collection.freezed.dart | 256 +++++++++++++++++- .../lib/models/insomnia_collection.g.dart | 20 ++ 4 files changed, 318 insertions(+), 15 deletions(-) diff --git a/packages/apidash_core/lib/import_export/insomnia_io.dart b/packages/apidash_core/lib/import_export/insomnia_io.dart index bbbce1a1..6b5e1e48 100644 --- a/packages/apidash_core/lib/import_export/insomnia_io.dart +++ b/packages/apidash_core/lib/import_export/insomnia_io.dart @@ -4,9 +4,6 @@ import '../models/models.dart'; import '../utils/utils.dart'; import 'package:insomnia_collection/insomnia_collection.dart' as ins; - - - class InsomniaIO { List<(String?, HttpRequestModel)>? getHttpRequestModelList(String content) { content = content.trim(); @@ -58,13 +55,41 @@ class InsomniaIO { if (request.body != null) { if (request.body?.mimeType != null) { try { - bodyContentType = ContentType.values - .byName(request.body?.mimeType ?? ""); + if (request.body?.mimeType == 'text/plain') { + bodyContentType = ContentType.text; + } else if (request.body?.mimeType == 'application/json') { + bodyContentType = ContentType.json; + } else if (request.body?.mimeType == 'multipart/form-data') { + bodyContentType = ContentType.formdata; + formData = []; + for (var fd in request.body?.params ?? []) { + var name = fd.name ?? ""; + FormDataType formDataType; + try { + formDataType = FormDataType.values.byName(fd.type ?? ""); + } catch (e) { + formDataType = FormDataType.text; + } + var value = switch (formDataType) { + FormDataType.text => fd.value ?? "", + FormDataType.file => fd.src ?? "" + }; + formData.add(FormDataModel( + name: name, + value: value, + type: formDataType, + )); + } + } else { + bodyContentType = + ContentType.values.byName(request.body?.mimeType ?? ""); + } } catch (e) { bodyContentType = kDefaultContentType; } body = request.body?.text; } + /// TODO: Handle formdata and text } @@ -80,5 +105,4 @@ class InsomniaIO { formData: formData, ); } - -} \ No newline at end of file +} diff --git a/packages/insomnia_collection/lib/models/insomnia_collection.dart b/packages/insomnia_collection/lib/models/insomnia_collection.dart index d35797b2..adc9e706 100644 --- a/packages/insomnia_collection/lib/models/insomnia_collection.dart +++ b/packages/insomnia_collection/lib/models/insomnia_collection.dart @@ -91,11 +91,30 @@ class Body with _$Body { const factory Body({ String? mimeType, String? text, + List? params, }) = _Body; factory Body.fromJson(Map json) => _$BodyFromJson(json); } +@freezed +class Formdatum with _$Formdatum { + @JsonSerializable( + explicitToJson: true, + anyMap: true, + includeIfNull: false, + ) + const factory Formdatum({ + String? name, + String? value, + String? type, + @JsonKey(name: 'fileName') String? src, + }) = _Formdatum; + + factory Formdatum.fromJson(Map json) => + _$FormdatumFromJson(json); +} + @freezed class Parameter with _$Parameter { @JsonSerializable( diff --git a/packages/insomnia_collection/lib/models/insomnia_collection.freezed.dart b/packages/insomnia_collection/lib/models/insomnia_collection.freezed.dart index ffde31d4..ea455522 100644 --- a/packages/insomnia_collection/lib/models/insomnia_collection.freezed.dart +++ b/packages/insomnia_collection/lib/models/insomnia_collection.freezed.dart @@ -944,6 +944,7 @@ Body _$BodyFromJson(Map json) { mixin _$Body { String? get mimeType => throw _privateConstructorUsedError; String? get text => throw _privateConstructorUsedError; + List? get params => throw _privateConstructorUsedError; /// Serializes this Body to a JSON map. Map toJson() => throw _privateConstructorUsedError; @@ -959,7 +960,7 @@ abstract class $BodyCopyWith<$Res> { factory $BodyCopyWith(Body value, $Res Function(Body) then) = _$BodyCopyWithImpl<$Res, Body>; @useResult - $Res call({String? mimeType, String? text}); + $Res call({String? mimeType, String? text, List? params}); } /// @nodoc @@ -979,6 +980,7 @@ class _$BodyCopyWithImpl<$Res, $Val extends Body> $Res call({ Object? mimeType = freezed, Object? text = freezed, + Object? params = freezed, }) { return _then(_value.copyWith( mimeType: freezed == mimeType @@ -989,6 +991,10 @@ class _$BodyCopyWithImpl<$Res, $Val extends Body> ? _value.text : text // ignore: cast_nullable_to_non_nullable as String?, + params: freezed == params + ? _value.params + : params // ignore: cast_nullable_to_non_nullable + as List?, ) as $Val); } } @@ -1000,7 +1006,7 @@ abstract class _$$BodyImplCopyWith<$Res> implements $BodyCopyWith<$Res> { __$$BodyImplCopyWithImpl<$Res>; @override @useResult - $Res call({String? mimeType, String? text}); + $Res call({String? mimeType, String? text, List? params}); } /// @nodoc @@ -1017,6 +1023,7 @@ class __$$BodyImplCopyWithImpl<$Res> $Res call({ Object? mimeType = freezed, Object? text = freezed, + Object? params = freezed, }) { return _then(_$BodyImpl( mimeType: freezed == mimeType @@ -1027,6 +1034,10 @@ class __$$BodyImplCopyWithImpl<$Res> ? _value.text : text // ignore: cast_nullable_to_non_nullable as String?, + params: freezed == params + ? _value._params + : params // ignore: cast_nullable_to_non_nullable + as List?, )); } } @@ -1035,7 +1046,8 @@ class __$$BodyImplCopyWithImpl<$Res> @JsonSerializable(explicitToJson: true, anyMap: true, includeIfNull: false) class _$BodyImpl implements _Body { - const _$BodyImpl({this.mimeType, this.text}); + const _$BodyImpl({this.mimeType, this.text, final List? params}) + : _params = params; factory _$BodyImpl.fromJson(Map json) => _$$BodyImplFromJson(json); @@ -1044,10 +1056,19 @@ class _$BodyImpl implements _Body { final String? mimeType; @override final String? text; + final List? _params; + @override + List? get params { + final value = _params; + if (value == null) return null; + if (_params is EqualUnmodifiableListView) return _params; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(value); + } @override String toString() { - return 'Body(mimeType: $mimeType, text: $text)'; + return 'Body(mimeType: $mimeType, text: $text, params: $params)'; } @override @@ -1057,12 +1078,14 @@ class _$BodyImpl implements _Body { other is _$BodyImpl && (identical(other.mimeType, mimeType) || other.mimeType == mimeType) && - (identical(other.text, text) || other.text == text)); + (identical(other.text, text) || other.text == text) && + const DeepCollectionEquality().equals(other._params, _params)); } @JsonKey(includeFromJson: false, includeToJson: false) @override - int get hashCode => Object.hash(runtimeType, mimeType, text); + int get hashCode => Object.hash(runtimeType, mimeType, text, + const DeepCollectionEquality().hash(_params)); /// Create a copy of Body /// with the given fields replaced by the non-null parameter values. @@ -1081,8 +1104,10 @@ class _$BodyImpl implements _Body { } abstract class _Body implements Body { - const factory _Body({final String? mimeType, final String? text}) = - _$BodyImpl; + const factory _Body( + {final String? mimeType, + final String? text, + final List? params}) = _$BodyImpl; factory _Body.fromJson(Map json) = _$BodyImpl.fromJson; @@ -1090,6 +1115,8 @@ abstract class _Body implements Body { String? get mimeType; @override String? get text; + @override + List? get params; /// Create a copy of Body /// with the given fields replaced by the non-null parameter values. @@ -1099,6 +1126,219 @@ abstract class _Body implements Body { throw _privateConstructorUsedError; } +Formdatum _$FormdatumFromJson(Map json) { + return _Formdatum.fromJson(json); +} + +/// @nodoc +mixin _$Formdatum { + String? get name => throw _privateConstructorUsedError; + String? get value => throw _privateConstructorUsedError; + String? get type => throw _privateConstructorUsedError; + @JsonKey(name: 'fileName') + String? get src => throw _privateConstructorUsedError; + + /// Serializes this Formdatum to a JSON map. + Map toJson() => throw _privateConstructorUsedError; + + /// Create a copy of Formdatum + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + $FormdatumCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $FormdatumCopyWith<$Res> { + factory $FormdatumCopyWith(Formdatum value, $Res Function(Formdatum) then) = + _$FormdatumCopyWithImpl<$Res, Formdatum>; + @useResult + $Res call( + {String? name, + String? value, + String? type, + @JsonKey(name: 'fileName') String? src}); +} + +/// @nodoc +class _$FormdatumCopyWithImpl<$Res, $Val extends Formdatum> + implements $FormdatumCopyWith<$Res> { + _$FormdatumCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of Formdatum + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? name = freezed, + Object? value = freezed, + Object? type = freezed, + Object? src = freezed, + }) { + return _then(_value.copyWith( + name: freezed == name + ? _value.name + : name // ignore: cast_nullable_to_non_nullable + as String?, + value: freezed == value + ? _value.value + : value // ignore: cast_nullable_to_non_nullable + as String?, + type: freezed == type + ? _value.type + : type // ignore: cast_nullable_to_non_nullable + as String?, + src: freezed == src + ? _value.src + : src // ignore: cast_nullable_to_non_nullable + as String?, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$FormdatumImplCopyWith<$Res> + implements $FormdatumCopyWith<$Res> { + factory _$$FormdatumImplCopyWith( + _$FormdatumImpl value, $Res Function(_$FormdatumImpl) then) = + __$$FormdatumImplCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {String? name, + String? value, + String? type, + @JsonKey(name: 'fileName') String? src}); +} + +/// @nodoc +class __$$FormdatumImplCopyWithImpl<$Res> + extends _$FormdatumCopyWithImpl<$Res, _$FormdatumImpl> + implements _$$FormdatumImplCopyWith<$Res> { + __$$FormdatumImplCopyWithImpl( + _$FormdatumImpl _value, $Res Function(_$FormdatumImpl) _then) + : super(_value, _then); + + /// Create a copy of Formdatum + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? name = freezed, + Object? value = freezed, + Object? type = freezed, + Object? src = freezed, + }) { + return _then(_$FormdatumImpl( + name: freezed == name + ? _value.name + : name // ignore: cast_nullable_to_non_nullable + as String?, + value: freezed == value + ? _value.value + : value // ignore: cast_nullable_to_non_nullable + as String?, + type: freezed == type + ? _value.type + : type // ignore: cast_nullable_to_non_nullable + as String?, + src: freezed == src + ? _value.src + : src // ignore: cast_nullable_to_non_nullable + as String?, + )); + } +} + +/// @nodoc + +@JsonSerializable(explicitToJson: true, anyMap: true, includeIfNull: false) +class _$FormdatumImpl implements _Formdatum { + const _$FormdatumImpl( + {this.name, this.value, this.type, @JsonKey(name: 'fileName') this.src}); + + factory _$FormdatumImpl.fromJson(Map json) => + _$$FormdatumImplFromJson(json); + + @override + final String? name; + @override + final String? value; + @override + final String? type; + @override + @JsonKey(name: 'fileName') + final String? src; + + @override + String toString() { + return 'Formdatum(name: $name, value: $value, type: $type, src: $src)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$FormdatumImpl && + (identical(other.name, name) || other.name == name) && + (identical(other.value, value) || other.value == value) && + (identical(other.type, type) || other.type == type) && + (identical(other.src, src) || other.src == src)); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => Object.hash(runtimeType, name, value, type, src); + + /// Create a copy of Formdatum + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$FormdatumImplCopyWith<_$FormdatumImpl> get copyWith => + __$$FormdatumImplCopyWithImpl<_$FormdatumImpl>(this, _$identity); + + @override + Map toJson() { + return _$$FormdatumImplToJson( + this, + ); + } +} + +abstract class _Formdatum implements Formdatum { + const factory _Formdatum( + {final String? name, + final String? value, + final String? type, + @JsonKey(name: 'fileName') final String? src}) = _$FormdatumImpl; + + factory _Formdatum.fromJson(Map json) = + _$FormdatumImpl.fromJson; + + @override + String? get name; + @override + String? get value; + @override + String? get type; + @override + @JsonKey(name: 'fileName') + String? get src; + + /// Create a copy of Formdatum + /// with the given fields replaced by the non-null parameter values. + @override + @JsonKey(includeFromJson: false, includeToJson: false) + _$$FormdatumImplCopyWith<_$FormdatumImpl> get copyWith => + throw _privateConstructorUsedError; +} + Parameter _$ParameterFromJson(Map json) { return _Parameter.fromJson(json); } diff --git a/packages/insomnia_collection/lib/models/insomnia_collection.g.dart b/packages/insomnia_collection/lib/models/insomnia_collection.g.dart index 947de2bc..0e279c5a 100644 --- a/packages/insomnia_collection/lib/models/insomnia_collection.g.dart +++ b/packages/insomnia_collection/lib/models/insomnia_collection.g.dart @@ -100,12 +100,32 @@ Map _$$ResourceImplToJson(_$ResourceImpl instance) => _$BodyImpl _$$BodyImplFromJson(Map json) => _$BodyImpl( mimeType: json['mimeType'] as String?, text: json['text'] as String?, + params: (json['params'] as List?) + ?.map((e) => Formdatum.fromJson(Map.from(e as Map))) + .toList(), ); Map _$$BodyImplToJson(_$BodyImpl instance) => { if (instance.mimeType case final value?) 'mimeType': value, if (instance.text case final value?) 'text': value, + if (instance.params?.map((e) => e.toJson()).toList() case final value?) + 'params': value, + }; + +_$FormdatumImpl _$$FormdatumImplFromJson(Map json) => _$FormdatumImpl( + name: json['name'] as String?, + value: json['value'] as String?, + type: json['type'] as String?, + src: json['fileName'] as String?, + ); + +Map _$$FormdatumImplToJson(_$FormdatumImpl instance) => + { + 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.src case final value?) 'fileName': value, }; _$ParameterImpl _$$ParameterImplFromJson(Map json) => _$ParameterImpl( From 180fd59a1fb48471238b353a5f103cef5e1558e5 Mon Sep 17 00:00:00 2001 From: StormGear Date: Thu, 30 Jan 2025 15:39:45 +0000 Subject: [PATCH 12/42] add environment when insomia v4 is imported --- lib/importer/import_dialog.dart | 24 +- lib/importer/importer.dart | 12 + lib/screens/envvar/environments_pane.dart | 1 + lib/utils/envvar_utils.dart | 43 ++ .../lib/import_export/insomnia_io.dart | 18 +- .../lib/models/insomnia_collection.dart | 22 +- .../lib/models/insomnia_environment.dart | 60 +++ .../models/insomnia_environment.freezed.dart | 496 ++++++++++++++++++ .../lib/models/insomnia_environment.g.dart | 47 ++ .../lib/utils/insomnia_utils.dart | 18 +- pubspec.lock | 2 +- pubspec.yaml | 2 + 12 files changed, 737 insertions(+), 8 deletions(-) create mode 100644 packages/insomnia_collection/lib/models/insomnia_environment.dart create mode 100644 packages/insomnia_collection/lib/models/insomnia_environment.freezed.dart create mode 100644 packages/insomnia_collection/lib/models/insomnia_environment.g.dart diff --git a/lib/importer/import_dialog.dart b/lib/importer/import_dialog.dart index a8d54366..51a0ed9e 100644 --- a/lib/importer/import_dialog.dart +++ b/lib/importer/import_dialog.dart @@ -1,3 +1,4 @@ +import 'package:apidash/utils/envvar_utils.dart'; import 'package:apidash_design_system/apidash_design_system.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; @@ -10,9 +11,6 @@ void importToCollectionPane( WidgetRef ref, ScaffoldMessengerState sm, ) { - // TODO: The dialog must have a feature to paste contents in a text field - // Also, a mechanism can be added where on importing a file it shows the - // contents in the text field and then the user presses ok to add it to collection showImportDialog( context: context, importFormat: ref.watch(importFormatStateProvider), @@ -26,6 +24,26 @@ void importToCollectionPane( sm.hideCurrentSnackBar(); file.readAsString().then( (content) { + kEnvImporter + .getInsomniaEnvironment(importFormatType, content) + .then((environment) { + debugPrint('Environment: $environment'); + debugPrint('Environment values: ${environment?.resources}'); + + if (environment != null) { + if (environment.resources == null || + environment.resources!.isEmpty) { + sm.showSnackBar(getSnackBar("No environment variables imported", + small: false)); + } else { + var env = createNewEnvironment(ref, environment); + + sm.showSnackBar(getSnackBar( + "Successfully imported ${env.length} environment variables", + small: false)); + } + } + }); kImporter .getHttpRequestModelList(importFormatType, content) .then((importedRequestModels) { diff --git a/lib/importer/importer.dart b/lib/importer/importer.dart index 4d93d9be..3d649947 100644 --- a/lib/importer/importer.dart +++ b/lib/importer/importer.dart @@ -1,5 +1,6 @@ import 'package:apidash/consts.dart'; import 'package:apidash_core/apidash_core.dart'; +import 'package:insomnia_collection/models/insomnia_environment.dart'; class Importer { Future?> getHttpRequestModelList( @@ -17,4 +18,15 @@ class Importer { } } +class EnvImporter { + Future getInsomniaEnvironment( + ImportFormat fileType, String content) async { + return switch (fileType) { + ImportFormat.insomnia => InsomniaIO().getInsomiaEnvironment(content), + _ => null + }; + } +} + final kImporter = Importer(); +final kEnvImporter = EnvImporter(); diff --git a/lib/screens/envvar/environments_pane.dart b/lib/screens/envvar/environments_pane.dart index 18bd2053..74ddf363 100644 --- a/lib/screens/envvar/environments_pane.dart +++ b/lib/screens/envvar/environments_pane.dart @@ -26,6 +26,7 @@ class EnvironmentsPane extends ConsumerWidget { ref .read(environmentsStateNotifierProvider.notifier) .addEnvironment(); + // createNewEnvironment(ref); }, ), kVSpacer10, diff --git a/lib/utils/envvar_utils.dart b/lib/utils/envvar_utils.dart index 620b8f4a..3a884cfe 100644 --- a/lib/utils/envvar_utils.dart +++ b/lib/utils/envvar_utils.dart @@ -1,6 +1,49 @@ +import 'package:apidash/providers/environment_providers.dart'; import 'package:apidash_core/apidash_core.dart'; import 'package:apidash/consts.dart'; import 'package:apidash/models/models.dart'; +import 'package:flutter/material.dart'; +import 'package:hooks_riverpod/hooks_riverpod.dart'; +import 'package:insomnia_collection/models/insomnia_environment.dart'; + +List createNewEnvironment(WidgetRef ref, InsomniaEnvironment environment) { + // Step 1: Add a new environment + ref.read(environmentsStateNotifierProvider.notifier).addEnvironment(); + + // Step 2: Get the ID of the newly created environment + final newEnvironmentId = + ref.read(selectedEnvironmentIdStateProvider.notifier).state; + + debugPrint('New id is $newEnvironmentId'); + + // Step 3: Update the new environment with a name and variables + if (newEnvironmentId != null) { + if (environment.resources == null || environment.resources!.isEmpty) { + debugPrint('No env variables found'); + return []; + } + List variables = []; + for (var env in environment.resources!) { + variables.add(EnvironmentVariableModel( + key: env.key, + value: env.value, + enabled: env.enabled ?? true, + type: env.type == "secret" + ? EnvironmentVariableType.secret + : EnvironmentVariableType.variable, + )); + } + ref.read(environmentsStateNotifierProvider.notifier).updateEnvironment( + newEnvironmentId, + name: environment.name ?? "Untitled", + values: variables, + ); + return variables; + } else { + debugPrint('No env id found'); + return []; + } +} String getEnvironmentTitle(String? name) { if (name == null || name.trim() == "") { diff --git a/packages/apidash_core/lib/import_export/insomnia_io.dart b/packages/apidash_core/lib/import_export/insomnia_io.dart index 6b5e1e48..3d8e9329 100644 --- a/packages/apidash_core/lib/import_export/insomnia_io.dart +++ b/packages/apidash_core/lib/import_export/insomnia_io.dart @@ -1,3 +1,4 @@ +import 'package:insomnia_collection/models/insomnia_environment.dart'; import 'package:seed/seed.dart'; import '../consts.dart'; import '../models/models.dart'; @@ -10,6 +11,10 @@ class InsomniaIO { try { final ic = ins.insomniaCollectionFromJsonStr(content); final requests = ins.getRequestsFromInsomniaCollection(ic); + + /// TODO; Get env from the insomnia collection + // final environmentVariables = ins.getEnvironmentVariablesFromInsomniaEnvironment(env); + return requests .map((req) => (req.$1, insomniaRequestToHttpRequestModel(req.$2))) .toList(); @@ -18,6 +23,17 @@ class InsomniaIO { } } + InsomniaEnvironment? getInsomiaEnvironment(String content) { + content = content.trim(); + try { + final env = ins.insomniaEnvironmentFromJsonStr(content); + + return env; + } catch (e) { + return null; + } + } + HttpRequestModel insomniaRequestToHttpRequestModel(ins.Resource request) { HTTPVerb method; @@ -89,8 +105,6 @@ class InsomniaIO { } body = request.body?.text; } - - /// TODO: Handle formdata and text } return HttpRequestModel( diff --git a/packages/insomnia_collection/lib/models/insomnia_collection.dart b/packages/insomnia_collection/lib/models/insomnia_collection.dart index adc9e706..12f2c0ff 100644 --- a/packages/insomnia_collection/lib/models/insomnia_collection.dart +++ b/packages/insomnia_collection/lib/models/insomnia_collection.dart @@ -1,9 +1,30 @@ import 'dart:convert'; import 'package:freezed_annotation/freezed_annotation.dart'; +import 'package:insomnia_collection/models/insomnia_environment.dart'; part 'insomnia_collection.freezed.dart'; part 'insomnia_collection.g.dart'; +InsomniaEnvironment insomniaEnvironmentFromJsonStr(String str) { + var InsomniaEnvjson = 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]); +} + +InsomniaEnvironment insomniaEnvironmentFromJson(Map 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 @@ -14,7 +35,6 @@ InsomniaCollection insomniaCollectionFromJsonStr(String str) { return InsomniaCollection.fromJson(Insomniajson); } - InsomniaCollection insomniaCollectionFromJson(Map json) { // Remove all resources which are not requests json['resources'] = (json['resources'] as List) diff --git a/packages/insomnia_collection/lib/models/insomnia_environment.dart b/packages/insomnia_collection/lib/models/insomnia_environment.dart new file mode 100644 index 00000000..ef32a756 --- /dev/null +++ b/packages/insomnia_collection/lib/models/insomnia_environment.dart @@ -0,0 +1,60 @@ +import 'dart:convert'; +import 'package:freezed_annotation/freezed_annotation.dart'; + +part 'insomnia_environment.freezed.dart'; +part 'insomnia_environment.g.dart'; + +@freezed +class InsomniaEnvironment with _$InsomniaEnvironment { + @JsonSerializable( + explicitToJson: true, + anyMap: true, + includeIfNull: false, + ) + const factory InsomniaEnvironment({ + @JsonKey(name: '_id') String? id, + String? name, + @JsonKey(name: 'kvPairData') List? resources , + @JsonKey(name: '_type') String? type, + }) = _InsomniaEnvironment; + + factory InsomniaEnvironment.fromJson(Map json) => + _$InsomniaEnvironmentFromJson(json); +} + +InsomniaEnvironment insomniaEnvironmentFromJsonStr(String str) { + var insomniaJson = json.decode(str); + return InsomniaEnvironment.fromJson(insomniaJson); +} + +String insomniaEnvironmentToJsonStr(InsomniaEnvironment environment) { + return json.encode(environment.toJson()); +} + +@freezed +class EnvironmentVariable with _$EnvironmentVariable { + @JsonSerializable( + explicitToJson: true, + anyMap: true, + includeIfNull: false, + ) + const factory EnvironmentVariable({ + String? id, + @JsonKey(name: 'name') required String key, + @JsonKey(name: 'value') required String value, + String? type, + @JsonKey(name: 'enabled') bool? enabled, + }) = _EnvironmentVariable; + + factory EnvironmentVariable.fromJson(Map json) => + _$EnvironmentVariableFromJson(json); +} + +EnvironmentVariable environmentVariableFromJsonStr(String str) { + var environmentJson = json.decode(str); + return EnvironmentVariable.fromJson(environmentJson); +} + +String environmentVariableToJsonStr(EnvironmentVariable variable) { + return json.encode(variable.toJson()); +} \ No newline at end of file diff --git a/packages/insomnia_collection/lib/models/insomnia_environment.freezed.dart b/packages/insomnia_collection/lib/models/insomnia_environment.freezed.dart new file mode 100644 index 00000000..ab073b42 --- /dev/null +++ b/packages/insomnia_collection/lib/models/insomnia_environment.freezed.dart @@ -0,0 +1,496 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'insomnia_environment.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models'); + +InsomniaEnvironment _$InsomniaEnvironmentFromJson(Map json) { + return _InsomniaEnvironment.fromJson(json); +} + +/// @nodoc +mixin _$InsomniaEnvironment { + @JsonKey(name: '_id') + String? get id => throw _privateConstructorUsedError; + String? get name => throw _privateConstructorUsedError; + @JsonKey(name: 'kvPairData') + List? get resources => + throw _privateConstructorUsedError; + @JsonKey(name: '_type') + String? get type => throw _privateConstructorUsedError; + + /// Serializes this InsomniaEnvironment to a JSON map. + Map toJson() => throw _privateConstructorUsedError; + + /// Create a copy of InsomniaEnvironment + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + $InsomniaEnvironmentCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $InsomniaEnvironmentCopyWith<$Res> { + factory $InsomniaEnvironmentCopyWith( + InsomniaEnvironment value, $Res Function(InsomniaEnvironment) then) = + _$InsomniaEnvironmentCopyWithImpl<$Res, InsomniaEnvironment>; + @useResult + $Res call( + {@JsonKey(name: '_id') String? id, + String? name, + @JsonKey(name: 'kvPairData') List? resources, + @JsonKey(name: '_type') String? type}); +} + +/// @nodoc +class _$InsomniaEnvironmentCopyWithImpl<$Res, $Val extends InsomniaEnvironment> + implements $InsomniaEnvironmentCopyWith<$Res> { + _$InsomniaEnvironmentCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of InsomniaEnvironment + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = freezed, + Object? name = freezed, + Object? resources = freezed, + Object? type = freezed, + }) { + return _then(_value.copyWith( + id: freezed == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as String?, + name: freezed == name + ? _value.name + : name // ignore: cast_nullable_to_non_nullable + as String?, + resources: freezed == resources + ? _value.resources + : resources // ignore: cast_nullable_to_non_nullable + as List?, + type: freezed == type + ? _value.type + : type // ignore: cast_nullable_to_non_nullable + as String?, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$InsomniaEnvironmentImplCopyWith<$Res> + implements $InsomniaEnvironmentCopyWith<$Res> { + factory _$$InsomniaEnvironmentImplCopyWith(_$InsomniaEnvironmentImpl value, + $Res Function(_$InsomniaEnvironmentImpl) then) = + __$$InsomniaEnvironmentImplCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {@JsonKey(name: '_id') String? id, + String? name, + @JsonKey(name: 'kvPairData') List? resources, + @JsonKey(name: '_type') String? type}); +} + +/// @nodoc +class __$$InsomniaEnvironmentImplCopyWithImpl<$Res> + extends _$InsomniaEnvironmentCopyWithImpl<$Res, _$InsomniaEnvironmentImpl> + implements _$$InsomniaEnvironmentImplCopyWith<$Res> { + __$$InsomniaEnvironmentImplCopyWithImpl(_$InsomniaEnvironmentImpl _value, + $Res Function(_$InsomniaEnvironmentImpl) _then) + : super(_value, _then); + + /// Create a copy of InsomniaEnvironment + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = freezed, + Object? name = freezed, + Object? resources = freezed, + Object? type = freezed, + }) { + return _then(_$InsomniaEnvironmentImpl( + id: freezed == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as String?, + name: freezed == name + ? _value.name + : name // ignore: cast_nullable_to_non_nullable + as String?, + resources: freezed == resources + ? _value._resources + : resources // ignore: cast_nullable_to_non_nullable + as List?, + type: freezed == type + ? _value.type + : type // ignore: cast_nullable_to_non_nullable + as String?, + )); + } +} + +/// @nodoc + +@JsonSerializable(explicitToJson: true, anyMap: true, includeIfNull: false) +class _$InsomniaEnvironmentImpl implements _InsomniaEnvironment { + const _$InsomniaEnvironmentImpl( + {@JsonKey(name: '_id') this.id, + this.name, + @JsonKey(name: 'kvPairData') final List? resources, + @JsonKey(name: '_type') this.type}) + : _resources = resources; + + factory _$InsomniaEnvironmentImpl.fromJson(Map json) => + _$$InsomniaEnvironmentImplFromJson(json); + + @override + @JsonKey(name: '_id') + final String? id; + @override + final String? name; + final List? _resources; + @override + @JsonKey(name: 'kvPairData') + List? get resources { + final value = _resources; + if (value == null) return null; + if (_resources is EqualUnmodifiableListView) return _resources; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(value); + } + + @override + @JsonKey(name: '_type') + final String? type; + + @override + String toString() { + return 'InsomniaEnvironment(id: $id, name: $name, resources: $resources, type: $type)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$InsomniaEnvironmentImpl && + (identical(other.id, id) || other.id == id) && + (identical(other.name, name) || other.name == name) && + const DeepCollectionEquality() + .equals(other._resources, _resources) && + (identical(other.type, type) || other.type == type)); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => Object.hash(runtimeType, id, name, + const DeepCollectionEquality().hash(_resources), type); + + /// Create a copy of InsomniaEnvironment + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$InsomniaEnvironmentImplCopyWith<_$InsomniaEnvironmentImpl> get copyWith => + __$$InsomniaEnvironmentImplCopyWithImpl<_$InsomniaEnvironmentImpl>( + this, _$identity); + + @override + Map toJson() { + return _$$InsomniaEnvironmentImplToJson( + this, + ); + } +} + +abstract class _InsomniaEnvironment implements InsomniaEnvironment { + const factory _InsomniaEnvironment( + {@JsonKey(name: '_id') final String? id, + final String? name, + @JsonKey(name: 'kvPairData') final List? resources, + @JsonKey(name: '_type') final String? type}) = _$InsomniaEnvironmentImpl; + + factory _InsomniaEnvironment.fromJson(Map json) = + _$InsomniaEnvironmentImpl.fromJson; + + @override + @JsonKey(name: '_id') + String? get id; + @override + String? get name; + @override + @JsonKey(name: 'kvPairData') + List? get resources; + @override + @JsonKey(name: '_type') + String? get type; + + /// Create a copy of InsomniaEnvironment + /// with the given fields replaced by the non-null parameter values. + @override + @JsonKey(includeFromJson: false, includeToJson: false) + _$$InsomniaEnvironmentImplCopyWith<_$InsomniaEnvironmentImpl> get copyWith => + throw _privateConstructorUsedError; +} + +EnvironmentVariable _$EnvironmentVariableFromJson(Map json) { + return _EnvironmentVariable.fromJson(json); +} + +/// @nodoc +mixin _$EnvironmentVariable { + String? get id => throw _privateConstructorUsedError; + @JsonKey(name: 'name') + String get key => throw _privateConstructorUsedError; + @JsonKey(name: 'value') + String get value => throw _privateConstructorUsedError; + String? get type => throw _privateConstructorUsedError; + @JsonKey(name: 'enabled') + bool? get enabled => throw _privateConstructorUsedError; + + /// Serializes this EnvironmentVariable to a JSON map. + Map toJson() => throw _privateConstructorUsedError; + + /// Create a copy of EnvironmentVariable + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + $EnvironmentVariableCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $EnvironmentVariableCopyWith<$Res> { + factory $EnvironmentVariableCopyWith( + EnvironmentVariable value, $Res Function(EnvironmentVariable) then) = + _$EnvironmentVariableCopyWithImpl<$Res, EnvironmentVariable>; + @useResult + $Res call( + {String? id, + @JsonKey(name: 'name') String key, + @JsonKey(name: 'value') String value, + String? type, + @JsonKey(name: 'enabled') bool? enabled}); +} + +/// @nodoc +class _$EnvironmentVariableCopyWithImpl<$Res, $Val extends EnvironmentVariable> + implements $EnvironmentVariableCopyWith<$Res> { + _$EnvironmentVariableCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of EnvironmentVariable + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = freezed, + Object? key = null, + Object? value = null, + Object? type = freezed, + Object? enabled = freezed, + }) { + return _then(_value.copyWith( + id: freezed == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as String?, + key: null == key + ? _value.key + : key // ignore: cast_nullable_to_non_nullable + as String, + value: null == value + ? _value.value + : value // ignore: cast_nullable_to_non_nullable + as String, + type: freezed == type + ? _value.type + : type // ignore: cast_nullable_to_non_nullable + as String?, + enabled: freezed == enabled + ? _value.enabled + : enabled // ignore: cast_nullable_to_non_nullable + as bool?, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$EnvironmentVariableImplCopyWith<$Res> + implements $EnvironmentVariableCopyWith<$Res> { + factory _$$EnvironmentVariableImplCopyWith(_$EnvironmentVariableImpl value, + $Res Function(_$EnvironmentVariableImpl) then) = + __$$EnvironmentVariableImplCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {String? id, + @JsonKey(name: 'name') String key, + @JsonKey(name: 'value') String value, + String? type, + @JsonKey(name: 'enabled') bool? enabled}); +} + +/// @nodoc +class __$$EnvironmentVariableImplCopyWithImpl<$Res> + extends _$EnvironmentVariableCopyWithImpl<$Res, _$EnvironmentVariableImpl> + implements _$$EnvironmentVariableImplCopyWith<$Res> { + __$$EnvironmentVariableImplCopyWithImpl(_$EnvironmentVariableImpl _value, + $Res Function(_$EnvironmentVariableImpl) _then) + : super(_value, _then); + + /// Create a copy of EnvironmentVariable + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = freezed, + Object? key = null, + Object? value = null, + Object? type = freezed, + Object? enabled = freezed, + }) { + return _then(_$EnvironmentVariableImpl( + id: freezed == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as String?, + key: null == key + ? _value.key + : key // ignore: cast_nullable_to_non_nullable + as String, + value: null == value + ? _value.value + : value // ignore: cast_nullable_to_non_nullable + as String, + type: freezed == type + ? _value.type + : type // ignore: cast_nullable_to_non_nullable + as String?, + enabled: freezed == enabled + ? _value.enabled + : enabled // ignore: cast_nullable_to_non_nullable + as bool?, + )); + } +} + +/// @nodoc + +@JsonSerializable(explicitToJson: true, anyMap: true, includeIfNull: false) +class _$EnvironmentVariableImpl implements _EnvironmentVariable { + const _$EnvironmentVariableImpl( + {this.id, + @JsonKey(name: 'name') required this.key, + @JsonKey(name: 'value') required this.value, + this.type, + @JsonKey(name: 'enabled') this.enabled}); + + factory _$EnvironmentVariableImpl.fromJson(Map json) => + _$$EnvironmentVariableImplFromJson(json); + + @override + final String? id; + @override + @JsonKey(name: 'name') + final String key; + @override + @JsonKey(name: 'value') + final String value; + @override + final String? type; + @override + @JsonKey(name: 'enabled') + final bool? enabled; + + @override + String toString() { + return 'EnvironmentVariable(id: $id, key: $key, value: $value, type: $type, enabled: $enabled)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$EnvironmentVariableImpl && + (identical(other.id, id) || other.id == id) && + (identical(other.key, key) || other.key == key) && + (identical(other.value, value) || other.value == value) && + (identical(other.type, type) || other.type == type) && + (identical(other.enabled, enabled) || other.enabled == enabled)); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => Object.hash(runtimeType, id, key, value, type, enabled); + + /// Create a copy of EnvironmentVariable + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$EnvironmentVariableImplCopyWith<_$EnvironmentVariableImpl> get copyWith => + __$$EnvironmentVariableImplCopyWithImpl<_$EnvironmentVariableImpl>( + this, _$identity); + + @override + Map toJson() { + return _$$EnvironmentVariableImplToJson( + this, + ); + } +} + +abstract class _EnvironmentVariable implements EnvironmentVariable { + const factory _EnvironmentVariable( + {final String? id, + @JsonKey(name: 'name') required final String key, + @JsonKey(name: 'value') required final String value, + final String? type, + @JsonKey(name: 'enabled') final bool? enabled}) = + _$EnvironmentVariableImpl; + + factory _EnvironmentVariable.fromJson(Map json) = + _$EnvironmentVariableImpl.fromJson; + + @override + String? get id; + @override + @JsonKey(name: 'name') + String get key; + @override + @JsonKey(name: 'value') + String get value; + @override + String? get type; + @override + @JsonKey(name: 'enabled') + bool? get enabled; + + /// Create a copy of EnvironmentVariable + /// with the given fields replaced by the non-null parameter values. + @override + @JsonKey(includeFromJson: false, includeToJson: false) + _$$EnvironmentVariableImplCopyWith<_$EnvironmentVariableImpl> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/packages/insomnia_collection/lib/models/insomnia_environment.g.dart b/packages/insomnia_collection/lib/models/insomnia_environment.g.dart new file mode 100644 index 00000000..95a1c316 --- /dev/null +++ b/packages/insomnia_collection/lib/models/insomnia_environment.g.dart @@ -0,0 +1,47 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'insomnia_environment.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$InsomniaEnvironmentImpl _$$InsomniaEnvironmentImplFromJson(Map json) => + _$InsomniaEnvironmentImpl( + id: json['_id'] as String?, + name: json['name'] as String?, + resources: (json['kvPairData'] as List?) + ?.map((e) => + EnvironmentVariable.fromJson(Map.from(e as Map))) + .toList(), + type: json['_type'] as String?, + ); + +Map _$$InsomniaEnvironmentImplToJson( + _$InsomniaEnvironmentImpl instance) => + { + if (instance.id case final value?) '_id': value, + if (instance.name case final value?) 'name': value, + if (instance.resources?.map((e) => e.toJson()).toList() case final value?) + 'kvPairData': value, + if (instance.type case final value?) '_type': value, + }; + +_$EnvironmentVariableImpl _$$EnvironmentVariableImplFromJson(Map json) => + _$EnvironmentVariableImpl( + id: json['id'] as String?, + key: json['name'] as String, + value: json['value'] as String, + type: json['type'] as String?, + enabled: json['enabled'] as bool?, + ); + +Map _$$EnvironmentVariableImplToJson( + _$EnvironmentVariableImpl instance) => + { + if (instance.id case final value?) 'id': value, + 'name': instance.key, + 'value': instance.value, + if (instance.type case final value?) 'type': value, + if (instance.enabled case final value?) 'enabled': value, + }; diff --git a/packages/insomnia_collection/lib/utils/insomnia_utils.dart b/packages/insomnia_collection/lib/utils/insomnia_utils.dart index ca3d9810..c0ab145e 100644 --- a/packages/insomnia_collection/lib/utils/insomnia_utils.dart +++ b/packages/insomnia_collection/lib/utils/insomnia_utils.dart @@ -2,6 +2,7 @@ import 'package:insomnia_collection/models/insomnia_collection.dart'; +import 'package:insomnia_collection/models/insomnia_environment.dart'; List<(String?, Resource)> getRequestsFromInsomniaCollection( InsomniaCollection? ic) { @@ -17,6 +18,20 @@ List<(String?, Resource)> getRequestsFromInsomniaCollection( return requests; } +List getEnvironmentVariablesFromInsomniaEnvironment( + InsomniaEnvironment? ev) { + if (ev == null || ev.resources == null) { + return []; + } + List envVariables = []; + if (ev.resources!.length > 0) { + for (var envvar in ev.resources!) { + envVariables.add(envvar); + } + } + return envVariables; +} + List<(String?, Resource)> getRequestsFromInsomniaResource(Resource? resource) { if (resource == null) { return []; @@ -28,4 +43,5 @@ List<(String?, Resource)> getRequestsFromInsomniaResource(Resource? resource) { print('Resource type is not request'); } return requests; -} \ No newline at end of file +} + diff --git a/pubspec.lock b/pubspec.lock index fdf2db3c..0826b5d5 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -773,7 +773,7 @@ packages: source: hosted version: "4.3.0" insomnia_collection: - dependency: transitive + dependency: "direct main" description: path: "packages/insomnia_collection" relative: true diff --git a/pubspec.yaml b/pubspec.yaml index e2d00bad..89733f2c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -12,6 +12,8 @@ dependencies: sdk: flutter apidash_core: path: packages/apidash_core + insomnia_collection: + path: packages/insomnia_collection apidash_design_system: path: packages/apidash_design_system code_builder: ^4.10.0 From 0ebe3369e1ab4f2921c2009a28d620fd60cead1c Mon Sep 17 00:00:00 2001 From: StormGear Date: Tue, 4 Feb 2025 09:14:22 +0000 Subject: [PATCH 13/42] readded the TODO --- lib/importer/import_dialog.dart | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/importer/import_dialog.dart b/lib/importer/import_dialog.dart index 51a0ed9e..52dec2c7 100644 --- a/lib/importer/import_dialog.dart +++ b/lib/importer/import_dialog.dart @@ -11,6 +11,9 @@ void importToCollectionPane( WidgetRef ref, ScaffoldMessengerState sm, ) { + // TODO: The dialog must have a feature to paste contents in a text field + // Also, a mechanism can be added where on importing a file it shows the + // contents in the text field and then the user presses ok to add it to collection showImportDialog( context: context, importFormat: ref.watch(importFormatStateProvider), From 1226e047fe2c66a0d009d8c7f539cdd959949ca6 Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Mon, 24 Feb 2025 04:47:02 +0530 Subject: [PATCH 14/42] Update pubspec_overrides.yaml --- packages/apidash_core/pubspec_overrides.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/apidash_core/pubspec_overrides.yaml b/packages/apidash_core/pubspec_overrides.yaml index 7c2883d9..7cac389e 100644 --- a/packages/apidash_core/pubspec_overrides.yaml +++ b/packages/apidash_core/pubspec_overrides.yaml @@ -1,7 +1,9 @@ -# melos_managed_dependency_overrides: curl_parser,postman,seed +# melos_managed_dependency_overrides: curl_parser,postman,seed,insomnia_collection dependency_overrides: curl_parser: path: ../curl_parser + insomnia_collection: + path: ../insomnia_collection postman: path: ../postman seed: From ecba435fc5a7cc090a7eb31c19962d3333b36eaf Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Mon, 24 Feb 2025 07:20:56 +0530 Subject: [PATCH 15/42] Remove custom environment model --- .../lib/models/insomnia_environment.dart | 60 --- .../models/insomnia_environment.freezed.dart | 496 ------------------ .../lib/models/insomnia_environment.g.dart | 47 -- 3 files changed, 603 deletions(-) delete mode 100644 packages/insomnia_collection/lib/models/insomnia_environment.dart delete mode 100644 packages/insomnia_collection/lib/models/insomnia_environment.freezed.dart delete mode 100644 packages/insomnia_collection/lib/models/insomnia_environment.g.dart diff --git a/packages/insomnia_collection/lib/models/insomnia_environment.dart b/packages/insomnia_collection/lib/models/insomnia_environment.dart deleted file mode 100644 index ef32a756..00000000 --- a/packages/insomnia_collection/lib/models/insomnia_environment.dart +++ /dev/null @@ -1,60 +0,0 @@ -import 'dart:convert'; -import 'package:freezed_annotation/freezed_annotation.dart'; - -part 'insomnia_environment.freezed.dart'; -part 'insomnia_environment.g.dart'; - -@freezed -class InsomniaEnvironment with _$InsomniaEnvironment { - @JsonSerializable( - explicitToJson: true, - anyMap: true, - includeIfNull: false, - ) - const factory InsomniaEnvironment({ - @JsonKey(name: '_id') String? id, - String? name, - @JsonKey(name: 'kvPairData') List? resources , - @JsonKey(name: '_type') String? type, - }) = _InsomniaEnvironment; - - factory InsomniaEnvironment.fromJson(Map json) => - _$InsomniaEnvironmentFromJson(json); -} - -InsomniaEnvironment insomniaEnvironmentFromJsonStr(String str) { - var insomniaJson = json.decode(str); - return InsomniaEnvironment.fromJson(insomniaJson); -} - -String insomniaEnvironmentToJsonStr(InsomniaEnvironment environment) { - return json.encode(environment.toJson()); -} - -@freezed -class EnvironmentVariable with _$EnvironmentVariable { - @JsonSerializable( - explicitToJson: true, - anyMap: true, - includeIfNull: false, - ) - const factory EnvironmentVariable({ - String? id, - @JsonKey(name: 'name') required String key, - @JsonKey(name: 'value') required String value, - String? type, - @JsonKey(name: 'enabled') bool? enabled, - }) = _EnvironmentVariable; - - factory EnvironmentVariable.fromJson(Map json) => - _$EnvironmentVariableFromJson(json); -} - -EnvironmentVariable environmentVariableFromJsonStr(String str) { - var environmentJson = json.decode(str); - return EnvironmentVariable.fromJson(environmentJson); -} - -String environmentVariableToJsonStr(EnvironmentVariable variable) { - return json.encode(variable.toJson()); -} \ No newline at end of file diff --git a/packages/insomnia_collection/lib/models/insomnia_environment.freezed.dart b/packages/insomnia_collection/lib/models/insomnia_environment.freezed.dart deleted file mode 100644 index ab073b42..00000000 --- a/packages/insomnia_collection/lib/models/insomnia_environment.freezed.dart +++ /dev/null @@ -1,496 +0,0 @@ -// coverage:ignore-file -// GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: type=lint -// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark - -part of 'insomnia_environment.dart'; - -// ************************************************************************** -// FreezedGenerator -// ************************************************************************** - -T _$identity(T value) => value; - -final _privateConstructorUsedError = UnsupportedError( - 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models'); - -InsomniaEnvironment _$InsomniaEnvironmentFromJson(Map json) { - return _InsomniaEnvironment.fromJson(json); -} - -/// @nodoc -mixin _$InsomniaEnvironment { - @JsonKey(name: '_id') - String? get id => throw _privateConstructorUsedError; - String? get name => throw _privateConstructorUsedError; - @JsonKey(name: 'kvPairData') - List? get resources => - throw _privateConstructorUsedError; - @JsonKey(name: '_type') - String? get type => throw _privateConstructorUsedError; - - /// Serializes this InsomniaEnvironment to a JSON map. - Map toJson() => throw _privateConstructorUsedError; - - /// Create a copy of InsomniaEnvironment - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - $InsomniaEnvironmentCopyWith get copyWith => - throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class $InsomniaEnvironmentCopyWith<$Res> { - factory $InsomniaEnvironmentCopyWith( - InsomniaEnvironment value, $Res Function(InsomniaEnvironment) then) = - _$InsomniaEnvironmentCopyWithImpl<$Res, InsomniaEnvironment>; - @useResult - $Res call( - {@JsonKey(name: '_id') String? id, - String? name, - @JsonKey(name: 'kvPairData') List? resources, - @JsonKey(name: '_type') String? type}); -} - -/// @nodoc -class _$InsomniaEnvironmentCopyWithImpl<$Res, $Val extends InsomniaEnvironment> - implements $InsomniaEnvironmentCopyWith<$Res> { - _$InsomniaEnvironmentCopyWithImpl(this._value, this._then); - - // ignore: unused_field - final $Val _value; - // ignore: unused_field - final $Res Function($Val) _then; - - /// Create a copy of InsomniaEnvironment - /// with the given fields replaced by the non-null parameter values. - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? id = freezed, - Object? name = freezed, - Object? resources = freezed, - Object? type = freezed, - }) { - return _then(_value.copyWith( - id: freezed == id - ? _value.id - : id // ignore: cast_nullable_to_non_nullable - as String?, - name: freezed == name - ? _value.name - : name // ignore: cast_nullable_to_non_nullable - as String?, - resources: freezed == resources - ? _value.resources - : resources // ignore: cast_nullable_to_non_nullable - as List?, - type: freezed == type - ? _value.type - : type // ignore: cast_nullable_to_non_nullable - as String?, - ) as $Val); - } -} - -/// @nodoc -abstract class _$$InsomniaEnvironmentImplCopyWith<$Res> - implements $InsomniaEnvironmentCopyWith<$Res> { - factory _$$InsomniaEnvironmentImplCopyWith(_$InsomniaEnvironmentImpl value, - $Res Function(_$InsomniaEnvironmentImpl) then) = - __$$InsomniaEnvironmentImplCopyWithImpl<$Res>; - @override - @useResult - $Res call( - {@JsonKey(name: '_id') String? id, - String? name, - @JsonKey(name: 'kvPairData') List? resources, - @JsonKey(name: '_type') String? type}); -} - -/// @nodoc -class __$$InsomniaEnvironmentImplCopyWithImpl<$Res> - extends _$InsomniaEnvironmentCopyWithImpl<$Res, _$InsomniaEnvironmentImpl> - implements _$$InsomniaEnvironmentImplCopyWith<$Res> { - __$$InsomniaEnvironmentImplCopyWithImpl(_$InsomniaEnvironmentImpl _value, - $Res Function(_$InsomniaEnvironmentImpl) _then) - : super(_value, _then); - - /// Create a copy of InsomniaEnvironment - /// with the given fields replaced by the non-null parameter values. - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? id = freezed, - Object? name = freezed, - Object? resources = freezed, - Object? type = freezed, - }) { - return _then(_$InsomniaEnvironmentImpl( - id: freezed == id - ? _value.id - : id // ignore: cast_nullable_to_non_nullable - as String?, - name: freezed == name - ? _value.name - : name // ignore: cast_nullable_to_non_nullable - as String?, - resources: freezed == resources - ? _value._resources - : resources // ignore: cast_nullable_to_non_nullable - as List?, - type: freezed == type - ? _value.type - : type // ignore: cast_nullable_to_non_nullable - as String?, - )); - } -} - -/// @nodoc - -@JsonSerializable(explicitToJson: true, anyMap: true, includeIfNull: false) -class _$InsomniaEnvironmentImpl implements _InsomniaEnvironment { - const _$InsomniaEnvironmentImpl( - {@JsonKey(name: '_id') this.id, - this.name, - @JsonKey(name: 'kvPairData') final List? resources, - @JsonKey(name: '_type') this.type}) - : _resources = resources; - - factory _$InsomniaEnvironmentImpl.fromJson(Map json) => - _$$InsomniaEnvironmentImplFromJson(json); - - @override - @JsonKey(name: '_id') - final String? id; - @override - final String? name; - final List? _resources; - @override - @JsonKey(name: 'kvPairData') - List? get resources { - final value = _resources; - if (value == null) return null; - if (_resources is EqualUnmodifiableListView) return _resources; - // ignore: implicit_dynamic_type - return EqualUnmodifiableListView(value); - } - - @override - @JsonKey(name: '_type') - final String? type; - - @override - String toString() { - return 'InsomniaEnvironment(id: $id, name: $name, resources: $resources, type: $type)'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$InsomniaEnvironmentImpl && - (identical(other.id, id) || other.id == id) && - (identical(other.name, name) || other.name == name) && - const DeepCollectionEquality() - .equals(other._resources, _resources) && - (identical(other.type, type) || other.type == type)); - } - - @JsonKey(includeFromJson: false, includeToJson: false) - @override - int get hashCode => Object.hash(runtimeType, id, name, - const DeepCollectionEquality().hash(_resources), type); - - /// Create a copy of InsomniaEnvironment - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - @override - @pragma('vm:prefer-inline') - _$$InsomniaEnvironmentImplCopyWith<_$InsomniaEnvironmentImpl> get copyWith => - __$$InsomniaEnvironmentImplCopyWithImpl<_$InsomniaEnvironmentImpl>( - this, _$identity); - - @override - Map toJson() { - return _$$InsomniaEnvironmentImplToJson( - this, - ); - } -} - -abstract class _InsomniaEnvironment implements InsomniaEnvironment { - const factory _InsomniaEnvironment( - {@JsonKey(name: '_id') final String? id, - final String? name, - @JsonKey(name: 'kvPairData') final List? resources, - @JsonKey(name: '_type') final String? type}) = _$InsomniaEnvironmentImpl; - - factory _InsomniaEnvironment.fromJson(Map json) = - _$InsomniaEnvironmentImpl.fromJson; - - @override - @JsonKey(name: '_id') - String? get id; - @override - String? get name; - @override - @JsonKey(name: 'kvPairData') - List? get resources; - @override - @JsonKey(name: '_type') - String? get type; - - /// Create a copy of InsomniaEnvironment - /// with the given fields replaced by the non-null parameter values. - @override - @JsonKey(includeFromJson: false, includeToJson: false) - _$$InsomniaEnvironmentImplCopyWith<_$InsomniaEnvironmentImpl> get copyWith => - throw _privateConstructorUsedError; -} - -EnvironmentVariable _$EnvironmentVariableFromJson(Map json) { - return _EnvironmentVariable.fromJson(json); -} - -/// @nodoc -mixin _$EnvironmentVariable { - String? get id => throw _privateConstructorUsedError; - @JsonKey(name: 'name') - String get key => throw _privateConstructorUsedError; - @JsonKey(name: 'value') - String get value => throw _privateConstructorUsedError; - String? get type => throw _privateConstructorUsedError; - @JsonKey(name: 'enabled') - bool? get enabled => throw _privateConstructorUsedError; - - /// Serializes this EnvironmentVariable to a JSON map. - Map toJson() => throw _privateConstructorUsedError; - - /// Create a copy of EnvironmentVariable - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - $EnvironmentVariableCopyWith get copyWith => - throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class $EnvironmentVariableCopyWith<$Res> { - factory $EnvironmentVariableCopyWith( - EnvironmentVariable value, $Res Function(EnvironmentVariable) then) = - _$EnvironmentVariableCopyWithImpl<$Res, EnvironmentVariable>; - @useResult - $Res call( - {String? id, - @JsonKey(name: 'name') String key, - @JsonKey(name: 'value') String value, - String? type, - @JsonKey(name: 'enabled') bool? enabled}); -} - -/// @nodoc -class _$EnvironmentVariableCopyWithImpl<$Res, $Val extends EnvironmentVariable> - implements $EnvironmentVariableCopyWith<$Res> { - _$EnvironmentVariableCopyWithImpl(this._value, this._then); - - // ignore: unused_field - final $Val _value; - // ignore: unused_field - final $Res Function($Val) _then; - - /// Create a copy of EnvironmentVariable - /// with the given fields replaced by the non-null parameter values. - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? id = freezed, - Object? key = null, - Object? value = null, - Object? type = freezed, - Object? enabled = freezed, - }) { - return _then(_value.copyWith( - id: freezed == id - ? _value.id - : id // ignore: cast_nullable_to_non_nullable - as String?, - key: null == key - ? _value.key - : key // ignore: cast_nullable_to_non_nullable - as String, - value: null == value - ? _value.value - : value // ignore: cast_nullable_to_non_nullable - as String, - type: freezed == type - ? _value.type - : type // ignore: cast_nullable_to_non_nullable - as String?, - enabled: freezed == enabled - ? _value.enabled - : enabled // ignore: cast_nullable_to_non_nullable - as bool?, - ) as $Val); - } -} - -/// @nodoc -abstract class _$$EnvironmentVariableImplCopyWith<$Res> - implements $EnvironmentVariableCopyWith<$Res> { - factory _$$EnvironmentVariableImplCopyWith(_$EnvironmentVariableImpl value, - $Res Function(_$EnvironmentVariableImpl) then) = - __$$EnvironmentVariableImplCopyWithImpl<$Res>; - @override - @useResult - $Res call( - {String? id, - @JsonKey(name: 'name') String key, - @JsonKey(name: 'value') String value, - String? type, - @JsonKey(name: 'enabled') bool? enabled}); -} - -/// @nodoc -class __$$EnvironmentVariableImplCopyWithImpl<$Res> - extends _$EnvironmentVariableCopyWithImpl<$Res, _$EnvironmentVariableImpl> - implements _$$EnvironmentVariableImplCopyWith<$Res> { - __$$EnvironmentVariableImplCopyWithImpl(_$EnvironmentVariableImpl _value, - $Res Function(_$EnvironmentVariableImpl) _then) - : super(_value, _then); - - /// Create a copy of EnvironmentVariable - /// with the given fields replaced by the non-null parameter values. - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? id = freezed, - Object? key = null, - Object? value = null, - Object? type = freezed, - Object? enabled = freezed, - }) { - return _then(_$EnvironmentVariableImpl( - id: freezed == id - ? _value.id - : id // ignore: cast_nullable_to_non_nullable - as String?, - key: null == key - ? _value.key - : key // ignore: cast_nullable_to_non_nullable - as String, - value: null == value - ? _value.value - : value // ignore: cast_nullable_to_non_nullable - as String, - type: freezed == type - ? _value.type - : type // ignore: cast_nullable_to_non_nullable - as String?, - enabled: freezed == enabled - ? _value.enabled - : enabled // ignore: cast_nullable_to_non_nullable - as bool?, - )); - } -} - -/// @nodoc - -@JsonSerializable(explicitToJson: true, anyMap: true, includeIfNull: false) -class _$EnvironmentVariableImpl implements _EnvironmentVariable { - const _$EnvironmentVariableImpl( - {this.id, - @JsonKey(name: 'name') required this.key, - @JsonKey(name: 'value') required this.value, - this.type, - @JsonKey(name: 'enabled') this.enabled}); - - factory _$EnvironmentVariableImpl.fromJson(Map json) => - _$$EnvironmentVariableImplFromJson(json); - - @override - final String? id; - @override - @JsonKey(name: 'name') - final String key; - @override - @JsonKey(name: 'value') - final String value; - @override - final String? type; - @override - @JsonKey(name: 'enabled') - final bool? enabled; - - @override - String toString() { - return 'EnvironmentVariable(id: $id, key: $key, value: $value, type: $type, enabled: $enabled)'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$EnvironmentVariableImpl && - (identical(other.id, id) || other.id == id) && - (identical(other.key, key) || other.key == key) && - (identical(other.value, value) || other.value == value) && - (identical(other.type, type) || other.type == type) && - (identical(other.enabled, enabled) || other.enabled == enabled)); - } - - @JsonKey(includeFromJson: false, includeToJson: false) - @override - int get hashCode => Object.hash(runtimeType, id, key, value, type, enabled); - - /// Create a copy of EnvironmentVariable - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - @override - @pragma('vm:prefer-inline') - _$$EnvironmentVariableImplCopyWith<_$EnvironmentVariableImpl> get copyWith => - __$$EnvironmentVariableImplCopyWithImpl<_$EnvironmentVariableImpl>( - this, _$identity); - - @override - Map toJson() { - return _$$EnvironmentVariableImplToJson( - this, - ); - } -} - -abstract class _EnvironmentVariable implements EnvironmentVariable { - const factory _EnvironmentVariable( - {final String? id, - @JsonKey(name: 'name') required final String key, - @JsonKey(name: 'value') required final String value, - final String? type, - @JsonKey(name: 'enabled') final bool? enabled}) = - _$EnvironmentVariableImpl; - - factory _EnvironmentVariable.fromJson(Map json) = - _$EnvironmentVariableImpl.fromJson; - - @override - String? get id; - @override - @JsonKey(name: 'name') - String get key; - @override - @JsonKey(name: 'value') - String get value; - @override - String? get type; - @override - @JsonKey(name: 'enabled') - bool? get enabled; - - /// Create a copy of EnvironmentVariable - /// with the given fields replaced by the non-null parameter values. - @override - @JsonKey(includeFromJson: false, includeToJson: false) - _$$EnvironmentVariableImplCopyWith<_$EnvironmentVariableImpl> get copyWith => - throw _privateConstructorUsedError; -} diff --git a/packages/insomnia_collection/lib/models/insomnia_environment.g.dart b/packages/insomnia_collection/lib/models/insomnia_environment.g.dart deleted file mode 100644 index 95a1c316..00000000 --- a/packages/insomnia_collection/lib/models/insomnia_environment.g.dart +++ /dev/null @@ -1,47 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'insomnia_environment.dart'; - -// ************************************************************************** -// JsonSerializableGenerator -// ************************************************************************** - -_$InsomniaEnvironmentImpl _$$InsomniaEnvironmentImplFromJson(Map json) => - _$InsomniaEnvironmentImpl( - id: json['_id'] as String?, - name: json['name'] as String?, - resources: (json['kvPairData'] as List?) - ?.map((e) => - EnvironmentVariable.fromJson(Map.from(e as Map))) - .toList(), - type: json['_type'] as String?, - ); - -Map _$$InsomniaEnvironmentImplToJson( - _$InsomniaEnvironmentImpl instance) => - { - if (instance.id case final value?) '_id': value, - if (instance.name case final value?) 'name': value, - if (instance.resources?.map((e) => e.toJson()).toList() case final value?) - 'kvPairData': value, - if (instance.type case final value?) '_type': value, - }; - -_$EnvironmentVariableImpl _$$EnvironmentVariableImplFromJson(Map json) => - _$EnvironmentVariableImpl( - id: json['id'] as String?, - key: json['name'] as String, - value: json['value'] as String, - type: json['type'] as String?, - enabled: json['enabled'] as bool?, - ); - -Map _$$EnvironmentVariableImplToJson( - _$EnvironmentVariableImpl instance) => - { - if (instance.id case final value?) 'id': value, - 'name': instance.key, - 'value': instance.value, - if (instance.type case final value?) 'type': value, - if (instance.enabled case final value?) 'enabled': value, - }; From 6f3e8437a6d79bed57a204ce741e8cf95df6e811 Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Mon, 24 Feb 2025 11:12:56 +0530 Subject: [PATCH 16/42] Update InsomniaCollection model --- .../lib/models/insomnia_collection.dart | 107 +- .../models/insomnia_collection.freezed.dart | 1008 ++++++++++++++++- .../lib/models/insomnia_collection.g.dart | 102 +- 3 files changed, 1117 insertions(+), 100 deletions(-) diff --git a/packages/insomnia_collection/lib/models/insomnia_collection.dart b/packages/insomnia_collection/lib/models/insomnia_collection.dart index 12f2c0ff..c5d2b1d7 100644 --- a/packages/insomnia_collection/lib/models/insomnia_collection.dart +++ b/packages/insomnia_collection/lib/models/insomnia_collection.dart @@ -1,50 +1,14 @@ import 'dart:convert'; import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:insomnia_collection/models/insomnia_environment.dart'; part 'insomnia_collection.freezed.dart'; part 'insomnia_collection.g.dart'; -InsomniaEnvironment insomniaEnvironmentFromJsonStr(String str) { - var InsomniaEnvjson = json.decode(str); - print(InsomniaEnvjson.toString()); - InsomniaEnvjson['resources'] = (InsomniaEnvjson['resources'] as List) - .where((resource) => resource['_type'] == 'environment') - .toList(); - print(InsomniaEnvjson['resources'].toString()); +InsomniaCollection insomniaCollectionFromJsonStr(String str) => + InsomniaCollection.fromJson(json.decode(str)); - return InsomniaEnvironment.fromJson(InsomniaEnvjson['resources'][0]); -} - -InsomniaEnvironment insomniaEnvironmentFromJson(Map 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 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 +String insomniaCollectionToJsonStr(InsomniaCollection data) => + JsonEncoder.withIndent(' ').convert(data); @freezed class InsomniaCollection with _$InsomniaCollection { @@ -74,7 +38,7 @@ class Resource with _$Resource { ) const factory Resource({ @JsonKey(name: '_id') String? id, - @JsonKey(name: 'parentId') String? parentId, + String? parentId, num? modified, num? created, String? url, @@ -82,18 +46,32 @@ class Resource with _$Resource { String? description, String? method, Body? body, + String? preRequestScript, List? parameters, List
? headers, - String? preRequestScript, + dynamic authentication, num? metaSortKey, bool? isPrivate, + List? pathParameters, String? afterResponseScript, - bool? settingSendCookies, bool? settingStoreCookies, + bool? settingSendCookies, bool? settingDisableRenderRequestBody, bool? settingEncodeUrl, bool? settingRebuildPath, String? settingFollowRedirects, + dynamic environment, + dynamic environmentPropertyOrder, + String? scope, + dynamic data, + dynamic dataPropertyOrder, + dynamic color, + List? cookies, + String? fileName, + String? contents, + String? contentType, + String? environmentType, + List? kvPairData, @JsonKey(name: '_type') String? type, }) = _Resource; @@ -169,3 +147,46 @@ class Header with _$Header { factory Header.fromJson(Map 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 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 json) => + _$KVPairDatumFromJson(json); +} diff --git a/packages/insomnia_collection/lib/models/insomnia_collection.freezed.dart b/packages/insomnia_collection/lib/models/insomnia_collection.freezed.dart index ea455522..ffa05a31 100644 --- a/packages/insomnia_collection/lib/models/insomnia_collection.freezed.dart +++ b/packages/insomnia_collection/lib/models/insomnia_collection.freezed.dart @@ -282,7 +282,6 @@ Resource _$ResourceFromJson(Map json) { mixin _$Resource { @JsonKey(name: '_id') String? get id => throw _privateConstructorUsedError; - @JsonKey(name: 'parentId') String? get parentId => throw _privateConstructorUsedError; num? get modified => throw _privateConstructorUsedError; num? get created => throw _privateConstructorUsedError; @@ -291,19 +290,33 @@ mixin _$Resource { String? get description => throw _privateConstructorUsedError; String? get method => throw _privateConstructorUsedError; Body? get body => throw _privateConstructorUsedError; + String? get preRequestScript => throw _privateConstructorUsedError; List? get parameters => throw _privateConstructorUsedError; List
? get headers => throw _privateConstructorUsedError; - String? get preRequestScript => throw _privateConstructorUsedError; + dynamic get authentication => throw _privateConstructorUsedError; num? get metaSortKey => throw _privateConstructorUsedError; bool? get isPrivate => throw _privateConstructorUsedError; + List? get pathParameters => throw _privateConstructorUsedError; String? get afterResponseScript => throw _privateConstructorUsedError; - bool? get settingSendCookies => throw _privateConstructorUsedError; bool? get settingStoreCookies => throw _privateConstructorUsedError; + bool? get settingSendCookies => throw _privateConstructorUsedError; bool? get settingDisableRenderRequestBody => throw _privateConstructorUsedError; bool? get settingEncodeUrl => throw _privateConstructorUsedError; bool? get settingRebuildPath => throw _privateConstructorUsedError; String? get settingFollowRedirects => throw _privateConstructorUsedError; + dynamic get environment => throw _privateConstructorUsedError; + dynamic get environmentPropertyOrder => throw _privateConstructorUsedError; + String? get scope => throw _privateConstructorUsedError; + dynamic get data => throw _privateConstructorUsedError; + dynamic get dataPropertyOrder => throw _privateConstructorUsedError; + dynamic get color => throw _privateConstructorUsedError; + List? get cookies => throw _privateConstructorUsedError; + String? get fileName => throw _privateConstructorUsedError; + String? get contents => throw _privateConstructorUsedError; + String? get contentType => throw _privateConstructorUsedError; + String? get environmentType => throw _privateConstructorUsedError; + List? get kvPairData => throw _privateConstructorUsedError; @JsonKey(name: '_type') String? get type => throw _privateConstructorUsedError; @@ -324,7 +337,7 @@ abstract class $ResourceCopyWith<$Res> { @useResult $Res call( {@JsonKey(name: '_id') String? id, - @JsonKey(name: 'parentId') String? parentId, + String? parentId, num? modified, num? created, String? url, @@ -332,18 +345,32 @@ abstract class $ResourceCopyWith<$Res> { String? description, String? method, Body? body, + String? preRequestScript, List? parameters, List
? headers, - String? preRequestScript, + dynamic authentication, num? metaSortKey, bool? isPrivate, + List? pathParameters, String? afterResponseScript, - bool? settingSendCookies, bool? settingStoreCookies, + bool? settingSendCookies, bool? settingDisableRenderRequestBody, bool? settingEncodeUrl, bool? settingRebuildPath, String? settingFollowRedirects, + dynamic environment, + dynamic environmentPropertyOrder, + String? scope, + dynamic data, + dynamic dataPropertyOrder, + dynamic color, + List? cookies, + String? fileName, + String? contents, + String? contentType, + String? environmentType, + List? kvPairData, @JsonKey(name: '_type') String? type}); $BodyCopyWith<$Res>? get body; @@ -373,18 +400,32 @@ class _$ResourceCopyWithImpl<$Res, $Val extends Resource> Object? description = freezed, Object? method = freezed, Object? body = freezed, + Object? preRequestScript = freezed, Object? parameters = freezed, Object? headers = freezed, - Object? preRequestScript = freezed, + Object? authentication = freezed, Object? metaSortKey = freezed, Object? isPrivate = freezed, + Object? pathParameters = freezed, Object? afterResponseScript = freezed, - Object? settingSendCookies = freezed, Object? settingStoreCookies = freezed, + Object? settingSendCookies = freezed, Object? settingDisableRenderRequestBody = freezed, Object? settingEncodeUrl = freezed, Object? settingRebuildPath = freezed, Object? settingFollowRedirects = freezed, + Object? environment = freezed, + Object? environmentPropertyOrder = freezed, + Object? scope = freezed, + Object? data = freezed, + Object? dataPropertyOrder = freezed, + Object? color = freezed, + Object? cookies = freezed, + Object? fileName = freezed, + Object? contents = freezed, + Object? contentType = freezed, + Object? environmentType = freezed, + Object? kvPairData = freezed, Object? type = freezed, }) { return _then(_value.copyWith( @@ -424,6 +465,10 @@ class _$ResourceCopyWithImpl<$Res, $Val extends Resource> ? _value.body : body // ignore: cast_nullable_to_non_nullable as Body?, + preRequestScript: freezed == preRequestScript + ? _value.preRequestScript + : preRequestScript // ignore: cast_nullable_to_non_nullable + as String?, parameters: freezed == parameters ? _value.parameters : parameters // ignore: cast_nullable_to_non_nullable @@ -432,10 +477,10 @@ class _$ResourceCopyWithImpl<$Res, $Val extends Resource> ? _value.headers : headers // ignore: cast_nullable_to_non_nullable as List
?, - preRequestScript: freezed == preRequestScript - ? _value.preRequestScript - : preRequestScript // ignore: cast_nullable_to_non_nullable - as String?, + authentication: freezed == authentication + ? _value.authentication + : authentication // ignore: cast_nullable_to_non_nullable + as dynamic, metaSortKey: freezed == metaSortKey ? _value.metaSortKey : metaSortKey // ignore: cast_nullable_to_non_nullable @@ -444,18 +489,22 @@ class _$ResourceCopyWithImpl<$Res, $Val extends Resource> ? _value.isPrivate : isPrivate // ignore: cast_nullable_to_non_nullable as bool?, + pathParameters: freezed == pathParameters + ? _value.pathParameters + : pathParameters // ignore: cast_nullable_to_non_nullable + as List?, afterResponseScript: freezed == afterResponseScript ? _value.afterResponseScript : afterResponseScript // ignore: cast_nullable_to_non_nullable as String?, - settingSendCookies: freezed == settingSendCookies - ? _value.settingSendCookies - : settingSendCookies // ignore: cast_nullable_to_non_nullable - as bool?, settingStoreCookies: freezed == settingStoreCookies ? _value.settingStoreCookies : settingStoreCookies // ignore: cast_nullable_to_non_nullable as bool?, + settingSendCookies: freezed == settingSendCookies + ? _value.settingSendCookies + : settingSendCookies // ignore: cast_nullable_to_non_nullable + as bool?, settingDisableRenderRequestBody: freezed == settingDisableRenderRequestBody ? _value.settingDisableRenderRequestBody @@ -473,6 +522,54 @@ class _$ResourceCopyWithImpl<$Res, $Val extends Resource> ? _value.settingFollowRedirects : settingFollowRedirects // ignore: cast_nullable_to_non_nullable as String?, + environment: freezed == environment + ? _value.environment + : environment // ignore: cast_nullable_to_non_nullable + as dynamic, + environmentPropertyOrder: freezed == environmentPropertyOrder + ? _value.environmentPropertyOrder + : environmentPropertyOrder // ignore: cast_nullable_to_non_nullable + as dynamic, + scope: freezed == scope + ? _value.scope + : scope // ignore: cast_nullable_to_non_nullable + as String?, + data: freezed == data + ? _value.data + : data // ignore: cast_nullable_to_non_nullable + as dynamic, + dataPropertyOrder: freezed == dataPropertyOrder + ? _value.dataPropertyOrder + : dataPropertyOrder // ignore: cast_nullable_to_non_nullable + as dynamic, + color: freezed == color + ? _value.color + : color // ignore: cast_nullable_to_non_nullable + as dynamic, + cookies: freezed == cookies + ? _value.cookies + : cookies // ignore: cast_nullable_to_non_nullable + as List?, + fileName: freezed == fileName + ? _value.fileName + : fileName // ignore: cast_nullable_to_non_nullable + as String?, + contents: freezed == contents + ? _value.contents + : contents // ignore: cast_nullable_to_non_nullable + as String?, + contentType: freezed == contentType + ? _value.contentType + : contentType // ignore: cast_nullable_to_non_nullable + as String?, + environmentType: freezed == environmentType + ? _value.environmentType + : environmentType // ignore: cast_nullable_to_non_nullable + as String?, + kvPairData: freezed == kvPairData + ? _value.kvPairData + : kvPairData // ignore: cast_nullable_to_non_nullable + as List?, type: freezed == type ? _value.type : type // ignore: cast_nullable_to_non_nullable @@ -505,7 +602,7 @@ abstract class _$$ResourceImplCopyWith<$Res> @useResult $Res call( {@JsonKey(name: '_id') String? id, - @JsonKey(name: 'parentId') String? parentId, + String? parentId, num? modified, num? created, String? url, @@ -513,18 +610,32 @@ abstract class _$$ResourceImplCopyWith<$Res> String? description, String? method, Body? body, + String? preRequestScript, List? parameters, List
? headers, - String? preRequestScript, + dynamic authentication, num? metaSortKey, bool? isPrivate, + List? pathParameters, String? afterResponseScript, - bool? settingSendCookies, bool? settingStoreCookies, + bool? settingSendCookies, bool? settingDisableRenderRequestBody, bool? settingEncodeUrl, bool? settingRebuildPath, String? settingFollowRedirects, + dynamic environment, + dynamic environmentPropertyOrder, + String? scope, + dynamic data, + dynamic dataPropertyOrder, + dynamic color, + List? cookies, + String? fileName, + String? contents, + String? contentType, + String? environmentType, + List? kvPairData, @JsonKey(name: '_type') String? type}); @override @@ -553,18 +664,32 @@ class __$$ResourceImplCopyWithImpl<$Res> Object? description = freezed, Object? method = freezed, Object? body = freezed, + Object? preRequestScript = freezed, Object? parameters = freezed, Object? headers = freezed, - Object? preRequestScript = freezed, + Object? authentication = freezed, Object? metaSortKey = freezed, Object? isPrivate = freezed, + Object? pathParameters = freezed, Object? afterResponseScript = freezed, - Object? settingSendCookies = freezed, Object? settingStoreCookies = freezed, + Object? settingSendCookies = freezed, Object? settingDisableRenderRequestBody = freezed, Object? settingEncodeUrl = freezed, Object? settingRebuildPath = freezed, Object? settingFollowRedirects = freezed, + Object? environment = freezed, + Object? environmentPropertyOrder = freezed, + Object? scope = freezed, + Object? data = freezed, + Object? dataPropertyOrder = freezed, + Object? color = freezed, + Object? cookies = freezed, + Object? fileName = freezed, + Object? contents = freezed, + Object? contentType = freezed, + Object? environmentType = freezed, + Object? kvPairData = freezed, Object? type = freezed, }) { return _then(_$ResourceImpl( @@ -604,6 +729,10 @@ class __$$ResourceImplCopyWithImpl<$Res> ? _value.body : body // ignore: cast_nullable_to_non_nullable as Body?, + preRequestScript: freezed == preRequestScript + ? _value.preRequestScript + : preRequestScript // ignore: cast_nullable_to_non_nullable + as String?, parameters: freezed == parameters ? _value._parameters : parameters // ignore: cast_nullable_to_non_nullable @@ -612,10 +741,10 @@ class __$$ResourceImplCopyWithImpl<$Res> ? _value._headers : headers // ignore: cast_nullable_to_non_nullable as List
?, - preRequestScript: freezed == preRequestScript - ? _value.preRequestScript - : preRequestScript // ignore: cast_nullable_to_non_nullable - as String?, + authentication: freezed == authentication + ? _value.authentication + : authentication // ignore: cast_nullable_to_non_nullable + as dynamic, metaSortKey: freezed == metaSortKey ? _value.metaSortKey : metaSortKey // ignore: cast_nullable_to_non_nullable @@ -624,18 +753,22 @@ class __$$ResourceImplCopyWithImpl<$Res> ? _value.isPrivate : isPrivate // ignore: cast_nullable_to_non_nullable as bool?, + pathParameters: freezed == pathParameters + ? _value._pathParameters + : pathParameters // ignore: cast_nullable_to_non_nullable + as List?, afterResponseScript: freezed == afterResponseScript ? _value.afterResponseScript : afterResponseScript // ignore: cast_nullable_to_non_nullable as String?, - settingSendCookies: freezed == settingSendCookies - ? _value.settingSendCookies - : settingSendCookies // ignore: cast_nullable_to_non_nullable - as bool?, settingStoreCookies: freezed == settingStoreCookies ? _value.settingStoreCookies : settingStoreCookies // ignore: cast_nullable_to_non_nullable as bool?, + settingSendCookies: freezed == settingSendCookies + ? _value.settingSendCookies + : settingSendCookies // ignore: cast_nullable_to_non_nullable + as bool?, settingDisableRenderRequestBody: freezed == settingDisableRenderRequestBody ? _value.settingDisableRenderRequestBody @@ -653,6 +786,54 @@ class __$$ResourceImplCopyWithImpl<$Res> ? _value.settingFollowRedirects : settingFollowRedirects // ignore: cast_nullable_to_non_nullable as String?, + environment: freezed == environment + ? _value.environment + : environment // ignore: cast_nullable_to_non_nullable + as dynamic, + environmentPropertyOrder: freezed == environmentPropertyOrder + ? _value.environmentPropertyOrder + : environmentPropertyOrder // ignore: cast_nullable_to_non_nullable + as dynamic, + scope: freezed == scope + ? _value.scope + : scope // ignore: cast_nullable_to_non_nullable + as String?, + data: freezed == data + ? _value.data + : data // ignore: cast_nullable_to_non_nullable + as dynamic, + dataPropertyOrder: freezed == dataPropertyOrder + ? _value.dataPropertyOrder + : dataPropertyOrder // ignore: cast_nullable_to_non_nullable + as dynamic, + color: freezed == color + ? _value.color + : color // ignore: cast_nullable_to_non_nullable + as dynamic, + cookies: freezed == cookies + ? _value._cookies + : cookies // ignore: cast_nullable_to_non_nullable + as List?, + fileName: freezed == fileName + ? _value.fileName + : fileName // ignore: cast_nullable_to_non_nullable + as String?, + contents: freezed == contents + ? _value.contents + : contents // ignore: cast_nullable_to_non_nullable + as String?, + contentType: freezed == contentType + ? _value.contentType + : contentType // ignore: cast_nullable_to_non_nullable + as String?, + environmentType: freezed == environmentType + ? _value.environmentType + : environmentType // ignore: cast_nullable_to_non_nullable + as String?, + kvPairData: freezed == kvPairData + ? _value._kvPairData + : kvPairData // ignore: cast_nullable_to_non_nullable + as List?, type: freezed == type ? _value.type : type // ignore: cast_nullable_to_non_nullable @@ -667,7 +848,7 @@ class __$$ResourceImplCopyWithImpl<$Res> class _$ResourceImpl implements _Resource { const _$ResourceImpl( {@JsonKey(name: '_id') this.id, - @JsonKey(name: 'parentId') this.parentId, + this.parentId, this.modified, this.created, this.url, @@ -675,21 +856,38 @@ class _$ResourceImpl implements _Resource { this.description, this.method, this.body, + this.preRequestScript, final List? parameters, final List
? headers, - this.preRequestScript, + this.authentication, this.metaSortKey, this.isPrivate, + final List? pathParameters, this.afterResponseScript, - this.settingSendCookies, this.settingStoreCookies, + this.settingSendCookies, this.settingDisableRenderRequestBody, this.settingEncodeUrl, this.settingRebuildPath, this.settingFollowRedirects, + this.environment, + this.environmentPropertyOrder, + this.scope, + this.data, + this.dataPropertyOrder, + this.color, + final List? cookies, + this.fileName, + this.contents, + this.contentType, + this.environmentType, + final List? kvPairData, @JsonKey(name: '_type') this.type}) : _parameters = parameters, - _headers = headers; + _headers = headers, + _pathParameters = pathParameters, + _cookies = cookies, + _kvPairData = kvPairData; factory _$ResourceImpl.fromJson(Map json) => _$$ResourceImplFromJson(json); @@ -698,7 +896,6 @@ class _$ResourceImpl implements _Resource { @JsonKey(name: '_id') final String? id; @override - @JsonKey(name: 'parentId') final String? parentId; @override final num? modified; @@ -714,6 +911,8 @@ class _$ResourceImpl implements _Resource { final String? method; @override final Body? body; + @override + final String? preRequestScript; final List? _parameters; @override List? get parameters { @@ -735,18 +934,28 @@ class _$ResourceImpl implements _Resource { } @override - final String? preRequestScript; + final dynamic authentication; @override final num? metaSortKey; @override final bool? isPrivate; + final List? _pathParameters; + @override + List? get pathParameters { + final value = _pathParameters; + if (value == null) return null; + if (_pathParameters is EqualUnmodifiableListView) return _pathParameters; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(value); + } + @override final String? afterResponseScript; @override - final bool? settingSendCookies; - @override final bool? settingStoreCookies; @override + final bool? settingSendCookies; + @override final bool? settingDisableRenderRequestBody; @override final bool? settingEncodeUrl; @@ -754,13 +963,53 @@ class _$ResourceImpl implements _Resource { final bool? settingRebuildPath; @override final String? settingFollowRedirects; + @override + final dynamic environment; + @override + final dynamic environmentPropertyOrder; + @override + final String? scope; + @override + final dynamic data; + @override + final dynamic dataPropertyOrder; + @override + final dynamic color; + final List? _cookies; + @override + List? get cookies { + final value = _cookies; + if (value == null) return null; + if (_cookies is EqualUnmodifiableListView) return _cookies; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(value); + } + + @override + final String? fileName; + @override + final String? contents; + @override + final String? contentType; + @override + final String? environmentType; + final List? _kvPairData; + @override + List? get kvPairData { + final value = _kvPairData; + if (value == null) return null; + if (_kvPairData is EqualUnmodifiableListView) return _kvPairData; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(value); + } + @override @JsonKey(name: '_type') final String? type; @override String toString() { - return 'Resource(id: $id, parentId: $parentId, modified: $modified, created: $created, url: $url, name: $name, description: $description, method: $method, body: $body, parameters: $parameters, headers: $headers, preRequestScript: $preRequestScript, metaSortKey: $metaSortKey, isPrivate: $isPrivate, afterResponseScript: $afterResponseScript, settingSendCookies: $settingSendCookies, settingStoreCookies: $settingStoreCookies, settingDisableRenderRequestBody: $settingDisableRenderRequestBody, settingEncodeUrl: $settingEncodeUrl, settingRebuildPath: $settingRebuildPath, settingFollowRedirects: $settingFollowRedirects, type: $type)'; + return 'Resource(id: $id, parentId: $parentId, modified: $modified, created: $created, url: $url, name: $name, description: $description, method: $method, body: $body, preRequestScript: $preRequestScript, parameters: $parameters, headers: $headers, authentication: $authentication, metaSortKey: $metaSortKey, isPrivate: $isPrivate, pathParameters: $pathParameters, afterResponseScript: $afterResponseScript, settingStoreCookies: $settingStoreCookies, settingSendCookies: $settingSendCookies, settingDisableRenderRequestBody: $settingDisableRenderRequestBody, settingEncodeUrl: $settingEncodeUrl, settingRebuildPath: $settingRebuildPath, settingFollowRedirects: $settingFollowRedirects, environment: $environment, environmentPropertyOrder: $environmentPropertyOrder, scope: $scope, data: $data, dataPropertyOrder: $dataPropertyOrder, color: $color, cookies: $cookies, fileName: $fileName, contents: $contents, contentType: $contentType, environmentType: $environmentType, kvPairData: $kvPairData, type: $type)'; } @override @@ -780,21 +1029,25 @@ class _$ResourceImpl implements _Resource { other.description == description) && (identical(other.method, method) || other.method == method) && (identical(other.body, body) || other.body == body) && + (identical(other.preRequestScript, preRequestScript) || + other.preRequestScript == preRequestScript) && const DeepCollectionEquality() .equals(other._parameters, _parameters) && const DeepCollectionEquality().equals(other._headers, _headers) && - (identical(other.preRequestScript, preRequestScript) || - other.preRequestScript == preRequestScript) && + const DeepCollectionEquality() + .equals(other.authentication, authentication) && (identical(other.metaSortKey, metaSortKey) || other.metaSortKey == metaSortKey) && (identical(other.isPrivate, isPrivate) || other.isPrivate == isPrivate) && + const DeepCollectionEquality() + .equals(other._pathParameters, _pathParameters) && (identical(other.afterResponseScript, afterResponseScript) || other.afterResponseScript == afterResponseScript) && - (identical(other.settingSendCookies, settingSendCookies) || - other.settingSendCookies == settingSendCookies) && (identical(other.settingStoreCookies, settingStoreCookies) || other.settingStoreCookies == settingStoreCookies) && + (identical(other.settingSendCookies, settingSendCookies) || + other.settingSendCookies == settingSendCookies) && (identical(other.settingDisableRenderRequestBody, settingDisableRenderRequestBody) || other.settingDisableRenderRequestBody == @@ -805,6 +1058,26 @@ class _$ResourceImpl implements _Resource { other.settingRebuildPath == settingRebuildPath) && (identical(other.settingFollowRedirects, settingFollowRedirects) || other.settingFollowRedirects == settingFollowRedirects) && + const DeepCollectionEquality() + .equals(other.environment, environment) && + const DeepCollectionEquality().equals( + other.environmentPropertyOrder, environmentPropertyOrder) && + (identical(other.scope, scope) || other.scope == scope) && + const DeepCollectionEquality().equals(other.data, data) && + const DeepCollectionEquality() + .equals(other.dataPropertyOrder, dataPropertyOrder) && + const DeepCollectionEquality().equals(other.color, color) && + const DeepCollectionEquality().equals(other._cookies, _cookies) && + (identical(other.fileName, fileName) || + other.fileName == fileName) && + (identical(other.contents, contents) || + other.contents == contents) && + (identical(other.contentType, contentType) || + other.contentType == contentType) && + (identical(other.environmentType, environmentType) || + other.environmentType == environmentType) && + const DeepCollectionEquality() + .equals(other._kvPairData, _kvPairData) && (identical(other.type, type) || other.type == type)); } @@ -821,18 +1094,32 @@ class _$ResourceImpl implements _Resource { description, method, body, + preRequestScript, const DeepCollectionEquality().hash(_parameters), const DeepCollectionEquality().hash(_headers), - preRequestScript, + const DeepCollectionEquality().hash(authentication), metaSortKey, isPrivate, + const DeepCollectionEquality().hash(_pathParameters), afterResponseScript, - settingSendCookies, settingStoreCookies, + settingSendCookies, settingDisableRenderRequestBody, settingEncodeUrl, settingRebuildPath, settingFollowRedirects, + const DeepCollectionEquality().hash(environment), + const DeepCollectionEquality().hash(environmentPropertyOrder), + scope, + const DeepCollectionEquality().hash(data), + const DeepCollectionEquality().hash(dataPropertyOrder), + const DeepCollectionEquality().hash(color), + const DeepCollectionEquality().hash(_cookies), + fileName, + contents, + contentType, + environmentType, + const DeepCollectionEquality().hash(_kvPairData), type ]); @@ -855,7 +1142,7 @@ class _$ResourceImpl implements _Resource { abstract class _Resource implements Resource { const factory _Resource( {@JsonKey(name: '_id') final String? id, - @JsonKey(name: 'parentId') final String? parentId, + final String? parentId, final num? modified, final num? created, final String? url, @@ -863,18 +1150,32 @@ abstract class _Resource implements Resource { final String? description, final String? method, final Body? body, + final String? preRequestScript, final List? parameters, final List
? headers, - final String? preRequestScript, + final dynamic authentication, final num? metaSortKey, final bool? isPrivate, + final List? pathParameters, final String? afterResponseScript, - final bool? settingSendCookies, final bool? settingStoreCookies, + final bool? settingSendCookies, final bool? settingDisableRenderRequestBody, final bool? settingEncodeUrl, final bool? settingRebuildPath, final String? settingFollowRedirects, + final dynamic environment, + final dynamic environmentPropertyOrder, + final String? scope, + final dynamic data, + final dynamic dataPropertyOrder, + final dynamic color, + final List? cookies, + final String? fileName, + final String? contents, + final String? contentType, + final String? environmentType, + final List? kvPairData, @JsonKey(name: '_type') final String? type}) = _$ResourceImpl; factory _Resource.fromJson(Map json) = @@ -884,7 +1185,6 @@ abstract class _Resource implements Resource { @JsonKey(name: '_id') String? get id; @override - @JsonKey(name: 'parentId') String? get parentId; @override num? get modified; @@ -901,22 +1201,26 @@ abstract class _Resource implements Resource { @override Body? get body; @override + String? get preRequestScript; + @override List? get parameters; @override List
? get headers; @override - String? get preRequestScript; + dynamic get authentication; @override num? get metaSortKey; @override bool? get isPrivate; @override + List? get pathParameters; + @override String? get afterResponseScript; @override - bool? get settingSendCookies; - @override bool? get settingStoreCookies; @override + bool? get settingSendCookies; + @override bool? get settingDisableRenderRequestBody; @override bool? get settingEncodeUrl; @@ -925,6 +1229,30 @@ abstract class _Resource implements Resource { @override String? get settingFollowRedirects; @override + dynamic get environment; + @override + dynamic get environmentPropertyOrder; + @override + String? get scope; + @override + dynamic get data; + @override + dynamic get dataPropertyOrder; + @override + dynamic get color; + @override + List? get cookies; + @override + String? get fileName; + @override + String? get contents; + @override + String? get contentType; + @override + String? get environmentType; + @override + List? get kvPairData; + @override @JsonKey(name: '_type') String? get type; @@ -1752,3 +2080,581 @@ abstract class _Header implements Header { _$$HeaderImplCopyWith<_$HeaderImpl> get copyWith => throw _privateConstructorUsedError; } + +Cookie _$CookieFromJson(Map json) { + return _Cookie.fromJson(json); +} + +/// @nodoc +mixin _$Cookie { + String? get key => throw _privateConstructorUsedError; + String? get value => throw _privateConstructorUsedError; + String? get domain => throw _privateConstructorUsedError; + String? get path => throw _privateConstructorUsedError; + bool? get secure => throw _privateConstructorUsedError; + bool? get httpOnly => throw _privateConstructorUsedError; + bool? get hostOnly => throw _privateConstructorUsedError; + DateTime? get creation => throw _privateConstructorUsedError; + DateTime? get lastAccessed => throw _privateConstructorUsedError; + String? get sameSite => throw _privateConstructorUsedError; + String? get id => throw _privateConstructorUsedError; + + /// Serializes this Cookie to a JSON map. + Map toJson() => throw _privateConstructorUsedError; + + /// Create a copy of Cookie + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + $CookieCopyWith get copyWith => throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $CookieCopyWith<$Res> { + factory $CookieCopyWith(Cookie value, $Res Function(Cookie) then) = + _$CookieCopyWithImpl<$Res, Cookie>; + @useResult + $Res call( + {String? key, + String? value, + String? domain, + String? path, + bool? secure, + bool? httpOnly, + bool? hostOnly, + DateTime? creation, + DateTime? lastAccessed, + String? sameSite, + String? id}); +} + +/// @nodoc +class _$CookieCopyWithImpl<$Res, $Val extends Cookie> + implements $CookieCopyWith<$Res> { + _$CookieCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of Cookie + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? key = freezed, + Object? value = freezed, + Object? domain = freezed, + Object? path = freezed, + Object? secure = freezed, + Object? httpOnly = freezed, + Object? hostOnly = freezed, + Object? creation = freezed, + Object? lastAccessed = freezed, + Object? sameSite = freezed, + Object? id = freezed, + }) { + return _then(_value.copyWith( + key: freezed == key + ? _value.key + : key // ignore: cast_nullable_to_non_nullable + as String?, + value: freezed == value + ? _value.value + : value // ignore: cast_nullable_to_non_nullable + as String?, + domain: freezed == domain + ? _value.domain + : domain // ignore: cast_nullable_to_non_nullable + as String?, + path: freezed == path + ? _value.path + : path // ignore: cast_nullable_to_non_nullable + as String?, + secure: freezed == secure + ? _value.secure + : secure // ignore: cast_nullable_to_non_nullable + as bool?, + httpOnly: freezed == httpOnly + ? _value.httpOnly + : httpOnly // ignore: cast_nullable_to_non_nullable + as bool?, + hostOnly: freezed == hostOnly + ? _value.hostOnly + : hostOnly // ignore: cast_nullable_to_non_nullable + as bool?, + creation: freezed == creation + ? _value.creation + : creation // ignore: cast_nullable_to_non_nullable + as DateTime?, + lastAccessed: freezed == lastAccessed + ? _value.lastAccessed + : lastAccessed // ignore: cast_nullable_to_non_nullable + as DateTime?, + sameSite: freezed == sameSite + ? _value.sameSite + : sameSite // ignore: cast_nullable_to_non_nullable + as String?, + id: freezed == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as String?, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$CookieImplCopyWith<$Res> implements $CookieCopyWith<$Res> { + factory _$$CookieImplCopyWith( + _$CookieImpl value, $Res Function(_$CookieImpl) then) = + __$$CookieImplCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {String? key, + String? value, + String? domain, + String? path, + bool? secure, + bool? httpOnly, + bool? hostOnly, + DateTime? creation, + DateTime? lastAccessed, + String? sameSite, + String? id}); +} + +/// @nodoc +class __$$CookieImplCopyWithImpl<$Res> + extends _$CookieCopyWithImpl<$Res, _$CookieImpl> + implements _$$CookieImplCopyWith<$Res> { + __$$CookieImplCopyWithImpl( + _$CookieImpl _value, $Res Function(_$CookieImpl) _then) + : super(_value, _then); + + /// Create a copy of Cookie + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? key = freezed, + Object? value = freezed, + Object? domain = freezed, + Object? path = freezed, + Object? secure = freezed, + Object? httpOnly = freezed, + Object? hostOnly = freezed, + Object? creation = freezed, + Object? lastAccessed = freezed, + Object? sameSite = freezed, + Object? id = freezed, + }) { + return _then(_$CookieImpl( + key: freezed == key + ? _value.key + : key // ignore: cast_nullable_to_non_nullable + as String?, + value: freezed == value + ? _value.value + : value // ignore: cast_nullable_to_non_nullable + as String?, + domain: freezed == domain + ? _value.domain + : domain // ignore: cast_nullable_to_non_nullable + as String?, + path: freezed == path + ? _value.path + : path // ignore: cast_nullable_to_non_nullable + as String?, + secure: freezed == secure + ? _value.secure + : secure // ignore: cast_nullable_to_non_nullable + as bool?, + httpOnly: freezed == httpOnly + ? _value.httpOnly + : httpOnly // ignore: cast_nullable_to_non_nullable + as bool?, + hostOnly: freezed == hostOnly + ? _value.hostOnly + : hostOnly // ignore: cast_nullable_to_non_nullable + as bool?, + creation: freezed == creation + ? _value.creation + : creation // ignore: cast_nullable_to_non_nullable + as DateTime?, + lastAccessed: freezed == lastAccessed + ? _value.lastAccessed + : lastAccessed // ignore: cast_nullable_to_non_nullable + as DateTime?, + sameSite: freezed == sameSite + ? _value.sameSite + : sameSite // ignore: cast_nullable_to_non_nullable + as String?, + id: freezed == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as String?, + )); + } +} + +/// @nodoc + +@JsonSerializable(explicitToJson: true, anyMap: true, includeIfNull: false) +class _$CookieImpl implements _Cookie { + const _$CookieImpl( + {this.key, + this.value, + this.domain, + this.path, + this.secure, + this.httpOnly, + this.hostOnly, + this.creation, + this.lastAccessed, + this.sameSite, + this.id}); + + factory _$CookieImpl.fromJson(Map json) => + _$$CookieImplFromJson(json); + + @override + final String? key; + @override + final String? value; + @override + final String? domain; + @override + final String? path; + @override + final bool? secure; + @override + final bool? httpOnly; + @override + final bool? hostOnly; + @override + final DateTime? creation; + @override + final DateTime? lastAccessed; + @override + final String? sameSite; + @override + final String? id; + + @override + String toString() { + return 'Cookie(key: $key, value: $value, domain: $domain, path: $path, secure: $secure, httpOnly: $httpOnly, hostOnly: $hostOnly, creation: $creation, lastAccessed: $lastAccessed, sameSite: $sameSite, id: $id)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$CookieImpl && + (identical(other.key, key) || other.key == key) && + (identical(other.value, value) || other.value == value) && + (identical(other.domain, domain) || other.domain == domain) && + (identical(other.path, path) || other.path == path) && + (identical(other.secure, secure) || other.secure == secure) && + (identical(other.httpOnly, httpOnly) || + other.httpOnly == httpOnly) && + (identical(other.hostOnly, hostOnly) || + other.hostOnly == hostOnly) && + (identical(other.creation, creation) || + other.creation == creation) && + (identical(other.lastAccessed, lastAccessed) || + other.lastAccessed == lastAccessed) && + (identical(other.sameSite, sameSite) || + other.sameSite == sameSite) && + (identical(other.id, id) || other.id == id)); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => Object.hash(runtimeType, key, value, domain, path, secure, + httpOnly, hostOnly, creation, lastAccessed, sameSite, id); + + /// Create a copy of Cookie + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$CookieImplCopyWith<_$CookieImpl> get copyWith => + __$$CookieImplCopyWithImpl<_$CookieImpl>(this, _$identity); + + @override + Map toJson() { + return _$$CookieImplToJson( + this, + ); + } +} + +abstract class _Cookie implements Cookie { + const factory _Cookie( + {final String? key, + final String? value, + final String? domain, + final String? path, + final bool? secure, + final bool? httpOnly, + final bool? hostOnly, + final DateTime? creation, + final DateTime? lastAccessed, + final String? sameSite, + final String? id}) = _$CookieImpl; + + factory _Cookie.fromJson(Map json) = _$CookieImpl.fromJson; + + @override + String? get key; + @override + String? get value; + @override + String? get domain; + @override + String? get path; + @override + bool? get secure; + @override + bool? get httpOnly; + @override + bool? get hostOnly; + @override + DateTime? get creation; + @override + DateTime? get lastAccessed; + @override + String? get sameSite; + @override + String? get id; + + /// Create a copy of Cookie + /// with the given fields replaced by the non-null parameter values. + @override + @JsonKey(includeFromJson: false, includeToJson: false) + _$$CookieImplCopyWith<_$CookieImpl> get copyWith => + throw _privateConstructorUsedError; +} + +KVPairDatum _$KVPairDatumFromJson(Map json) { + return _KVPairDatum.fromJson(json); +} + +/// @nodoc +mixin _$KVPairDatum { + String? get id => throw _privateConstructorUsedError; + String? get name => throw _privateConstructorUsedError; + String? get value => throw _privateConstructorUsedError; + String? get type => throw _privateConstructorUsedError; + bool? get enabled => throw _privateConstructorUsedError; + + /// Serializes this KVPairDatum to a JSON map. + Map toJson() => throw _privateConstructorUsedError; + + /// Create a copy of KVPairDatum + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + $KVPairDatumCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $KVPairDatumCopyWith<$Res> { + factory $KVPairDatumCopyWith( + KVPairDatum value, $Res Function(KVPairDatum) then) = + _$KVPairDatumCopyWithImpl<$Res, KVPairDatum>; + @useResult + $Res call( + {String? id, String? name, String? value, String? type, bool? enabled}); +} + +/// @nodoc +class _$KVPairDatumCopyWithImpl<$Res, $Val extends KVPairDatum> + implements $KVPairDatumCopyWith<$Res> { + _$KVPairDatumCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of KVPairDatum + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = freezed, + Object? name = freezed, + Object? value = freezed, + Object? type = freezed, + Object? enabled = freezed, + }) { + return _then(_value.copyWith( + id: freezed == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as String?, + name: freezed == name + ? _value.name + : name // ignore: cast_nullable_to_non_nullable + as String?, + value: freezed == value + ? _value.value + : value // ignore: cast_nullable_to_non_nullable + as String?, + type: freezed == type + ? _value.type + : type // ignore: cast_nullable_to_non_nullable + as String?, + enabled: freezed == enabled + ? _value.enabled + : enabled // ignore: cast_nullable_to_non_nullable + as bool?, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$KVPairDatumImplCopyWith<$Res> + implements $KVPairDatumCopyWith<$Res> { + factory _$$KVPairDatumImplCopyWith( + _$KVPairDatumImpl value, $Res Function(_$KVPairDatumImpl) then) = + __$$KVPairDatumImplCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {String? id, String? name, String? value, String? type, bool? enabled}); +} + +/// @nodoc +class __$$KVPairDatumImplCopyWithImpl<$Res> + extends _$KVPairDatumCopyWithImpl<$Res, _$KVPairDatumImpl> + implements _$$KVPairDatumImplCopyWith<$Res> { + __$$KVPairDatumImplCopyWithImpl( + _$KVPairDatumImpl _value, $Res Function(_$KVPairDatumImpl) _then) + : super(_value, _then); + + /// Create a copy of KVPairDatum + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = freezed, + Object? name = freezed, + Object? value = freezed, + Object? type = freezed, + Object? enabled = freezed, + }) { + return _then(_$KVPairDatumImpl( + id: freezed == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as String?, + name: freezed == name + ? _value.name + : name // ignore: cast_nullable_to_non_nullable + as String?, + value: freezed == value + ? _value.value + : value // ignore: cast_nullable_to_non_nullable + as String?, + type: freezed == type + ? _value.type + : type // ignore: cast_nullable_to_non_nullable + as String?, + enabled: freezed == enabled + ? _value.enabled + : enabled // ignore: cast_nullable_to_non_nullable + as bool?, + )); + } +} + +/// @nodoc + +@JsonSerializable(explicitToJson: true, anyMap: true, includeIfNull: false) +class _$KVPairDatumImpl implements _KVPairDatum { + const _$KVPairDatumImpl( + {this.id, this.name, this.value, this.type, this.enabled}); + + factory _$KVPairDatumImpl.fromJson(Map json) => + _$$KVPairDatumImplFromJson(json); + + @override + final String? id; + @override + final String? name; + @override + final String? value; + @override + final String? type; + @override + final bool? enabled; + + @override + String toString() { + return 'KVPairDatum(id: $id, name: $name, value: $value, type: $type, enabled: $enabled)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$KVPairDatumImpl && + (identical(other.id, id) || other.id == id) && + (identical(other.name, name) || other.name == name) && + (identical(other.value, value) || other.value == value) && + (identical(other.type, type) || other.type == type) && + (identical(other.enabled, enabled) || other.enabled == enabled)); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => Object.hash(runtimeType, id, name, value, type, enabled); + + /// Create a copy of KVPairDatum + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$KVPairDatumImplCopyWith<_$KVPairDatumImpl> get copyWith => + __$$KVPairDatumImplCopyWithImpl<_$KVPairDatumImpl>(this, _$identity); + + @override + Map toJson() { + return _$$KVPairDatumImplToJson( + this, + ); + } +} + +abstract class _KVPairDatum implements KVPairDatum { + const factory _KVPairDatum( + {final String? id, + final String? name, + final String? value, + final String? type, + final bool? enabled}) = _$KVPairDatumImpl; + + factory _KVPairDatum.fromJson(Map json) = + _$KVPairDatumImpl.fromJson; + + @override + String? get id; + @override + String? get name; + @override + String? get value; + @override + String? get type; + @override + bool? get enabled; + + /// Create a copy of KVPairDatum + /// with the given fields replaced by the non-null parameter values. + @override + @JsonKey(includeFromJson: false, includeToJson: false) + _$$KVPairDatumImplCopyWith<_$KVPairDatumImpl> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/packages/insomnia_collection/lib/models/insomnia_collection.g.dart b/packages/insomnia_collection/lib/models/insomnia_collection.g.dart index 0e279c5a..431aa70d 100644 --- a/packages/insomnia_collection/lib/models/insomnia_collection.g.dart +++ b/packages/insomnia_collection/lib/models/insomnia_collection.g.dart @@ -40,23 +40,42 @@ _$ResourceImpl _$$ResourceImplFromJson(Map json) => _$ResourceImpl( body: json['body'] == null ? null : Body.fromJson(Map.from(json['body'] as Map)), + preRequestScript: json['preRequestScript'] as String?, parameters: (json['parameters'] as List?) ?.map((e) => Parameter.fromJson(Map.from(e as Map))) .toList(), headers: (json['headers'] as List?) ?.map((e) => Header.fromJson(Map.from(e as Map))) .toList(), - preRequestScript: json['preRequestScript'] as String?, + authentication: json['authentication'], metaSortKey: json['metaSortKey'] as num?, isPrivate: json['isPrivate'] as bool?, + pathParameters: json['pathParameters'] as List?, afterResponseScript: json['afterResponseScript'] as String?, - settingSendCookies: json['settingSendCookies'] as bool?, settingStoreCookies: json['settingStoreCookies'] as bool?, + settingSendCookies: json['settingSendCookies'] as bool?, settingDisableRenderRequestBody: json['settingDisableRenderRequestBody'] as bool?, settingEncodeUrl: json['settingEncodeUrl'] as bool?, settingRebuildPath: json['settingRebuildPath'] as bool?, 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?) + ?.map((e) => Cookie.fromJson(Map.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?) + ?.map( + (e) => KVPairDatum.fromJson(Map.from(e as Map))) + .toList(), type: json['_type'] as String?, ); @@ -71,21 +90,23 @@ Map _$$ResourceImplToJson(_$ResourceImpl instance) => 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.preRequestScript case final value?) + 'preRequestScript': 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.authentication case final value?) 'authentication': value, if (instance.metaSortKey case final value?) 'metaSortKey': value, if (instance.isPrivate case final value?) 'isPrivate': value, + if (instance.pathParameters case final value?) 'pathParameters': 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.settingSendCookies case final value?) + 'settingSendCookies': value, if (instance.settingDisableRenderRequestBody case final value?) 'settingDisableRenderRequestBody': value, if (instance.settingEncodeUrl case final value?) @@ -94,6 +115,23 @@ Map _$$ResourceImplToJson(_$ResourceImpl instance) => 'settingRebuildPath': value, if (instance.settingFollowRedirects case final 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, }; @@ -157,3 +195,55 @@ Map _$$HeaderImplToJson(_$HeaderImpl instance) => if (instance.value case final value?) 'value': 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 _$$CookieImplToJson(_$CookieImpl instance) => + { + 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 _$$KVPairDatumImplToJson(_$KVPairDatumImpl instance) => + { + 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, + }; From 707ea116aa7c66a884d8ad21a0c71c983a6147ec Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Mon, 24 Feb 2025 11:13:01 +0530 Subject: [PATCH 17/42] Create insomnia_item.dart --- .../lib/models/insomnia_item.dart | 102 ++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 packages/insomnia_collection/lib/models/insomnia_item.dart diff --git a/packages/insomnia_collection/lib/models/insomnia_item.dart b/packages/insomnia_collection/lib/models/insomnia_item.dart new file mode 100644 index 00000000..c906baf9 --- /dev/null +++ b/packages/insomnia_collection/lib/models/insomnia_item.dart @@ -0,0 +1,102 @@ +import 'insomnia_collection.dart'; + +enum ResourceType { + workspace, + environment, + request_group, + cookie_jar, + request, + websocket_payload, + api_spec +} + +class InsomniaItem { + const InsomniaItem({ + this.id, + this.type, + this.resource, + this.children, + }); + + final String? id; + final ResourceType? type; + final Resource? resource; + final List? children; + + factory InsomniaItem.fromInsomniaCollection( + InsomniaCollection? collection, + ) { + if (collection?.resources == null) { + return InsomniaItem(); + } + final resources = collection!.resources!; + final resourceMap = {for (var v in resources) v.id!: v}; + Map> childrenMap = {}; + for (var item in resources) { + if (item.parentId != null && item.id != null) { + if (childrenMap.containsKey(item.parentId)) { + childrenMap[item.parentId]!.add(item.id!); + } else { + childrenMap[item.parentId!] = [item.id!]; + } + } + } + var wksp; + for (var item in resources) { + if (item.type == ResourceType.workspace.name) { + wksp = InsomniaItem( + id: item.id, + type: ResourceType.workspace, + resource: item, + children: getInsomniaItemChildren( + childrenMap[item.id], + childrenMap, + resourceMap, + ), + ); + break; + } + } + return wksp; + } +} + +List? getInsomniaItemChildren( + List? ids, + Map> childrenMap, + Map resourceMap, +) { + if (ids == null) { + return null; + } + List children = []; + for (var itemId in ids) { + var resource = resourceMap[itemId]; + ResourceType? type; + try { + type = ResourceType.values.byName(resource?.type ?? ''); + } catch (e) { + type = null; + } + if (childrenMap.containsKey(itemId)) { + children.add(InsomniaItem( + id: itemId, + type: type, + resource: resource, + children: getInsomniaItemChildren( + childrenMap[itemId], + childrenMap, + resourceMap, + ), + )); + } else { + children.add(InsomniaItem( + id: itemId, + type: type, + resource: resource, + children: null, + )); + } + } + return children; +} From 6ccd395ba1695502a8428a41c691e5a2fd1c89e4 Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Mon, 24 Feb 2025 11:13:05 +0530 Subject: [PATCH 18/42] Update models.dart --- packages/insomnia_collection/lib/models/models.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/insomnia_collection/lib/models/models.dart b/packages/insomnia_collection/lib/models/models.dart index 881e622e..12e1aa42 100644 --- a/packages/insomnia_collection/lib/models/models.dart +++ b/packages/insomnia_collection/lib/models/models.dart @@ -1 +1,2 @@ -export 'insomnia_collection.dart'; \ No newline at end of file +export 'insomnia_collection.dart'; +export 'insomnia_item.dart'; From 903dc96eea8ba4c7822fc1fa006df921e5fcfabc Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Mon, 24 Feb 2025 11:13:11 +0530 Subject: [PATCH 19/42] Update insomnia_utils.dart --- .../lib/utils/insomnia_utils.dart | 54 ++++++------------- 1 file changed, 16 insertions(+), 38 deletions(-) diff --git a/packages/insomnia_collection/lib/utils/insomnia_utils.dart b/packages/insomnia_collection/lib/utils/insomnia_utils.dart index c0ab145e..50a1d41a 100644 --- a/packages/insomnia_collection/lib/utils/insomnia_utils.dart +++ b/packages/insomnia_collection/lib/utils/insomnia_utils.dart @@ -1,47 +1,25 @@ - - - -import 'package:insomnia_collection/models/insomnia_collection.dart'; -import 'package:insomnia_collection/models/insomnia_environment.dart'; +import '../models/models.dart'; List<(String?, Resource)> getRequestsFromInsomniaCollection( - InsomniaCollection? ic) { - if (ic == null || ic.resources == null) { + InsomniaCollection? ic) => + getItemByTypeFromInsomniaCollection(ic, ResourceType.request.name); + +List<(String?, Resource)> getEnvironmentsFromInsomniaCollection( + InsomniaCollection? ic) => + getItemByTypeFromInsomniaCollection(ic, ResourceType.environment.name); + +List<(String?, Resource)> getItemByTypeFromInsomniaCollection( + InsomniaCollection? ic, + String type, +) { + if (ic?.resources == null || ic!.resources!.length > 0) { return []; } List<(String?, Resource)> requests = []; - if (ic.resources!.length > 0) { - for (var i in ic.resources!) { - requests.addAll(getRequestsFromInsomniaResource(i)); + for (var item in ic.resources!) { + if (item.type != null || item.type == type) { + requests.add((item.name, item)); } } return requests; } - -List getEnvironmentVariablesFromInsomniaEnvironment( - InsomniaEnvironment? ev) { - if (ev == null || ev.resources == null) { - return []; - } - List envVariables = []; - if (ev.resources!.length > 0) { - for (var envvar in ev.resources!) { - envVariables.add(envvar); - } - } - return envVariables; -} - -List<(String?, Resource)> getRequestsFromInsomniaResource(Resource? resource) { - if (resource == null) { - return []; - } - List<(String?, Resource)> requests = []; - if (resource.type != null || resource.type == 'request') { - requests.add((resource.name, resource)); - } else { - print('Resource type is not request'); - } - return requests; -} - From a7b5966f8b122956e478bea5629a901773471421 Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Mon, 24 Feb 2025 11:13:20 +0530 Subject: [PATCH 20/42] Fix tests --- .../collection_apidash.dart | 339 ++++++++++-------- .../test/insomnia_test.dart | 21 +- .../test/models/collection_apidash_model.dart | 309 +++++++++------- 3 files changed, 380 insertions(+), 289 deletions(-) diff --git a/packages/insomnia_collection/test/collection_examples/collection_apidash.dart b/packages/insomnia_collection/test/collection_examples/collection_apidash.dart index 918dcf39..7c836e30 100644 --- a/packages/insomnia_collection/test/collection_examples/collection_apidash.dart +++ b/packages/insomnia_collection/test/collection_examples/collection_apidash.dart @@ -1,152 +1,183 @@ -var collectionApiDashJsonStr = r''' -{ +var collectionApiDashJsonStr = r'''{ "_type": "export", "__export_format": 4, "__export_date": "2025-01-05T13:05:11.752Z", "__export_source": "insomnia.desktop.app:v10.3.0", "resources": [ { - "_id":"req_15f4d64ca3084a92a0680e29a958c9da", - "parentId":"fld_a2e9704c49034e36a05cdb3a233f6ebd", - "modified":1736112258432, - "created":1736111908438, - "url":"https://food-service-backend.onrender.com/api/users/", - "name":"get-with-params", - "description":"", - "method":"GET", - "body":{}, - "parameters": [{"id":"pair_bf0ae4f4280e440a8a591b64fd4ec4f4","name":"user_id","value":"34","description":"","disabled":false} - ], - "headers":[{"name":"User-Agent","value":"insomnia/10.3.0"}], - "authentication":{}, - "metaSortKey":-1736111908438, - "isPrivate":false, - "pathParameters":[], - "settingStoreCookies":true, - "settingSendCookies":true, - "settingDisableRenderRequestBody":false, - "settingEncodeUrl":true, - "settingRebuildPath":true, - "settingFollowRedirects": "global", - "_type":"request" - }, - { - "_id":"fld_a2e9704c49034e36a05cdb3a233f6ebd", - "parentId":"wrk_fde7dcc4f5064b74b0fd749cbf8f684a", - "modified":1736082089076, - "created":1736082089076, - "name":"APIDash-APItests", - "description":"These are test endpoints for API Dash", - "environment":{}, - "environmentPropertyOrder":null, - "metaSortKey":-1736082080559, - "preRequestScript":"", - "afterResponseScript":"", - "authentication":{}, - "_type":"request_group" - }, -{ -"_id":"wrk_fde7dcc4f5064b74b0fd749cbf8f684a", -"parentId":null, -"modified":1736082089075, -"created":1736082089075, -"name":"APIDash-APItests","description":"", -"scope":"collection","_type":"workspace"}, -{ -"_id":"req_db3c393084f14369bb409afe857e390c", -"parentId":"fld_a2e9704c49034e36a05cdb3a233f6ebd", -"modified":1736082089077, -"created":1736082089077, -"url":"https://api.apidash.dev/country/codes", -"name":"test-get", -"description":"", -"method":"GET", -"body":{}, -"parameters":[], -"headers":[], -"authentication":{}, -"preRequestScript":"", -"metaSortKey":-1736082080558, -"isPrivate":false, -"afterResponseScript":"", -"settingStoreCookies":true, -"settingSendCookies":true, -"settingDisableRenderRequestBody":false, -"settingEncodeUrl":true, -"settingRebuildPath":true, -"settingFollowRedirects":"global", -"_type":"request"}, -{ -"_id":"req_ba718bbacd094e95a30ef3f07baa4e42", -"parentId":"fld_a2e9704c49034e36a05cdb3a233f6ebd", -"modified":1736082089078,"created":1736082089078, -"url":"https://api.apidash.dev/case/lower", -"name":"test-post", -"description":"", -"method":"POST", -"body":{"mimeType":"application/json","text":"{\n \"text\": \"Grass is green\"\n}"}, -"parameters":[], -"headers":[{"name":"Content-Type","value":"application/json"}], -"authentication":{}, -"preRequestScript":"", -"metaSortKey":-1736082080557, -"isPrivate":false, -"afterResponseScript":"", -"settingStoreCookies":true, -"settingSendCookies":true, -"settingDisableRenderRequestBody":false, -"settingEncodeUrl":true, -"settingRebuildPath":true, -"settingFollowRedirects":"global", -"_type":"request"}, -{"_id":"req_24cff90fc3c74e71a567f61d3f8e8cc1", -"parentId":"fld_a2e9704c49034e36a05cdb3a233f6ebd", -"modified":1736082089078, -"created":1736082089078, -"url":"https://reqres.in/api/users/2", -"name":"test-put", -"description":"", -"method":"PUT", -"body":{"mimeType":"application/json", -"text":"{\n \"name\": \"morpheus\",\n \"job\": \"zion resident\"\n}"}, -"parameters":[], -"headers":[{"name":"Content-Type","value":"application/json"}], -"authentication":{}, -"preRequestScript":"", -"metaSortKey":-1736082080556, -"isPrivate":false, -"afterResponseScript":"", -"settingStoreCookies":true, -"settingSendCookies":true, -"settingDisableRenderRequestBody":false, -"settingEncodeUrl":true, -"settingRebuildPath":true, -"settingFollowRedirects":"global", -"_type":"request"}, -{ -"_id":"env_9d818b2866dffc9831640d91a516ea3986e16bda", -"parentId":"wrk_fde7dcc4f5064b74b0fd749cbf8f684a", -"modified":1736082095630,"created":1736082095630, -"name":"Base Environment", -"data":{},"dataPropertyOrder":null, -"color":null, -"isPrivate":false, -"metaSortKey":1736082095630, -"environmentType":"kv", -"_type":"environment" -}, -{ -"_id":"jar_9d818b2866dffc9831640d91a516ea3986e16bda", -"parentId":"wrk_fde7dcc4f5064b74b0fd749cbf8f684a", -"modified":1736082095688, -"created":1736082095688, -"name":"Default Jar", -"cookies":[], -"_type":"cookie_jar" -} -] -} -'''; + "_id": "req_15f4d64ca3084a92a0680e29a958c9da", + "parentId": "fld_a2e9704c49034e36a05cdb3a233f6ebd", + "modified": 1736112258432, + "created": 1736111908438, + "url": "https://food-service-backend.onrender.com/api/users/", + "name": "get-with-params", + "description": "", + "method": "GET", + "body": {}, + "parameters": [ + { + "id": "pair_bf0ae4f4280e440a8a591b64fd4ec4f4", + "name": "user_id", + "value": "34", + "description": "", + "disabled": false + } + ], + "headers": [ + { + "name": "User-Agent", + "value": "insomnia/10.3.0" + } + ], + "authentication": {}, + "metaSortKey": -1736111908438, + "isPrivate": false, + "pathParameters": [], + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, + { + "_id": "fld_a2e9704c49034e36a05cdb3a233f6ebd", + "parentId": "wrk_fde7dcc4f5064b74b0fd749cbf8f684a", + "modified": 1736082089076, + "created": 1736082089076, + "name": "APIDash-APItests", + "description": "These are test endpoints for API Dash", + "authentication": {}, + "metaSortKey": -1736082080559, + "isPrivate": false, + "afterResponseScript": "", + "environment": {}, + "_type": "request_group" + }, + { + "_id": "wrk_fde7dcc4f5064b74b0fd749cbf8f684a", + "modified": 1736082089075, + "created": 1736082089075, + "name": "APIDash-APItests", + "description": "", + "scope": "collection", + "_type": "workspace" + }, + { + "_id": "req_db3c393084f14369bb409afe857e390c", + "parentId": "fld_a2e9704c49034e36a05cdb3a233f6ebd", + "modified": 1736082089077, + "created": 1736082089077, + "url": "https://api.apidash.dev/country/codes", + "name": "test-get", + "description": "", + "method": "GET", + "body": {}, + "preRequestScript": "", + "parameters": [], + "headers": [], + "authentication": {}, + "metaSortKey": -1736082080558, + "isPrivate": false, + "afterResponseScript": "", + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, + { + "_id": "req_ba718bbacd094e95a30ef3f07baa4e42", + "parentId": "fld_a2e9704c49034e36a05cdb3a233f6ebd", + "modified": 1736082089078, + "created": 1736082089078, + "url": "https://api.apidash.dev/case/lower", + "name": "test-post", + "description": "", + "method": "POST", + "body": { + "mimeType": "application/json", + "text": "{\n \"text\": \"Grass is green\"\n}" + }, + "preRequestScript": "", + "parameters": [], + "headers": [ + { + "name": "Content-Type", + "value": "application/json" + } + ], + "authentication": {}, + "metaSortKey": -1736082080557, + "isPrivate": false, + "afterResponseScript": "", + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, + { + "_id": "req_24cff90fc3c74e71a567f61d3f8e8cc1", + "parentId": "fld_a2e9704c49034e36a05cdb3a233f6ebd", + "modified": 1736082089078, + "created": 1736082089078, + "url": "https://reqres.in/api/users/2", + "name": "test-put", + "description": "", + "method": "PUT", + "body": { + "mimeType": "application/json", + "text": "{\n \"name\": \"morpheus\",\n \"job\": \"zion resident\"\n}" + }, + "preRequestScript": "", + "parameters": [], + "headers": [ + { + "name": "Content-Type", + "value": "application/json" + } + ], + "authentication": {}, + "metaSortKey": -1736082080556, + "isPrivate": false, + "afterResponseScript": "", + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, + { + "_id": "env_9d818b2866dffc9831640d91a516ea3986e16bda", + "parentId": "wrk_fde7dcc4f5064b74b0fd749cbf8f684a", + "modified": 1736082095630, + "created": 1736082095630, + "name": "Base Environment", + "metaSortKey": 1736082095630, + "isPrivate": false, + "data": {}, + "environmentType": "kv", + "_type": "environment" + }, + { + "_id": "jar_9d818b2866dffc9831640d91a516ea3986e16bda", + "parentId": "wrk_fde7dcc4f5064b74b0fd749cbf8f684a", + "modified": 1736082095688, + "created": 1736082095688, + "name": "Default Jar", + "cookies": [], + "_type": "cookie_jar" + } + ] +}'''; var collectionApiDashJson = { "_type": "export", @@ -195,17 +226,15 @@ var collectionApiDashJson = { "created": 1736082089076, "name": "APIDash-APItests", "description": "These are test endpoints for API Dash", - "environment": {}, - "environmentPropertyOrder": null, - "metaSortKey": -1736082080559, - "preRequestScript": "", - "afterResponseScript": "", "authentication": {}, + "metaSortKey": -1736082080559, + "isPrivate": false, + "afterResponseScript": "", + "environment": {}, "_type": "request_group" }, { "_id": "wrk_fde7dcc4f5064b74b0fd749cbf8f684a", - "parentId": null, "modified": 1736082089075, "created": 1736082089075, "name": "APIDash-APItests", @@ -223,10 +252,10 @@ var collectionApiDashJson = { "description": "", "method": "GET", "body": {}, + "preRequestScript": "", "parameters": [], "headers": [], "authentication": {}, - "preRequestScript": "", "metaSortKey": -1736082080558, "isPrivate": false, "afterResponseScript": "", @@ -251,12 +280,12 @@ var collectionApiDashJson = { "mimeType": "application/json", "text": "{\n \"text\": \"Grass is green\"\n}" }, + "preRequestScript": "", "parameters": [], "headers": [ {"name": "Content-Type", "value": "application/json"} ], "authentication": {}, - "preRequestScript": "", "metaSortKey": -1736082080557, "isPrivate": false, "afterResponseScript": "", @@ -282,12 +311,12 @@ var collectionApiDashJson = { "text": "{\n \"name\": \"morpheus\",\n \"job\": \"zion resident\"\n}" }, + "preRequestScript": "", "parameters": [], "headers": [ {"name": "Content-Type", "value": "application/json"} ], "authentication": {}, - "preRequestScript": "", "metaSortKey": -1736082080556, "isPrivate": false, "afterResponseScript": "", @@ -305,11 +334,9 @@ var collectionApiDashJson = { "modified": 1736082095630, "created": 1736082095630, "name": "Base Environment", - "data": {}, - "dataPropertyOrder": null, - "color": null, - "isPrivate": false, "metaSortKey": 1736082095630, + "isPrivate": false, + "data": {}, "environmentType": "kv", "_type": "environment" }, diff --git a/packages/insomnia_collection/test/insomnia_test.dart b/packages/insomnia_collection/test/insomnia_test.dart index 808fe906..41bf8e14 100644 --- a/packages/insomnia_collection/test/insomnia_test.dart +++ b/packages/insomnia_collection/test/insomnia_test.dart @@ -5,14 +5,25 @@ import 'package:test/test.dart'; void main() { group('Insomnia tests', () { - test('API Dash Insomnia collection from Json String', () { - expect(insomniaCollectionFromJsonStr(collectionApiDashJsonStr), collectionApiDashModel); + test('Insomnia collection from Json String', () { + expect( + insomniaCollectionFromJsonStr(collectionApiDashJsonStr), + collectionApiDashModel, + ); }); - test('API Dash Insomnia collection from Json', () { - expect(insomniaCollectionFromJson(collectionApiDashJson), - collectionApiDashModel); + test('Insomnia collection from Json', () { + expect( + InsomniaCollection.fromJson(collectionApiDashJson), + collectionApiDashModel, + ); }); + test('Insomnia collection to Json String', () { + expect( + insomniaCollectionToJsonStr(collectionApiDashModel), + collectionApiDashJsonStr, + ); + }); }); } diff --git a/packages/insomnia_collection/test/models/collection_apidash_model.dart b/packages/insomnia_collection/test/models/collection_apidash_model.dart index f9816028..6b931b07 100644 --- a/packages/insomnia_collection/test/models/collection_apidash_model.dart +++ b/packages/insomnia_collection/test/models/collection_apidash_model.dart @@ -1,133 +1,186 @@ import 'package:insomnia_collection/models/models.dart'; var collectionApiDashModel = InsomniaCollection( - type: "export", - exportDate: "2025-01-05T13:05:11.752Z", - exportFormat: 4, - exportSource: "insomnia.desktop.app:v10.3.0", - resources: [ - Resource( - id: "req_15f4d64ca3084a92a0680e29a958c9da", - parentId: "fld_a2e9704c49034e36a05cdb3a233f6ebd", - modified: 1736112258432, - created: 1736111908438, - url: "https://food-service-backend.onrender.com/api/users/", - name: "get-with-params", - description: "", - method: "GET", - body: Body(), - parameters: [Parameter( - id: "pair_bf0ae4f4280e440a8a591b64fd4ec4f4", - name: "user_id", - value: "34", - description: "", - disabled: false, - ) - ], - headers: [ - Header( - name: "User-Agent", - value: "insomnia/10.3.0", - ) - ], - metaSortKey: -1736111908438, - isPrivate: false, - afterResponseScript: null, - settingSendCookies: true, - settingStoreCookies: true, - settingDisableRenderRequestBody: false, - settingEncodeUrl: true, - settingRebuildPath: true, - settingFollowRedirects: "global", - type: "request", - ), - Resource( - id: "req_db3c393084f14369bb409afe857e390c", - parentId: "fld_a2e9704c49034e36a05cdb3a233f6ebd", - modified: 1736082089077, - created: 1736082089077, - url: "https://api.apidash.dev/country/codes", - name: "test-get", - description: "", - method: "GET", - body: Body(), - parameters: [], - headers: [], - preRequestScript: "", - metaSortKey: -1736082080558, - isPrivate: false, - afterResponseScript: "", - settingSendCookies: true, - settingStoreCookies: true, - settingDisableRenderRequestBody: false, - settingEncodeUrl: true, - settingRebuildPath: true, - settingFollowRedirects: "global", - type: "request", - ), - Resource( - id: "req_ba718bbacd094e95a30ef3f07baa4e42", - parentId: "fld_a2e9704c49034e36a05cdb3a233f6ebd", - modified: 1736082089078, - created: 1736082089078, - url: "https://api.apidash.dev/case/lower", - name: "test-post", - description: "", - method: "POST", - body: Body( - mimeType: "application/json", - text: "{\n \"text\": \"Grass is green\"\n}", + type: "export", + exportFormat: 4, + exportDate: "2025-01-05T13:05:11.752Z", + exportSource: "insomnia.desktop.app:v10.3.0", + resources: [ + Resource( + id: "req_15f4d64ca3084a92a0680e29a958c9da", + parentId: "fld_a2e9704c49034e36a05cdb3a233f6ebd", + modified: 1736112258432, + created: 1736111908438, + url: "https://food-service-backend.onrender.com/api/users/", + name: "get-with-params", + description: "", + method: "GET", + body: Body(), + parameters: [ + Parameter( + id: "pair_bf0ae4f4280e440a8a591b64fd4ec4f4", + name: "user_id", + value: "34", + description: "", + disabled: false, + ) + ], + headers: [ + Header( + name: "User-Agent", + value: "insomnia/10.3.0", + ) + ], + authentication: {}, + metaSortKey: -1736111908438, + isPrivate: false, + pathParameters: [], + afterResponseScript: null, + settingSendCookies: true, + settingStoreCookies: true, + settingDisableRenderRequestBody: false, + settingEncodeUrl: true, + settingRebuildPath: true, + settingFollowRedirects: "global", + type: "request", ), - parameters: [], - headers: [ - Header( - name: "Content-Type", - value: "application/json", - ) - ], - preRequestScript: "", - metaSortKey: -1736082080557, - isPrivate: false, - afterResponseScript: "", - settingSendCookies: true, - settingStoreCookies: true, - settingDisableRenderRequestBody: false, - settingEncodeUrl: true, - settingRebuildPath: true, - settingFollowRedirects: "global", - type: "request", - ), - Resource( - id: "req_24cff90fc3c74e71a567f61d3f8e8cc1", - parentId: "fld_a2e9704c49034e36a05cdb3a233f6ebd", - modified: 1736082089078, - created: 1736082089078, - url: "https://reqres.in/api/users/2", - name: "test-put", - description: "", - method: "PUT", - body: Body( - mimeType: "application/json", - text: "{\n \"name\": \"morpheus\",\n \"job\": \"zion resident\"\n}" + Resource( + id: "fld_a2e9704c49034e36a05cdb3a233f6ebd", + parentId: "wrk_fde7dcc4f5064b74b0fd749cbf8f684a", + modified: 1736082089076, + created: 1736082089076, + name: "APIDash-APItests", + description: "These are test endpoints for API Dash", + environment: {}, + environmentPropertyOrder: null, + metaSortKey: -1736082080559, + isPrivate: false, + afterResponseScript: "", + authentication: {}, + type: "request_group", ), - parameters: [], - headers: [ - Header( - name: "Content-Type", - value: "application/json", - ) - ], - preRequestScript: "", - metaSortKey: -1736082080556, - isPrivate: false, - afterResponseScript: "", - settingSendCookies: true, - settingStoreCookies: true, - settingDisableRenderRequestBody: false, - settingEncodeUrl: true, - settingRebuildPath: true, - settingFollowRedirects: "global", - type: "request", - ), - ] -); + Resource( + id: "wrk_fde7dcc4f5064b74b0fd749cbf8f684a", + parentId: null, + modified: 1736082089075, + created: 1736082089075, + name: "APIDash-APItests", + description: "", + scope: "collection", + type: "workspace", + ), + Resource( + id: "req_db3c393084f14369bb409afe857e390c", + parentId: "fld_a2e9704c49034e36a05cdb3a233f6ebd", + modified: 1736082089077, + created: 1736082089077, + url: "https://api.apidash.dev/country/codes", + name: "test-get", + description: "", + method: "GET", + body: Body(), + parameters: [], + headers: [], + preRequestScript: "", + authentication: {}, + metaSortKey: -1736082080558, + isPrivate: false, + afterResponseScript: "", + settingSendCookies: true, + settingStoreCookies: true, + settingDisableRenderRequestBody: false, + settingEncodeUrl: true, + settingRebuildPath: true, + settingFollowRedirects: "global", + type: "request", + ), + Resource( + id: "req_ba718bbacd094e95a30ef3f07baa4e42", + parentId: "fld_a2e9704c49034e36a05cdb3a233f6ebd", + modified: 1736082089078, + created: 1736082089078, + url: "https://api.apidash.dev/case/lower", + name: "test-post", + description: "", + method: "POST", + body: Body( + mimeType: "application/json", + text: "{\n \"text\": \"Grass is green\"\n}", + ), + parameters: [], + headers: [ + Header( + name: "Content-Type", + value: "application/json", + ) + ], + preRequestScript: "", + authentication: {}, + metaSortKey: -1736082080557, + isPrivate: false, + afterResponseScript: "", + settingSendCookies: true, + settingStoreCookies: true, + settingDisableRenderRequestBody: false, + settingEncodeUrl: true, + settingRebuildPath: true, + settingFollowRedirects: "global", + type: "request", + ), + Resource( + id: "req_24cff90fc3c74e71a567f61d3f8e8cc1", + parentId: "fld_a2e9704c49034e36a05cdb3a233f6ebd", + modified: 1736082089078, + created: 1736082089078, + url: "https://reqres.in/api/users/2", + name: "test-put", + description: "", + method: "PUT", + body: Body( + mimeType: "application/json", + text: + "{\n \"name\": \"morpheus\",\n \"job\": \"zion resident\"\n}"), + parameters: [], + headers: [ + Header( + name: "Content-Type", + value: "application/json", + ) + ], + preRequestScript: "", + authentication: {}, + metaSortKey: -1736082080556, + isPrivate: false, + afterResponseScript: "", + settingSendCookies: true, + settingStoreCookies: true, + settingDisableRenderRequestBody: false, + settingEncodeUrl: true, + settingRebuildPath: true, + settingFollowRedirects: "global", + type: "request", + ), + Resource( + id: "env_9d818b2866dffc9831640d91a516ea3986e16bda", + parentId: "wrk_fde7dcc4f5064b74b0fd749cbf8f684a", + modified: 1736082095630, + created: 1736082095630, + name: "Base Environment", + data: {}, + dataPropertyOrder: null, + color: null, + isPrivate: false, + metaSortKey: 1736082095630, + environmentType: "kv", + type: "environment", + ), + Resource( + id: "jar_9d818b2866dffc9831640d91a516ea3986e16bda", + parentId: "wrk_fde7dcc4f5064b74b0fd749cbf8f684a", + modified: 1736082095688, + created: 1736082095688, + name: "Default Jar", + cookies: [], + type: "cookie_jar", + ), + ]); From 4e4d367eacf407fa1eca790aa444d1208688971f Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Mon, 24 Feb 2025 11:13:26 +0530 Subject: [PATCH 21/42] Update insomnia_example.dart --- packages/insomnia_collection/example/insomnia_example.dart | 6 ------ 1 file changed, 6 deletions(-) diff --git a/packages/insomnia_collection/example/insomnia_example.dart b/packages/insomnia_collection/example/insomnia_example.dart index f9301346..36830b5c 100644 --- a/packages/insomnia_collection/example/insomnia_example.dart +++ b/packages/insomnia_collection/example/insomnia_example.dart @@ -1,4 +1,3 @@ - import 'package:insomnia_collection/insomnia_collection.dart'; void main() { @@ -150,14 +149,10 @@ void main() { } '''; - - var collection; try { collection = insomniaCollectionFromJsonStr(collectionJsonStr); - - print(collection.exportSource); // insomnia.desktop.app:v10.3.0 print(collection.resources?[3].name); @@ -170,7 +165,6 @@ void main() { print(e.toString() + 'error from collection'); } - // Example 2: Insomnia collection from JSON var collectionJson = { "_type": "export", From efd7eaae32be53d03697b71cc06b76a0035e6b7a Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Mon, 24 Feb 2025 11:13:48 +0530 Subject: [PATCH 22/42] Remove direct dependency of insomnia_collection --- pubspec.lock | 2 +- pubspec.yaml | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/pubspec.lock b/pubspec.lock index 0826b5d5..fdf2db3c 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -773,7 +773,7 @@ packages: source: hosted version: "4.3.0" insomnia_collection: - dependency: "direct main" + dependency: transitive description: path: "packages/insomnia_collection" relative: true diff --git a/pubspec.yaml b/pubspec.yaml index 89733f2c..e2d00bad 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -12,8 +12,6 @@ dependencies: sdk: flutter apidash_core: path: packages/apidash_core - insomnia_collection: - path: packages/insomnia_collection apidash_design_system: path: packages/apidash_design_system code_builder: ^4.10.0 From c40704b0b1b9d5c3042ab66f683845d3dba4c301 Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Mon, 24 Feb 2025 11:39:41 +0530 Subject: [PATCH 23/42] Update content_type_utils.dart --- .../lib/utils/content_type_utils.dart | 33 ++++++++++++++----- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/packages/apidash_core/lib/utils/content_type_utils.dart b/packages/apidash_core/lib/utils/content_type_utils.dart index 13fb7226..ace8d715 100644 --- a/packages/apidash_core/lib/utils/content_type_utils.dart +++ b/packages/apidash_core/lib/utils/content_type_utils.dart @@ -7,15 +7,7 @@ ContentType? getContentTypeFromHeadersMap( ) { if (kvMap != null && kvMap.hasKeyContentType()) { var val = getMediaTypeFromHeaders(kvMap); - if (val != null) { - if (val.subtype.contains(kSubTypeJson)) { - return ContentType.json; - } else if (val.type == kTypeMultipart && - val.subtype == kSubTypeFormData) { - return ContentType.formdata; - } - return ContentType.text; - } + return getContentTypeFromMediaType(val); } return null; } @@ -37,3 +29,26 @@ MediaType? getMediaTypeFromContentType(String? contentType) { } return null; } + +ContentType? getContentTypeFromMediaType(MediaType? mediaType) { + if (mediaType != null) { + if (mediaType.subtype.contains(kSubTypeJson)) { + return ContentType.json; + } else if (mediaType.type == kTypeMultipart && + mediaType.subtype == kSubTypeFormData) { + return ContentType.formdata; + } + return ContentType.text; + } + return null; +} + +ContentType? getContentTypeFromContentTypeStr( + String? contentType, +) { + if (contentType != null) { + var val = getMediaTypeFromContentType(contentType); + return getContentTypeFromMediaType(val); + } + return null; +} From 18c32dc4c776121d8cc13c9ea2338ec276484cb6 Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Mon, 24 Feb 2025 11:39:50 +0530 Subject: [PATCH 24/42] Update insomnia_io.dart --- .../lib/import_export/insomnia_io.dart | 88 +++++++------------ 1 file changed, 31 insertions(+), 57 deletions(-) diff --git a/packages/apidash_core/lib/import_export/insomnia_io.dart b/packages/apidash_core/lib/import_export/insomnia_io.dart index 3d8e9329..11db5339 100644 --- a/packages/apidash_core/lib/import_export/insomnia_io.dart +++ b/packages/apidash_core/lib/import_export/insomnia_io.dart @@ -1,42 +1,26 @@ -import 'package:insomnia_collection/models/insomnia_environment.dart'; +import 'package:insomnia_collection/insomnia_collection.dart'; import 'package:seed/seed.dart'; import '../consts.dart'; import '../models/models.dart'; import '../utils/utils.dart'; -import 'package:insomnia_collection/insomnia_collection.dart' as ins; class InsomniaIO { List<(String?, HttpRequestModel)>? getHttpRequestModelList(String content) { content = content.trim(); try { - final ic = ins.insomniaCollectionFromJsonStr(content); - final requests = ins.getRequestsFromInsomniaCollection(ic); - - /// TODO; Get env from the insomnia collection - // final environmentVariables = ins.getEnvironmentVariablesFromInsomniaEnvironment(env); + final ic = insomniaCollectionFromJsonStr(content); + final requests = getRequestsFromInsomniaCollection(ic); return requests - .map((req) => (req.$1, insomniaRequestToHttpRequestModel(req.$2))) + .map((req) => (req.$1, insomniaResourceToHttpRequestModel(req.$2))) .toList(); } catch (e) { return null; } } - InsomniaEnvironment? getInsomiaEnvironment(String content) { - content = content.trim(); - try { - final env = ins.insomniaEnvironmentFromJsonStr(content); - - return env; - } catch (e) { - return null; - } - } - - HttpRequestModel insomniaRequestToHttpRequestModel(ins.Resource request) { + HttpRequestModel insomniaResourceToHttpRequestModel(Resource request) { HTTPVerb method; - try { method = HTTPVerb.values.byName((request.method ?? "").toLowerCase()); } catch (e) { @@ -49,7 +33,7 @@ class InsomniaIO { List params = []; List isParamEnabledList = []; - for (var header in request.headers ?? []) { + for (var header in request.headers ??
[]) { var name = header.name ?? ""; var value = header.value ?? ""; var activeHeader = header.disabled ?? false; @@ -57,7 +41,7 @@ class InsomniaIO { isHeaderEnabledList.add(!activeHeader); } - for (var query in request.parameters ?? []) { + for (var query in request.parameters ?? []) { var name = query.name ?? ""; var value = query.value; var activeQuery = query.disabled ?? false; @@ -65,44 +49,34 @@ class InsomniaIO { isParamEnabledList.add(!activeQuery); } - ContentType bodyContentType = kDefaultContentType; + ContentType bodyContentType = + getContentTypeFromContentTypeStr(request.body?.mimeType) ?? + kDefaultContentType; + String? body; List? formData; - if (request.body != null) { - if (request.body?.mimeType != null) { - try { - if (request.body?.mimeType == 'text/plain') { - bodyContentType = ContentType.text; - } else if (request.body?.mimeType == 'application/json') { - bodyContentType = ContentType.json; - } else if (request.body?.mimeType == 'multipart/form-data') { - bodyContentType = ContentType.formdata; - formData = []; - for (var fd in request.body?.params ?? []) { - var name = fd.name ?? ""; - FormDataType formDataType; - try { - formDataType = FormDataType.values.byName(fd.type ?? ""); - } catch (e) { - formDataType = FormDataType.text; - } - var value = switch (formDataType) { - FormDataType.text => fd.value ?? "", - FormDataType.file => fd.src ?? "" - }; - formData.add(FormDataModel( - name: name, - value: value, - type: formDataType, - )); - } - } else { - bodyContentType = - ContentType.values.byName(request.body?.mimeType ?? ""); + if (request.body != null && request.body?.mimeType != null) { + if (bodyContentType == ContentType.formdata) { + formData = []; + for (var fd in request.body?.params ?? []) { + var name = fd.name ?? ""; + FormDataType formDataType; + try { + formDataType = FormDataType.values.byName(fd.type ?? ""); + } catch (e) { + formDataType = FormDataType.text; } - } catch (e) { - bodyContentType = kDefaultContentType; + var value = switch (formDataType) { + FormDataType.text => fd.value ?? "", + FormDataType.file => fd.src ?? "" + }; + formData.add(FormDataModel( + name: name, + value: value, + type: formDataType, + )); } + } else { body = request.body?.text; } } From 02ba4d605206c292ac81bc1a32772a83597f6afb Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Mon, 24 Feb 2025 11:43:49 +0530 Subject: [PATCH 25/42] Update import_dialog.dart --- lib/importer/import_dialog.dart | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/lib/importer/import_dialog.dart b/lib/importer/import_dialog.dart index 52dec2c7..42abb366 100644 --- a/lib/importer/import_dialog.dart +++ b/lib/importer/import_dialog.dart @@ -27,26 +27,6 @@ void importToCollectionPane( sm.hideCurrentSnackBar(); file.readAsString().then( (content) { - kEnvImporter - .getInsomniaEnvironment(importFormatType, content) - .then((environment) { - debugPrint('Environment: $environment'); - debugPrint('Environment values: ${environment?.resources}'); - - if (environment != null) { - if (environment.resources == null || - environment.resources!.isEmpty) { - sm.showSnackBar(getSnackBar("No environment variables imported", - small: false)); - } else { - var env = createNewEnvironment(ref, environment); - - sm.showSnackBar(getSnackBar( - "Successfully imported ${env.length} environment variables", - small: false)); - } - } - }); kImporter .getHttpRequestModelList(importFormatType, content) .then((importedRequestModels) { From b2082d45ae74c3f060858b216af00de71b7936af Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Mon, 24 Feb 2025 11:43:52 +0530 Subject: [PATCH 26/42] Update importer.dart --- lib/importer/importer.dart | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/lib/importer/importer.dart b/lib/importer/importer.dart index 3d649947..4d93d9be 100644 --- a/lib/importer/importer.dart +++ b/lib/importer/importer.dart @@ -1,6 +1,5 @@ import 'package:apidash/consts.dart'; import 'package:apidash_core/apidash_core.dart'; -import 'package:insomnia_collection/models/insomnia_environment.dart'; class Importer { Future?> getHttpRequestModelList( @@ -18,15 +17,4 @@ class Importer { } } -class EnvImporter { - Future getInsomniaEnvironment( - ImportFormat fileType, String content) async { - return switch (fileType) { - ImportFormat.insomnia => InsomniaIO().getInsomiaEnvironment(content), - _ => null - }; - } -} - final kImporter = Importer(); -final kEnvImporter = EnvImporter(); From 01391babb98eb52f70cfed3baf155efc5de5e7c0 Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Mon, 24 Feb 2025 11:49:49 +0530 Subject: [PATCH 27/42] Update environments_pane.dart --- lib/screens/envvar/environments_pane.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/screens/envvar/environments_pane.dart b/lib/screens/envvar/environments_pane.dart index 74ddf363..18bd2053 100644 --- a/lib/screens/envvar/environments_pane.dart +++ b/lib/screens/envvar/environments_pane.dart @@ -26,7 +26,6 @@ class EnvironmentsPane extends ConsumerWidget { ref .read(environmentsStateNotifierProvider.notifier) .addEnvironment(); - // createNewEnvironment(ref); }, ), kVSpacer10, From c53472a00b5ffa98a1e26caeaed250f1bc2b1409 Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Mon, 24 Feb 2025 11:49:57 +0530 Subject: [PATCH 28/42] Update import_dialog.dart --- lib/importer/import_dialog.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/importer/import_dialog.dart b/lib/importer/import_dialog.dart index 42abb366..a8d54366 100644 --- a/lib/importer/import_dialog.dart +++ b/lib/importer/import_dialog.dart @@ -1,4 +1,3 @@ -import 'package:apidash/utils/envvar_utils.dart'; import 'package:apidash_design_system/apidash_design_system.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; From b69a7d5e0650d6fc2f57a57b28814172a72c51ea Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Mon, 24 Feb 2025 12:12:22 +0530 Subject: [PATCH 29/42] Move EnvironmentVariableType --- lib/consts.dart | 2 -- packages/apidash_core/lib/consts.dart | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/consts.dart b/lib/consts.dart index 50401b29..b1e9c956 100644 --- a/lib/consts.dart +++ b/lib/consts.dart @@ -96,8 +96,6 @@ enum SidebarMenuOption { final String label; } -enum EnvironmentVariableType { variable, secret } - final kEnvVarRegEx = RegExp(r'{{([^{}]*)}}'); enum CodegenLanguage { diff --git a/packages/apidash_core/lib/consts.dart b/packages/apidash_core/lib/consts.dart index c3ac388c..1d7044c7 100644 --- a/packages/apidash_core/lib/consts.dart +++ b/packages/apidash_core/lib/consts.dart @@ -9,6 +9,8 @@ enum APIType { final String abbr; } +enum EnvironmentVariableType { variable, secret } + enum HTTPVerb { get("GET"), head("HEAD"), From 38c6d8ecf6347cb112d92f9833341fa9c26b367e Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Mon, 24 Feb 2025 12:12:52 +0530 Subject: [PATCH 30/42] Move EnvironmentModel --- .../apidash_core/lib}/models/environment_model.dart | 4 ++-- .../apidash_core/lib}/models/environment_model.freezed.dart | 0 .../apidash_core/lib}/models/environment_model.g.dart | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename {lib => packages/apidash_core/lib}/models/environment_model.dart (96%) rename {lib => packages/apidash_core/lib}/models/environment_model.freezed.dart (100%) rename {lib => packages/apidash_core/lib}/models/environment_model.g.dart (100%) diff --git a/lib/models/environment_model.dart b/packages/apidash_core/lib/models/environment_model.dart similarity index 96% rename from lib/models/environment_model.dart rename to packages/apidash_core/lib/models/environment_model.dart index 7f37fb6f..9242d4d5 100644 --- a/lib/models/environment_model.dart +++ b/packages/apidash_core/lib/models/environment_model.dart @@ -1,5 +1,5 @@ -import 'package:apidash/consts.dart'; -import 'package:apidash_core/apidash_core.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; +import '../consts.dart'; part 'environment_model.freezed.dart'; diff --git a/lib/models/environment_model.freezed.dart b/packages/apidash_core/lib/models/environment_model.freezed.dart similarity index 100% rename from lib/models/environment_model.freezed.dart rename to packages/apidash_core/lib/models/environment_model.freezed.dart diff --git a/lib/models/environment_model.g.dart b/packages/apidash_core/lib/models/environment_model.g.dart similarity index 100% rename from lib/models/environment_model.g.dart rename to packages/apidash_core/lib/models/environment_model.g.dart From 634d909b02331d16a8c9291c17ee86c4043b9656 Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Mon, 24 Feb 2025 12:13:09 +0530 Subject: [PATCH 31/42] Update models.dart --- lib/models/models.dart | 1 - packages/apidash_core/lib/models/models.dart | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/models/models.dart b/lib/models/models.dart index d8ea6ac0..5d17479a 100644 --- a/lib/models/models.dart +++ b/lib/models/models.dart @@ -1,4 +1,3 @@ -export 'environment_model.dart'; export 'history_meta_model.dart'; export 'history_request_model.dart'; export 'request_model.dart'; diff --git a/packages/apidash_core/lib/models/models.dart b/packages/apidash_core/lib/models/models.dart index a33c6fdd..c50ec988 100644 --- a/packages/apidash_core/lib/models/models.dart +++ b/packages/apidash_core/lib/models/models.dart @@ -1,2 +1,3 @@ +export 'environment_model.dart'; export 'http_request_model.dart'; export 'http_response_model.dart'; From 11055f7ea872ef87aec0b05bdaf3d245689750c2 Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Mon, 24 Feb 2025 12:13:13 +0530 Subject: [PATCH 32/42] Update environment_providers.dart --- lib/providers/environment_providers.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/providers/environment_providers.dart b/lib/providers/environment_providers.dart index 0f29cb2d..13c504b2 100644 --- a/lib/providers/environment_providers.dart +++ b/lib/providers/environment_providers.dart @@ -1,7 +1,7 @@ import 'package:apidash/consts.dart'; -import 'package:apidash/models/environment_model.dart'; import 'package:apidash/providers/providers.dart'; import 'package:apidash/utils/file_utils.dart'; +import 'package:apidash_core/apidash_core.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import '../services/services.dart' show hiveHandler, HiveHandler; From becf72ced569414406d449faa8eecfe73ad575d3 Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Mon, 24 Feb 2025 12:13:46 +0530 Subject: [PATCH 33/42] Update imports --- lib/screens/common_widgets/env_trigger_options.dart | 2 +- lib/screens/common_widgets/envvar_indicator.dart | 2 +- lib/screens/common_widgets/envvar_popover.dart | 2 +- lib/screens/envvar/editor_pane/secrets_pane.dart | 2 +- lib/screens/envvar/editor_pane/variables_pane.dart | 2 +- lib/screens/envvar/environments_pane.dart | 2 +- lib/widgets/popup_menu_env.dart | 1 - 7 files changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/screens/common_widgets/env_trigger_options.dart b/lib/screens/common_widgets/env_trigger_options.dart index 702209b8..045db973 100644 --- a/lib/screens/common_widgets/env_trigger_options.dart +++ b/lib/screens/common_widgets/env_trigger_options.dart @@ -1,8 +1,8 @@ import 'package:apidash/consts.dart'; +import 'package:apidash_core/apidash_core.dart'; import 'package:apidash_design_system/apidash_design_system.dart'; import 'package:flutter/material.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; -import 'package:apidash/models/models.dart'; import 'package:apidash/providers/providers.dart'; import 'package:apidash/utils/utils.dart'; diff --git a/lib/screens/common_widgets/envvar_indicator.dart b/lib/screens/common_widgets/envvar_indicator.dart index bc56fc19..c57b2e87 100644 --- a/lib/screens/common_widgets/envvar_indicator.dart +++ b/lib/screens/common_widgets/envvar_indicator.dart @@ -1,6 +1,6 @@ +import 'package:apidash_core/apidash_core.dart'; import 'package:apidash_design_system/apidash_design_system.dart'; import 'package:flutter/material.dart'; -import 'package:apidash/models/models.dart'; import 'package:apidash/consts.dart'; class EnvVarIndicator extends StatelessWidget { diff --git a/lib/screens/common_widgets/envvar_popover.dart b/lib/screens/common_widgets/envvar_popover.dart index 3d7b93da..7a5e67c0 100644 --- a/lib/screens/common_widgets/envvar_popover.dart +++ b/lib/screens/common_widgets/envvar_popover.dart @@ -1,6 +1,6 @@ +import 'package:apidash_core/apidash_core.dart'; import 'package:apidash_design_system/apidash_design_system.dart'; import 'package:flutter/material.dart'; -import 'package:apidash/models/models.dart'; import 'common_widgets.dart'; class EnvVarPopover extends StatelessWidget { diff --git a/lib/screens/envvar/editor_pane/secrets_pane.dart b/lib/screens/envvar/editor_pane/secrets_pane.dart index 0e67f0f7..014d0426 100644 --- a/lib/screens/envvar/editor_pane/secrets_pane.dart +++ b/lib/screens/envvar/editor_pane/secrets_pane.dart @@ -1,10 +1,10 @@ import 'dart:math'; +import 'package:apidash_core/apidash_core.dart'; import 'package:apidash_design_system/apidash_design_system.dart'; import 'package:flutter/material.dart'; import 'package:data_table_2/data_table_2.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:apidash/consts.dart'; -import 'package:apidash/models/models.dart'; import 'package:apidash/providers/providers.dart'; import 'package:apidash/utils/utils.dart'; import 'package:apidash/widgets/widgets.dart'; diff --git a/lib/screens/envvar/editor_pane/variables_pane.dart b/lib/screens/envvar/editor_pane/variables_pane.dart index 31039770..af3a1e39 100644 --- a/lib/screens/envvar/editor_pane/variables_pane.dart +++ b/lib/screens/envvar/editor_pane/variables_pane.dart @@ -1,10 +1,10 @@ import 'dart:math'; +import 'package:apidash_core/apidash_core.dart'; import 'package:apidash_design_system/apidash_design_system.dart'; import 'package:flutter/material.dart'; import 'package:data_table_2/data_table_2.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:apidash/consts.dart'; -import 'package:apidash/models/models.dart'; import 'package:apidash/providers/providers.dart'; import 'package:apidash/utils/utils.dart'; import 'package:apidash/widgets/widgets.dart'; diff --git a/lib/screens/envvar/environments_pane.dart b/lib/screens/envvar/environments_pane.dart index 18bd2053..2c74742e 100644 --- a/lib/screens/envvar/environments_pane.dart +++ b/lib/screens/envvar/environments_pane.dart @@ -1,8 +1,8 @@ +import 'package:apidash_core/apidash_core.dart'; import 'package:apidash_design_system/apidash_design_system.dart'; import 'package:flutter/material.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:flutter_hooks/flutter_hooks.dart'; -import 'package:apidash/models/environment_model.dart'; import 'package:apidash/providers/providers.dart'; import 'package:apidash/widgets/widgets.dart'; import 'package:apidash/consts.dart'; diff --git a/lib/widgets/popup_menu_env.dart b/lib/widgets/popup_menu_env.dart index 1ee1022d..601c7fad 100644 --- a/lib/widgets/popup_menu_env.dart +++ b/lib/widgets/popup_menu_env.dart @@ -1,7 +1,6 @@ import 'package:apidash_core/apidash_core.dart'; import 'package:apidash_design_system/apidash_design_system.dart'; import 'package:flutter/material.dart'; -import 'package:apidash/models/models.dart'; import 'package:apidash/utils/utils.dart'; import '../consts.dart'; From 8ab16c1739cc678ebf9d1733e227f78a74fa2037 Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Mon, 24 Feb 2025 12:13:58 +0530 Subject: [PATCH 34/42] Update tests --- test/models/environment_models.dart | 6 +----- test/models/environment_models_test.dart | 3 +-- test/screens/common_widgets/env_trigger_options_test.dart | 2 +- test/screens/common_widgets/envvar_indicator_test.dart | 2 +- test/screens/common_widgets/envvar_popover_test.dart | 2 +- test/utils/envvar_utils_test.dart | 1 - test/widgets/popup_menu_env_test.dart | 2 +- 7 files changed, 6 insertions(+), 12 deletions(-) diff --git a/test/models/environment_models.dart b/test/models/environment_models.dart index 66d61eb3..e23f659b 100644 --- a/test/models/environment_models.dart +++ b/test/models/environment_models.dart @@ -1,9 +1,5 @@ import 'package:apidash/consts.dart'; -import 'package:apidash/models/models.dart' - show - EnvironmentModel, - EnvironmentVariableModel, - EnvironmentVariableSuggestion; +import 'package:apidash_core/apidash_core.dart'; /// Global environment model const globalEnvironment = EnvironmentModel( diff --git a/test/models/environment_models_test.dart b/test/models/environment_models_test.dart index 8664b164..f4ab1e31 100644 --- a/test/models/environment_models_test.dart +++ b/test/models/environment_models_test.dart @@ -1,6 +1,5 @@ +import 'package:apidash_core/apidash_core.dart'; import 'package:test/test.dart'; -import 'package:apidash/models/models.dart'; -import 'package:apidash/consts.dart'; import 'environment_models.dart'; diff --git a/test/screens/common_widgets/env_trigger_options_test.dart b/test/screens/common_widgets/env_trigger_options_test.dart index 0bbe5bf4..8856e6b8 100644 --- a/test/screens/common_widgets/env_trigger_options_test.dart +++ b/test/screens/common_widgets/env_trigger_options_test.dart @@ -1,7 +1,7 @@ +import 'package:apidash_core/apidash_core.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; -import 'package:apidash/models/models.dart'; import 'package:apidash/providers/providers.dart'; import 'package:apidash/consts.dart'; import 'package:apidash/screens/common_widgets/env_trigger_options.dart'; diff --git a/test/screens/common_widgets/envvar_indicator_test.dart b/test/screens/common_widgets/envvar_indicator_test.dart index 9dc9bdc6..effddb8b 100644 --- a/test/screens/common_widgets/envvar_indicator_test.dart +++ b/test/screens/common_widgets/envvar_indicator_test.dart @@ -1,7 +1,7 @@ +import 'package:apidash_core/apidash_core.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:apidash/consts.dart'; -import 'package:apidash/models/models.dart'; import 'package:apidash/screens/common_widgets/envvar_indicator.dart'; void main() { diff --git a/test/screens/common_widgets/envvar_popover_test.dart b/test/screens/common_widgets/envvar_popover_test.dart index d1eb268f..5a47257d 100644 --- a/test/screens/common_widgets/envvar_popover_test.dart +++ b/test/screens/common_widgets/envvar_popover_test.dart @@ -1,6 +1,6 @@ +import 'package:apidash_core/apidash_core.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:apidash/models/models.dart'; import 'package:apidash/screens/common_widgets/envvar_indicator.dart'; import 'package:apidash/screens/common_widgets/envvar_popover.dart'; diff --git a/test/utils/envvar_utils_test.dart b/test/utils/envvar_utils_test.dart index a6c9ee03..a57e57c3 100644 --- a/test/utils/envvar_utils_test.dart +++ b/test/utils/envvar_utils_test.dart @@ -1,4 +1,3 @@ -import 'package:apidash/models/models.dart'; import 'package:apidash/utils/envvar_utils.dart'; import 'package:apidash/consts.dart'; import 'package:apidash_core/apidash_core.dart'; diff --git a/test/widgets/popup_menu_env_test.dart b/test/widgets/popup_menu_env_test.dart index 4c11df39..66672d3c 100644 --- a/test/widgets/popup_menu_env_test.dart +++ b/test/widgets/popup_menu_env_test.dart @@ -1,7 +1,7 @@ import 'package:apidash/consts.dart'; +import 'package:apidash_core/apidash_core.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:apidash/models/models.dart'; import 'package:apidash/widgets/popup_menu_env.dart'; void main() { From 5e4bf071a183f6ceff5a59d2637a353c7d35f46b Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Mon, 24 Feb 2025 12:14:05 +0530 Subject: [PATCH 35/42] Update insomnia_io.dart --- .../lib/import_export/insomnia_io.dart | 37 ++++++++++++++----- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/packages/apidash_core/lib/import_export/insomnia_io.dart b/packages/apidash_core/lib/import_export/insomnia_io.dart index 11db5339..a154b62e 100644 --- a/packages/apidash_core/lib/import_export/insomnia_io.dart +++ b/packages/apidash_core/lib/import_export/insomnia_io.dart @@ -19,21 +19,21 @@ class InsomniaIO { } } - HttpRequestModel insomniaResourceToHttpRequestModel(Resource request) { + HttpRequestModel insomniaResourceToHttpRequestModel(Resource resource) { HTTPVerb method; try { - method = HTTPVerb.values.byName((request.method ?? "").toLowerCase()); + method = HTTPVerb.values.byName((resource.method ?? "").toLowerCase()); } catch (e) { method = kDefaultHttpMethod; } - String url = stripUrlParams(request.url ?? ""); + String url = stripUrlParams(resource.url ?? ""); List headers = []; List isHeaderEnabledList = []; List params = []; List isParamEnabledList = []; - for (var header in request.headers ??
[]) { + for (var header in resource.headers ??
[]) { var name = header.name ?? ""; var value = header.value ?? ""; var activeHeader = header.disabled ?? false; @@ -41,7 +41,7 @@ class InsomniaIO { isHeaderEnabledList.add(!activeHeader); } - for (var query in request.parameters ?? []) { + for (var query in resource.parameters ?? []) { var name = query.name ?? ""; var value = query.value; var activeQuery = query.disabled ?? false; @@ -50,15 +50,15 @@ class InsomniaIO { } ContentType bodyContentType = - getContentTypeFromContentTypeStr(request.body?.mimeType) ?? + getContentTypeFromContentTypeStr(resource.body?.mimeType) ?? kDefaultContentType; String? body; List? formData; - if (request.body != null && request.body?.mimeType != null) { + if (resource.body != null && resource.body?.mimeType != null) { if (bodyContentType == ContentType.formdata) { formData = []; - for (var fd in request.body?.params ?? []) { + for (var fd in resource.body?.params ?? []) { var name = fd.name ?? ""; FormDataType formDataType; try { @@ -77,7 +77,7 @@ class InsomniaIO { )); } } else { - body = request.body?.text; + body = resource.body?.text; } } @@ -93,4 +93,23 @@ class InsomniaIO { formData: formData, ); } + + EnvironmentModel insomniaResourceToEnvironmentModel(Resource resource) { + List variables = []; + for (var envvar in resource.kvPairData!) { + variables.add(EnvironmentVariableModel( + key: envvar.name ?? "", + value: envvar.value ?? "", + enabled: envvar.enabled ?? true, + type: envvar.type == "secret" + ? EnvironmentVariableType.secret + : EnvironmentVariableType.variable, + )); + } + return EnvironmentModel( + id: resource.id!, + name: resource.name ?? "", + values: variables, + ); + } } From 8245f768f816cf5b05e74adf4f89a3c803ec21d9 Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Mon, 24 Feb 2025 12:14:37 +0530 Subject: [PATCH 36/42] Update .gitignore --- packages/insomnia_collection/.gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/insomnia_collection/.gitignore b/packages/insomnia_collection/.gitignore index ac5aa989..fca0f548 100644 --- a/packages/insomnia_collection/.gitignore +++ b/packages/insomnia_collection/.gitignore @@ -27,3 +27,4 @@ migrate_working_dir/ **/doc/api/ .dart_tool/ build/ +coverage/ From f77d8cfc7fa232457dd52e2bf82997546613748e Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Mon, 24 Feb 2025 12:14:46 +0530 Subject: [PATCH 37/42] Update envvar_utils.dart --- lib/utils/envvar_utils.dart | 44 ------------------------------------- 1 file changed, 44 deletions(-) diff --git a/lib/utils/envvar_utils.dart b/lib/utils/envvar_utils.dart index 3a884cfe..15186512 100644 --- a/lib/utils/envvar_utils.dart +++ b/lib/utils/envvar_utils.dart @@ -1,49 +1,5 @@ -import 'package:apidash/providers/environment_providers.dart'; import 'package:apidash_core/apidash_core.dart'; import 'package:apidash/consts.dart'; -import 'package:apidash/models/models.dart'; -import 'package:flutter/material.dart'; -import 'package:hooks_riverpod/hooks_riverpod.dart'; -import 'package:insomnia_collection/models/insomnia_environment.dart'; - -List createNewEnvironment(WidgetRef ref, InsomniaEnvironment environment) { - // Step 1: Add a new environment - ref.read(environmentsStateNotifierProvider.notifier).addEnvironment(); - - // Step 2: Get the ID of the newly created environment - final newEnvironmentId = - ref.read(selectedEnvironmentIdStateProvider.notifier).state; - - debugPrint('New id is $newEnvironmentId'); - - // Step 3: Update the new environment with a name and variables - if (newEnvironmentId != null) { - if (environment.resources == null || environment.resources!.isEmpty) { - debugPrint('No env variables found'); - return []; - } - List variables = []; - for (var env in environment.resources!) { - variables.add(EnvironmentVariableModel( - key: env.key, - value: env.value, - enabled: env.enabled ?? true, - type: env.type == "secret" - ? EnvironmentVariableType.secret - : EnvironmentVariableType.variable, - )); - } - ref.read(environmentsStateNotifierProvider.notifier).updateEnvironment( - newEnvironmentId, - name: environment.name ?? "Untitled", - values: variables, - ); - return variables; - } else { - debugPrint('No env id found'); - return []; - } -} String getEnvironmentTitle(String? name) { if (name == null || name.trim() == "") { From 0ee7bf6b5c28ffa4d6c63d9987af13e01811f6fe Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Mon, 24 Feb 2025 12:33:27 +0530 Subject: [PATCH 38/42] Update insomnia_io.dart --- packages/apidash_core/lib/import_export/insomnia_io.dart | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/apidash_core/lib/import_export/insomnia_io.dart b/packages/apidash_core/lib/import_export/insomnia_io.dart index a154b62e..d9608500 100644 --- a/packages/apidash_core/lib/import_export/insomnia_io.dart +++ b/packages/apidash_core/lib/import_export/insomnia_io.dart @@ -1,3 +1,4 @@ +import 'package:flutter/material.dart'; import 'package:insomnia_collection/insomnia_collection.dart'; import 'package:seed/seed.dart'; import '../consts.dart'; @@ -15,6 +16,7 @@ class InsomniaIO { .map((req) => (req.$1, insomniaResourceToHttpRequestModel(req.$2))) .toList(); } catch (e) { + debugPrint("$e"); return null; } } From 91c761f5a91133cb258613845f102b9e3a1280e1 Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Mon, 24 Feb 2025 12:34:15 +0530 Subject: [PATCH 39/42] Fix: getItemByTypeFromInsomniaCollection() --- packages/insomnia_collection/lib/utils/insomnia_utils.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/insomnia_collection/lib/utils/insomnia_utils.dart b/packages/insomnia_collection/lib/utils/insomnia_utils.dart index 50a1d41a..9d4aa7eb 100644 --- a/packages/insomnia_collection/lib/utils/insomnia_utils.dart +++ b/packages/insomnia_collection/lib/utils/insomnia_utils.dart @@ -12,12 +12,12 @@ List<(String?, Resource)> getItemByTypeFromInsomniaCollection( InsomniaCollection? ic, String type, ) { - if (ic?.resources == null || ic!.resources!.length > 0) { + if (ic?.resources == null || ic!.resources!.length == 0) { return []; } List<(String?, Resource)> requests = []; for (var item in ic.resources!) { - if (item.type != null || item.type == type) { + if (item.type != null && item.type == type) { requests.add((item.name, item)); } } From 69f63147a05a813bd3fa8ff47e671b643ff8b045 Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Mon, 24 Feb 2025 12:40:26 +0530 Subject: [PATCH 40/42] Update README.md --- packages/insomnia_collection/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/insomnia_collection/README.md b/packages/insomnia_collection/README.md index 255d890a..3063e46f 100644 --- a/packages/insomnia_collection/README.md +++ b/packages/insomnia_collection/README.md @@ -389,8 +389,8 @@ void main() { ## Maintainer - Ashita Prasad ([GitHub](https://github.com/ashitaprasad), [LinkedIn](https://www.linkedin.com/in/ashitaprasad/), [X](https://x.com/ashitaprasad)) -- Papa Kofi (contributor) ([GitHub](https://github.com/StormGear), [LinkedIn](https://www.linkedin.com/in/papakofiboahen)) +- Papa Kofi (contributor) ([GitHub](https://github.com/StormGear)) ## License -This project is licensed under the [Apache License 2.0](https://github.com/foss42/apidash/blob/main/packages/postman/LICENSE). +This project is licensed under the [Apache License 2.0](https://github.com/foss42/apidash/blob/main/packages/insomnia_collection/LICENSE). From 7de23e36dc9c4a20c0697f2d854bea1b57f28f34 Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Mon, 24 Feb 2025 12:45:59 +0530 Subject: [PATCH 41/42] cleanup pubspec --- packages/insomnia_collection/pubspec.yaml | 9 ++------- pubspec.lock | 8 -------- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/packages/insomnia_collection/pubspec.yaml b/packages/insomnia_collection/pubspec.yaml index 5504badd..4b174704 100644 --- a/packages/insomnia_collection/pubspec.yaml +++ b/packages/insomnia_collection/pubspec.yaml @@ -14,16 +14,11 @@ environment: sdk: ">=3.0.0 <4.0.0" dependencies: - diff_match_patch: ^0.4.1 - equatable: ^2.0.7 freezed_annotation: ^2.4.4 - json_annotation: ^4.9.0 dev_dependencies: - build_runner: ^2.4.13 + build_runner: ^2.4.12 freezed: ^2.5.7 - json_serializable: ^6.9.0 + json_serializable: ^6.7.1 lints: ^4.0.0 test: ^1.24.0 - - diff --git a/pubspec.lock b/pubspec.lock index fdf2db3c..71b166a2 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -339,14 +339,6 @@ packages: url: "https://pub.dev" source: hosted version: "0.4.4" - diff_match_patch: - dependency: transitive - description: - name: diff_match_patch - sha256: "2efc9e6e8f449d0abe15be240e2c2a3bcd977c8d126cfd70598aee60af35c0a4" - url: "https://pub.dev" - source: hosted - version: "0.4.1" equatable: dependency: transitive description: From 17656671b62bbb565f9772345f820182e9c021b3 Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Mon, 24 Feb 2025 12:48:31 +0530 Subject: [PATCH 42/42] Update pubspec.yaml --- packages/insomnia_collection/pubspec.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/insomnia_collection/pubspec.yaml b/packages/insomnia_collection/pubspec.yaml index 4b174704..66f89b28 100644 --- a/packages/insomnia_collection/pubspec.yaml +++ b/packages/insomnia_collection/pubspec.yaml @@ -15,6 +15,7 @@ environment: dependencies: freezed_annotation: ^2.4.4 + json_annotation: ^4.9.0 dev_dependencies: build_runner: ^2.4.12