add environment when insomia v4 is imported

This commit is contained in:
StormGear
2025-01-30 15:39:45 +00:00
parent 7b43a297df
commit 180fd59a1f
12 changed files with 737 additions and 8 deletions

View File

@ -1,3 +1,4 @@
import 'package:apidash/utils/envvar_utils.dart';
import 'package:apidash_design_system/apidash_design_system.dart'; import 'package:apidash_design_system/apidash_design_system.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart';
@ -10,9 +11,6 @@ void importToCollectionPane(
WidgetRef ref, WidgetRef ref,
ScaffoldMessengerState sm, 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( showImportDialog(
context: context, context: context,
importFormat: ref.watch(importFormatStateProvider), importFormat: ref.watch(importFormatStateProvider),
@ -26,6 +24,26 @@ void importToCollectionPane(
sm.hideCurrentSnackBar(); sm.hideCurrentSnackBar();
file.readAsString().then( file.readAsString().then(
(content) { (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 kImporter
.getHttpRequestModelList(importFormatType, content) .getHttpRequestModelList(importFormatType, content)
.then((importedRequestModels) { .then((importedRequestModels) {

View File

@ -1,5 +1,6 @@
import 'package:apidash/consts.dart'; import 'package:apidash/consts.dart';
import 'package:apidash_core/apidash_core.dart'; import 'package:apidash_core/apidash_core.dart';
import 'package:insomnia_collection/models/insomnia_environment.dart';
class Importer { class Importer {
Future<List<(String?, HttpRequestModel)>?> getHttpRequestModelList( Future<List<(String?, HttpRequestModel)>?> getHttpRequestModelList(
@ -17,4 +18,15 @@ class Importer {
} }
} }
class EnvImporter {
Future<InsomniaEnvironment?> getInsomniaEnvironment(
ImportFormat fileType, String content) async {
return switch (fileType) {
ImportFormat.insomnia => InsomniaIO().getInsomiaEnvironment(content),
_ => null
};
}
}
final kImporter = Importer(); final kImporter = Importer();
final kEnvImporter = EnvImporter();

View File

@ -26,6 +26,7 @@ class EnvironmentsPane extends ConsumerWidget {
ref ref
.read(environmentsStateNotifierProvider.notifier) .read(environmentsStateNotifierProvider.notifier)
.addEnvironment(); .addEnvironment();
// createNewEnvironment(ref);
}, },
), ),
kVSpacer10, kVSpacer10,

View File

@ -1,6 +1,49 @@
import 'package:apidash/providers/environment_providers.dart';
import 'package:apidash_core/apidash_core.dart'; import 'package:apidash_core/apidash_core.dart';
import 'package:apidash/consts.dart'; import 'package:apidash/consts.dart';
import 'package:apidash/models/models.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<EnvironmentVariableModel> 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<EnvironmentVariableModel> 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) { String getEnvironmentTitle(String? name) {
if (name == null || name.trim() == "") { if (name == null || name.trim() == "") {

View File

@ -1,3 +1,4 @@
import 'package:insomnia_collection/models/insomnia_environment.dart';
import 'package:seed/seed.dart'; import 'package:seed/seed.dart';
import '../consts.dart'; import '../consts.dart';
import '../models/models.dart'; import '../models/models.dart';
@ -10,6 +11,10 @@ class InsomniaIO {
try { try {
final ic = ins.insomniaCollectionFromJsonStr(content); final ic = ins.insomniaCollectionFromJsonStr(content);
final requests = ins.getRequestsFromInsomniaCollection(ic); final requests = ins.getRequestsFromInsomniaCollection(ic);
/// TODO; Get env from the insomnia collection
// final environmentVariables = ins.getEnvironmentVariablesFromInsomniaEnvironment(env);
return requests return requests
.map((req) => (req.$1, insomniaRequestToHttpRequestModel(req.$2))) .map((req) => (req.$1, insomniaRequestToHttpRequestModel(req.$2)))
.toList(); .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) { HttpRequestModel insomniaRequestToHttpRequestModel(ins.Resource request) {
HTTPVerb method; HTTPVerb method;
@ -89,8 +105,6 @@ class InsomniaIO {
} }
body = request.body?.text; body = request.body?.text;
} }
/// TODO: Handle formdata and text
} }
return HttpRequestModel( return HttpRequestModel(

View File

@ -1,9 +1,30 @@
import 'dart:convert'; import 'dart:convert';
import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:insomnia_collection/models/insomnia_environment.dart';
part 'insomnia_collection.freezed.dart'; part 'insomnia_collection.freezed.dart';
part 'insomnia_collection.g.dart'; part 'insomnia_collection.g.dart';
InsomniaEnvironment insomniaEnvironmentFromJsonStr(String str) {
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<String, dynamic> json) {
// Remove all resources which are not requests
json['resources'] = (json['resources'] as List)
.where((resource) => resource['_type'] == 'environment')
.toList();
return InsomniaEnvironment.fromJson(json['resources'][0]);
}
InsomniaCollection insomniaCollectionFromJsonStr(String str) { InsomniaCollection insomniaCollectionFromJsonStr(String str) {
var Insomniajson = json.decode(str); var Insomniajson = json.decode(str);
// Remove all resources which are not requests // Remove all resources which are not requests
@ -14,7 +35,6 @@ InsomniaCollection insomniaCollectionFromJsonStr(String str) {
return InsomniaCollection.fromJson(Insomniajson); return InsomniaCollection.fromJson(Insomniajson);
} }
InsomniaCollection insomniaCollectionFromJson(Map<String, dynamic> json) { InsomniaCollection insomniaCollectionFromJson(Map<String, dynamic> json) {
// Remove all resources which are not requests // Remove all resources which are not requests
json['resources'] = (json['resources'] as List) json['resources'] = (json['resources'] as List)

View File

@ -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<EnvironmentVariable>? resources ,
@JsonKey(name: '_type') String? type,
}) = _InsomniaEnvironment;
factory InsomniaEnvironment.fromJson(Map<String, dynamic> 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<String, dynamic> 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());
}

View File

@ -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>(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<String, dynamic> 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<EnvironmentVariable>? get resources =>
throw _privateConstructorUsedError;
@JsonKey(name: '_type')
String? get type => throw _privateConstructorUsedError;
/// Serializes this InsomniaEnvironment to a JSON map.
Map<String, dynamic> 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<InsomniaEnvironment> 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<EnvironmentVariable>? 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<EnvironmentVariable>?,
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<EnvironmentVariable>? 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<EnvironmentVariable>?,
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<EnvironmentVariable>? resources,
@JsonKey(name: '_type') this.type})
: _resources = resources;
factory _$InsomniaEnvironmentImpl.fromJson(Map<String, dynamic> json) =>
_$$InsomniaEnvironmentImplFromJson(json);
@override
@JsonKey(name: '_id')
final String? id;
@override
final String? name;
final List<EnvironmentVariable>? _resources;
@override
@JsonKey(name: 'kvPairData')
List<EnvironmentVariable>? 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<String, dynamic> 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<EnvironmentVariable>? resources,
@JsonKey(name: '_type') final String? type}) = _$InsomniaEnvironmentImpl;
factory _InsomniaEnvironment.fromJson(Map<String, dynamic> json) =
_$InsomniaEnvironmentImpl.fromJson;
@override
@JsonKey(name: '_id')
String? get id;
@override
String? get name;
@override
@JsonKey(name: 'kvPairData')
List<EnvironmentVariable>? 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<String, dynamic> 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<String, dynamic> 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<EnvironmentVariable> 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<String, dynamic> 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<String, dynamic> 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<String, dynamic> 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;
}

View File

@ -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<dynamic>?)
?.map((e) =>
EnvironmentVariable.fromJson(Map<String, dynamic>.from(e as Map)))
.toList(),
type: json['_type'] as String?,
);
Map<String, dynamic> _$$InsomniaEnvironmentImplToJson(
_$InsomniaEnvironmentImpl instance) =>
<String, dynamic>{
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<String, dynamic> _$$EnvironmentVariableImplToJson(
_$EnvironmentVariableImpl instance) =>
<String, dynamic>{
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,
};

View File

@ -2,6 +2,7 @@
import 'package:insomnia_collection/models/insomnia_collection.dart'; import 'package:insomnia_collection/models/insomnia_collection.dart';
import 'package:insomnia_collection/models/insomnia_environment.dart';
List<(String?, Resource)> getRequestsFromInsomniaCollection( List<(String?, Resource)> getRequestsFromInsomniaCollection(
InsomniaCollection? ic) { InsomniaCollection? ic) {
@ -17,6 +18,20 @@ List<(String?, Resource)> getRequestsFromInsomniaCollection(
return requests; return requests;
} }
List<EnvironmentVariable> getEnvironmentVariablesFromInsomniaEnvironment(
InsomniaEnvironment? ev) {
if (ev == null || ev.resources == null) {
return [];
}
List<EnvironmentVariable> envVariables = [];
if (ev.resources!.length > 0) {
for (var envvar in ev.resources!) {
envVariables.add(envvar);
}
}
return envVariables;
}
List<(String?, Resource)> getRequestsFromInsomniaResource(Resource? resource) { List<(String?, Resource)> getRequestsFromInsomniaResource(Resource? resource) {
if (resource == null) { if (resource == null) {
return []; return [];
@ -28,4 +43,5 @@ List<(String?, Resource)> getRequestsFromInsomniaResource(Resource? resource) {
print('Resource type is not request'); print('Resource type is not request');
} }
return requests; return requests;
} }

View File

@ -773,7 +773,7 @@ packages:
source: hosted source: hosted
version: "4.3.0" version: "4.3.0"
insomnia_collection: insomnia_collection:
dependency: transitive dependency: "direct main"
description: description:
path: "packages/insomnia_collection" path: "packages/insomnia_collection"
relative: true relative: true

View File

@ -12,6 +12,8 @@ dependencies:
sdk: flutter sdk: flutter
apidash_core: apidash_core:
path: packages/apidash_core path: packages/apidash_core
insomnia_collection:
path: packages/insomnia_collection
apidash_design_system: apidash_design_system:
path: packages/apidash_design_system path: packages/apidash_design_system
code_builder: ^4.10.0 code_builder: ^4.10.0