mirror of
https://github.com/foss42/apidash.git
synced 2025-12-02 18:57:05 +08:00
Merge pull request #525 from StormGear/add-feat-insomia
Added insomia importer
This commit is contained in:
@@ -9,6 +9,8 @@ enum APIType {
|
||||
final String abbr;
|
||||
}
|
||||
|
||||
enum EnvironmentVariableType { variable, secret }
|
||||
|
||||
enum HTTPVerb {
|
||||
get("GET"),
|
||||
head("HEAD"),
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
export 'curl_io.dart';
|
||||
export 'postman_io.dart';
|
||||
export 'insomnia_io.dart';
|
||||
|
||||
117
packages/apidash_core/lib/import_export/insomnia_io.dart
Normal file
117
packages/apidash_core/lib/import_export/insomnia_io.dart
Normal file
@@ -0,0 +1,117 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:insomnia_collection/insomnia_collection.dart';
|
||||
import 'package:seed/seed.dart';
|
||||
import '../consts.dart';
|
||||
import '../models/models.dart';
|
||||
import '../utils/utils.dart';
|
||||
|
||||
class InsomniaIO {
|
||||
List<(String?, HttpRequestModel)>? getHttpRequestModelList(String content) {
|
||||
content = content.trim();
|
||||
try {
|
||||
final ic = insomniaCollectionFromJsonStr(content);
|
||||
final requests = getRequestsFromInsomniaCollection(ic);
|
||||
|
||||
return requests
|
||||
.map((req) => (req.$1, insomniaResourceToHttpRequestModel(req.$2)))
|
||||
.toList();
|
||||
} catch (e) {
|
||||
debugPrint("$e");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
HttpRequestModel insomniaResourceToHttpRequestModel(Resource resource) {
|
||||
HTTPVerb method;
|
||||
try {
|
||||
method = HTTPVerb.values.byName((resource.method ?? "").toLowerCase());
|
||||
} catch (e) {
|
||||
method = kDefaultHttpMethod;
|
||||
}
|
||||
String url = stripUrlParams(resource.url ?? "");
|
||||
List<NameValueModel> headers = [];
|
||||
List<bool> isHeaderEnabledList = [];
|
||||
|
||||
List<NameValueModel> params = [];
|
||||
List<bool> isParamEnabledList = [];
|
||||
|
||||
for (var header in resource.headers ?? <Header>[]) {
|
||||
var name = header.name ?? "";
|
||||
var value = header.value ?? "";
|
||||
var activeHeader = header.disabled ?? false;
|
||||
headers.add(NameValueModel(name: name, value: value));
|
||||
isHeaderEnabledList.add(!activeHeader);
|
||||
}
|
||||
|
||||
for (var query in resource.parameters ?? <Parameter>[]) {
|
||||
var name = query.name ?? "";
|
||||
var value = query.value;
|
||||
var activeQuery = query.disabled ?? false;
|
||||
params.add(NameValueModel(name: name, value: value));
|
||||
isParamEnabledList.add(!activeQuery);
|
||||
}
|
||||
|
||||
ContentType bodyContentType =
|
||||
getContentTypeFromContentTypeStr(resource.body?.mimeType) ??
|
||||
kDefaultContentType;
|
||||
|
||||
String? body;
|
||||
List<FormDataModel>? formData;
|
||||
if (resource.body != null && resource.body?.mimeType != null) {
|
||||
if (bodyContentType == ContentType.formdata) {
|
||||
formData = [];
|
||||
for (var fd in resource.body?.params ?? <Formdatum>[]) {
|
||||
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 {
|
||||
body = resource.body?.text;
|
||||
}
|
||||
}
|
||||
|
||||
return HttpRequestModel(
|
||||
method: method,
|
||||
url: url,
|
||||
headers: headers,
|
||||
params: params,
|
||||
isHeaderEnabledList: isHeaderEnabledList,
|
||||
isParamEnabledList: isParamEnabledList,
|
||||
body: body,
|
||||
bodyContentType: bodyContentType,
|
||||
formData: formData,
|
||||
);
|
||||
}
|
||||
|
||||
EnvironmentModel insomniaResourceToEnvironmentModel(Resource resource) {
|
||||
List<EnvironmentVariableModel> 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,
|
||||
);
|
||||
}
|
||||
}
|
||||
82
packages/apidash_core/lib/models/environment_model.dart
Normal file
82
packages/apidash_core/lib/models/environment_model.dart
Normal file
@@ -0,0 +1,82 @@
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import '../consts.dart';
|
||||
|
||||
part 'environment_model.freezed.dart';
|
||||
|
||||
part 'environment_model.g.dart';
|
||||
|
||||
@freezed
|
||||
class EnvironmentModel with _$EnvironmentModel {
|
||||
@JsonSerializable(
|
||||
explicitToJson: true,
|
||||
anyMap: true,
|
||||
)
|
||||
const factory EnvironmentModel({
|
||||
required String id,
|
||||
@Default("") String name,
|
||||
@Default([]) List<EnvironmentVariableModel> values,
|
||||
}) = _EnvironmentModel;
|
||||
|
||||
factory EnvironmentModel.fromJson(Map<String, Object?> json) =>
|
||||
_$EnvironmentModelFromJson(json);
|
||||
}
|
||||
|
||||
@freezed
|
||||
class EnvironmentVariableModel with _$EnvironmentVariableModel {
|
||||
@JsonSerializable(
|
||||
explicitToJson: true,
|
||||
anyMap: true,
|
||||
)
|
||||
const factory EnvironmentVariableModel({
|
||||
required String key,
|
||||
required String value,
|
||||
@Default(EnvironmentVariableType.variable) EnvironmentVariableType type,
|
||||
@Default(false) bool enabled,
|
||||
}) = _EnvironmentVariableModel;
|
||||
|
||||
factory EnvironmentVariableModel.fromJson(Map<String, Object?> json) =>
|
||||
_$EnvironmentVariableModelFromJson(json);
|
||||
}
|
||||
|
||||
const kEnvironmentVariableEmptyModel =
|
||||
EnvironmentVariableModel(key: "", value: "");
|
||||
const kEnvironmentSecretEmptyModel = EnvironmentVariableModel(
|
||||
key: "", value: "", type: EnvironmentVariableType.secret);
|
||||
|
||||
class EnvironmentVariableSuggestion {
|
||||
final String environmentId;
|
||||
final EnvironmentVariableModel variable;
|
||||
final bool isUnknown;
|
||||
|
||||
const EnvironmentVariableSuggestion({
|
||||
required this.environmentId,
|
||||
required this.variable,
|
||||
this.isUnknown = false,
|
||||
});
|
||||
|
||||
EnvironmentVariableSuggestion copyWith({
|
||||
String? environmentId,
|
||||
EnvironmentVariableModel? variable,
|
||||
bool? isUnknown,
|
||||
}) {
|
||||
return EnvironmentVariableSuggestion(
|
||||
environmentId: environmentId ?? this.environmentId,
|
||||
variable: variable ?? this.variable,
|
||||
isUnknown: isUnknown ?? this.isUnknown,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
if (identical(this, other)) return true;
|
||||
|
||||
return other is EnvironmentVariableSuggestion &&
|
||||
other.environmentId == environmentId &&
|
||||
other.variable == variable &&
|
||||
other.isUnknown == isUnknown;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode =>
|
||||
environmentId.hashCode ^ variable.hashCode ^ isUnknown.hashCode;
|
||||
}
|
||||
430
packages/apidash_core/lib/models/environment_model.freezed.dart
Normal file
430
packages/apidash_core/lib/models/environment_model.freezed.dart
Normal file
@@ -0,0 +1,430 @@
|
||||
// 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 'environment_model.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');
|
||||
|
||||
EnvironmentModel _$EnvironmentModelFromJson(Map<String, dynamic> json) {
|
||||
return _EnvironmentModel.fromJson(json);
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
mixin _$EnvironmentModel {
|
||||
String get id => throw _privateConstructorUsedError;
|
||||
String get name => throw _privateConstructorUsedError;
|
||||
List<EnvironmentVariableModel> get values =>
|
||||
throw _privateConstructorUsedError;
|
||||
|
||||
/// Serializes this EnvironmentModel to a JSON map.
|
||||
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
|
||||
|
||||
/// Create a copy of EnvironmentModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
$EnvironmentModelCopyWith<EnvironmentModel> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class $EnvironmentModelCopyWith<$Res> {
|
||||
factory $EnvironmentModelCopyWith(
|
||||
EnvironmentModel value, $Res Function(EnvironmentModel) then) =
|
||||
_$EnvironmentModelCopyWithImpl<$Res, EnvironmentModel>;
|
||||
@useResult
|
||||
$Res call({String id, String name, List<EnvironmentVariableModel> values});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class _$EnvironmentModelCopyWithImpl<$Res, $Val extends EnvironmentModel>
|
||||
implements $EnvironmentModelCopyWith<$Res> {
|
||||
_$EnvironmentModelCopyWithImpl(this._value, this._then);
|
||||
|
||||
// ignore: unused_field
|
||||
final $Val _value;
|
||||
// ignore: unused_field
|
||||
final $Res Function($Val) _then;
|
||||
|
||||
/// Create a copy of EnvironmentModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? id = null,
|
||||
Object? name = null,
|
||||
Object? values = null,
|
||||
}) {
|
||||
return _then(_value.copyWith(
|
||||
id: null == id
|
||||
? _value.id
|
||||
: id // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
name: null == name
|
||||
? _value.name
|
||||
: name // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
values: null == values
|
||||
? _value.values
|
||||
: values // ignore: cast_nullable_to_non_nullable
|
||||
as List<EnvironmentVariableModel>,
|
||||
) as $Val);
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$EnvironmentModelImplCopyWith<$Res>
|
||||
implements $EnvironmentModelCopyWith<$Res> {
|
||||
factory _$$EnvironmentModelImplCopyWith(_$EnvironmentModelImpl value,
|
||||
$Res Function(_$EnvironmentModelImpl) then) =
|
||||
__$$EnvironmentModelImplCopyWithImpl<$Res>;
|
||||
@override
|
||||
@useResult
|
||||
$Res call({String id, String name, List<EnvironmentVariableModel> values});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$EnvironmentModelImplCopyWithImpl<$Res>
|
||||
extends _$EnvironmentModelCopyWithImpl<$Res, _$EnvironmentModelImpl>
|
||||
implements _$$EnvironmentModelImplCopyWith<$Res> {
|
||||
__$$EnvironmentModelImplCopyWithImpl(_$EnvironmentModelImpl _value,
|
||||
$Res Function(_$EnvironmentModelImpl) _then)
|
||||
: super(_value, _then);
|
||||
|
||||
/// Create a copy of EnvironmentModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? id = null,
|
||||
Object? name = null,
|
||||
Object? values = null,
|
||||
}) {
|
||||
return _then(_$EnvironmentModelImpl(
|
||||
id: null == id
|
||||
? _value.id
|
||||
: id // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
name: null == name
|
||||
? _value.name
|
||||
: name // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
values: null == values
|
||||
? _value._values
|
||||
: values // ignore: cast_nullable_to_non_nullable
|
||||
as List<EnvironmentVariableModel>,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
@JsonSerializable(explicitToJson: true, anyMap: true)
|
||||
class _$EnvironmentModelImpl implements _EnvironmentModel {
|
||||
const _$EnvironmentModelImpl(
|
||||
{required this.id,
|
||||
this.name = "",
|
||||
final List<EnvironmentVariableModel> values = const []})
|
||||
: _values = values;
|
||||
|
||||
factory _$EnvironmentModelImpl.fromJson(Map<String, dynamic> json) =>
|
||||
_$$EnvironmentModelImplFromJson(json);
|
||||
|
||||
@override
|
||||
final String id;
|
||||
@override
|
||||
@JsonKey()
|
||||
final String name;
|
||||
final List<EnvironmentVariableModel> _values;
|
||||
@override
|
||||
@JsonKey()
|
||||
List<EnvironmentVariableModel> get values {
|
||||
if (_values is EqualUnmodifiableListView) return _values;
|
||||
// ignore: implicit_dynamic_type
|
||||
return EqualUnmodifiableListView(_values);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'EnvironmentModel(id: $id, name: $name, values: $values)';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _$EnvironmentModelImpl &&
|
||||
(identical(other.id, id) || other.id == id) &&
|
||||
(identical(other.name, name) || other.name == name) &&
|
||||
const DeepCollectionEquality().equals(other._values, _values));
|
||||
}
|
||||
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
int get hashCode => Object.hash(
|
||||
runtimeType, id, name, const DeepCollectionEquality().hash(_values));
|
||||
|
||||
/// Create a copy of EnvironmentModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
_$$EnvironmentModelImplCopyWith<_$EnvironmentModelImpl> get copyWith =>
|
||||
__$$EnvironmentModelImplCopyWithImpl<_$EnvironmentModelImpl>(
|
||||
this, _$identity);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
return _$$EnvironmentModelImplToJson(
|
||||
this,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
abstract class _EnvironmentModel implements EnvironmentModel {
|
||||
const factory _EnvironmentModel(
|
||||
{required final String id,
|
||||
final String name,
|
||||
final List<EnvironmentVariableModel> values}) = _$EnvironmentModelImpl;
|
||||
|
||||
factory _EnvironmentModel.fromJson(Map<String, dynamic> json) =
|
||||
_$EnvironmentModelImpl.fromJson;
|
||||
|
||||
@override
|
||||
String get id;
|
||||
@override
|
||||
String get name;
|
||||
@override
|
||||
List<EnvironmentVariableModel> get values;
|
||||
|
||||
/// Create a copy of EnvironmentModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
_$$EnvironmentModelImplCopyWith<_$EnvironmentModelImpl> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
EnvironmentVariableModel _$EnvironmentVariableModelFromJson(
|
||||
Map<String, dynamic> json) {
|
||||
return _EnvironmentVariableModel.fromJson(json);
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
mixin _$EnvironmentVariableModel {
|
||||
String get key => throw _privateConstructorUsedError;
|
||||
String get value => throw _privateConstructorUsedError;
|
||||
EnvironmentVariableType get type => throw _privateConstructorUsedError;
|
||||
bool get enabled => throw _privateConstructorUsedError;
|
||||
|
||||
/// Serializes this EnvironmentVariableModel to a JSON map.
|
||||
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
|
||||
|
||||
/// Create a copy of EnvironmentVariableModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
$EnvironmentVariableModelCopyWith<EnvironmentVariableModel> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class $EnvironmentVariableModelCopyWith<$Res> {
|
||||
factory $EnvironmentVariableModelCopyWith(EnvironmentVariableModel value,
|
||||
$Res Function(EnvironmentVariableModel) then) =
|
||||
_$EnvironmentVariableModelCopyWithImpl<$Res, EnvironmentVariableModel>;
|
||||
@useResult
|
||||
$Res call(
|
||||
{String key, String value, EnvironmentVariableType type, bool enabled});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class _$EnvironmentVariableModelCopyWithImpl<$Res,
|
||||
$Val extends EnvironmentVariableModel>
|
||||
implements $EnvironmentVariableModelCopyWith<$Res> {
|
||||
_$EnvironmentVariableModelCopyWithImpl(this._value, this._then);
|
||||
|
||||
// ignore: unused_field
|
||||
final $Val _value;
|
||||
// ignore: unused_field
|
||||
final $Res Function($Val) _then;
|
||||
|
||||
/// Create a copy of EnvironmentVariableModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? key = null,
|
||||
Object? value = null,
|
||||
Object? type = null,
|
||||
Object? enabled = null,
|
||||
}) {
|
||||
return _then(_value.copyWith(
|
||||
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: null == type
|
||||
? _value.type
|
||||
: type // ignore: cast_nullable_to_non_nullable
|
||||
as EnvironmentVariableType,
|
||||
enabled: null == enabled
|
||||
? _value.enabled
|
||||
: enabled // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
) as $Val);
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$EnvironmentVariableModelImplCopyWith<$Res>
|
||||
implements $EnvironmentVariableModelCopyWith<$Res> {
|
||||
factory _$$EnvironmentVariableModelImplCopyWith(
|
||||
_$EnvironmentVariableModelImpl value,
|
||||
$Res Function(_$EnvironmentVariableModelImpl) then) =
|
||||
__$$EnvironmentVariableModelImplCopyWithImpl<$Res>;
|
||||
@override
|
||||
@useResult
|
||||
$Res call(
|
||||
{String key, String value, EnvironmentVariableType type, bool enabled});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$EnvironmentVariableModelImplCopyWithImpl<$Res>
|
||||
extends _$EnvironmentVariableModelCopyWithImpl<$Res,
|
||||
_$EnvironmentVariableModelImpl>
|
||||
implements _$$EnvironmentVariableModelImplCopyWith<$Res> {
|
||||
__$$EnvironmentVariableModelImplCopyWithImpl(
|
||||
_$EnvironmentVariableModelImpl _value,
|
||||
$Res Function(_$EnvironmentVariableModelImpl) _then)
|
||||
: super(_value, _then);
|
||||
|
||||
/// Create a copy of EnvironmentVariableModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? key = null,
|
||||
Object? value = null,
|
||||
Object? type = null,
|
||||
Object? enabled = null,
|
||||
}) {
|
||||
return _then(_$EnvironmentVariableModelImpl(
|
||||
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: null == type
|
||||
? _value.type
|
||||
: type // ignore: cast_nullable_to_non_nullable
|
||||
as EnvironmentVariableType,
|
||||
enabled: null == enabled
|
||||
? _value.enabled
|
||||
: enabled // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
@JsonSerializable(explicitToJson: true, anyMap: true)
|
||||
class _$EnvironmentVariableModelImpl implements _EnvironmentVariableModel {
|
||||
const _$EnvironmentVariableModelImpl(
|
||||
{required this.key,
|
||||
required this.value,
|
||||
this.type = EnvironmentVariableType.variable,
|
||||
this.enabled = false});
|
||||
|
||||
factory _$EnvironmentVariableModelImpl.fromJson(Map<String, dynamic> json) =>
|
||||
_$$EnvironmentVariableModelImplFromJson(json);
|
||||
|
||||
@override
|
||||
final String key;
|
||||
@override
|
||||
final String value;
|
||||
@override
|
||||
@JsonKey()
|
||||
final EnvironmentVariableType type;
|
||||
@override
|
||||
@JsonKey()
|
||||
final bool enabled;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'EnvironmentVariableModel(key: $key, value: $value, type: $type, enabled: $enabled)';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _$EnvironmentVariableModelImpl &&
|
||||
(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, key, value, type, enabled);
|
||||
|
||||
/// Create a copy of EnvironmentVariableModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
_$$EnvironmentVariableModelImplCopyWith<_$EnvironmentVariableModelImpl>
|
||||
get copyWith => __$$EnvironmentVariableModelImplCopyWithImpl<
|
||||
_$EnvironmentVariableModelImpl>(this, _$identity);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
return _$$EnvironmentVariableModelImplToJson(
|
||||
this,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
abstract class _EnvironmentVariableModel implements EnvironmentVariableModel {
|
||||
const factory _EnvironmentVariableModel(
|
||||
{required final String key,
|
||||
required final String value,
|
||||
final EnvironmentVariableType type,
|
||||
final bool enabled}) = _$EnvironmentVariableModelImpl;
|
||||
|
||||
factory _EnvironmentVariableModel.fromJson(Map<String, dynamic> json) =
|
||||
_$EnvironmentVariableModelImpl.fromJson;
|
||||
|
||||
@override
|
||||
String get key;
|
||||
@override
|
||||
String get value;
|
||||
@override
|
||||
EnvironmentVariableType get type;
|
||||
@override
|
||||
bool get enabled;
|
||||
|
||||
/// Create a copy of EnvironmentVariableModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
_$$EnvironmentVariableModelImplCopyWith<_$EnvironmentVariableModelImpl>
|
||||
get copyWith => throw _privateConstructorUsedError;
|
||||
}
|
||||
51
packages/apidash_core/lib/models/environment_model.g.dart
Normal file
51
packages/apidash_core/lib/models/environment_model.g.dart
Normal file
@@ -0,0 +1,51 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'environment_model.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
_$EnvironmentModelImpl _$$EnvironmentModelImplFromJson(Map json) =>
|
||||
_$EnvironmentModelImpl(
|
||||
id: json['id'] as String,
|
||||
name: json['name'] as String? ?? "",
|
||||
values: (json['values'] as List<dynamic>?)
|
||||
?.map((e) => EnvironmentVariableModel.fromJson(
|
||||
Map<String, Object?>.from(e as Map)))
|
||||
.toList() ??
|
||||
const [],
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$EnvironmentModelImplToJson(
|
||||
_$EnvironmentModelImpl instance) =>
|
||||
<String, dynamic>{
|
||||
'id': instance.id,
|
||||
'name': instance.name,
|
||||
'values': instance.values.map((e) => e.toJson()).toList(),
|
||||
};
|
||||
|
||||
_$EnvironmentVariableModelImpl _$$EnvironmentVariableModelImplFromJson(
|
||||
Map json) =>
|
||||
_$EnvironmentVariableModelImpl(
|
||||
key: json['key'] as String,
|
||||
value: json['value'] as String,
|
||||
type:
|
||||
$enumDecodeNullable(_$EnvironmentVariableTypeEnumMap, json['type']) ??
|
||||
EnvironmentVariableType.variable,
|
||||
enabled: json['enabled'] as bool? ?? false,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$EnvironmentVariableModelImplToJson(
|
||||
_$EnvironmentVariableModelImpl instance) =>
|
||||
<String, dynamic>{
|
||||
'key': instance.key,
|
||||
'value': instance.value,
|
||||
'type': _$EnvironmentVariableTypeEnumMap[instance.type]!,
|
||||
'enabled': instance.enabled,
|
||||
};
|
||||
|
||||
const _$EnvironmentVariableTypeEnumMap = {
|
||||
EnvironmentVariableType.variable: 'variable',
|
||||
EnvironmentVariableType.secret: 'secret',
|
||||
};
|
||||
@@ -1,2 +1,3 @@
|
||||
export 'environment_model.dart';
|
||||
export 'http_request_model.dart';
|
||||
export 'http_response_model.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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user