diff --git a/lib/models/history_request_model.dart b/lib/models/history_request_model.dart index 1ffc5460..4235d643 100644 --- a/lib/models/history_request_model.dart +++ b/lib/models/history_request_model.dart @@ -16,8 +16,7 @@ class HistoryRequestModel with _$HistoryRequestModel { required HistoryMetaModel metaData, required HttpRequestModel httpRequestModel, required HttpResponseModel httpResponseModel, - String? preRequestScript, - String? postRequestScript, + required AuthModel? authModel, }) = _HistoryRequestModel; factory HistoryRequestModel.fromJson(Map json) => diff --git a/lib/models/history_request_model.freezed.dart b/lib/models/history_request_model.freezed.dart index ac43f3ee..8afe5c5a 100644 --- a/lib/models/history_request_model.freezed.dart +++ b/lib/models/history_request_model.freezed.dart @@ -24,8 +24,7 @@ mixin _$HistoryRequestModel { HistoryMetaModel get metaData => throw _privateConstructorUsedError; HttpRequestModel get httpRequestModel => throw _privateConstructorUsedError; HttpResponseModel get httpResponseModel => throw _privateConstructorUsedError; - String? get preRequestScript => throw _privateConstructorUsedError; - String? get postRequestScript => throw _privateConstructorUsedError; + AuthModel? get authModel => throw _privateConstructorUsedError; /// Serializes this HistoryRequestModel to a JSON map. Map toJson() => throw _privateConstructorUsedError; @@ -48,12 +47,12 @@ abstract class $HistoryRequestModelCopyWith<$Res> { HistoryMetaModel metaData, HttpRequestModel httpRequestModel, HttpResponseModel httpResponseModel, - String? preRequestScript, - String? postRequestScript}); + AuthModel? authModel}); $HistoryMetaModelCopyWith<$Res> get metaData; $HttpRequestModelCopyWith<$Res> get httpRequestModel; $HttpResponseModelCopyWith<$Res> get httpResponseModel; + $AuthModelCopyWith<$Res>? get authModel; } /// @nodoc @@ -75,8 +74,7 @@ class _$HistoryRequestModelCopyWithImpl<$Res, $Val extends HistoryRequestModel> Object? metaData = null, Object? httpRequestModel = null, Object? httpResponseModel = null, - Object? preRequestScript = freezed, - Object? postRequestScript = freezed, + Object? authModel = freezed, }) { return _then(_value.copyWith( historyId: null == historyId @@ -95,14 +93,10 @@ class _$HistoryRequestModelCopyWithImpl<$Res, $Val extends HistoryRequestModel> ? _value.httpResponseModel : httpResponseModel // ignore: cast_nullable_to_non_nullable as HttpResponseModel, - preRequestScript: freezed == preRequestScript - ? _value.preRequestScript - : preRequestScript // ignore: cast_nullable_to_non_nullable - as String?, - postRequestScript: freezed == postRequestScript - ? _value.postRequestScript - : postRequestScript // ignore: cast_nullable_to_non_nullable - as String?, + authModel: freezed == authModel + ? _value.authModel + : authModel // ignore: cast_nullable_to_non_nullable + as AuthModel?, ) as $Val); } @@ -135,6 +129,20 @@ class _$HistoryRequestModelCopyWithImpl<$Res, $Val extends HistoryRequestModel> return _then(_value.copyWith(httpResponseModel: value) as $Val); }); } + + /// Create a copy of HistoryRequestModel + /// with the given fields replaced by the non-null parameter values. + @override + @pragma('vm:prefer-inline') + $AuthModelCopyWith<$Res>? get authModel { + if (_value.authModel == null) { + return null; + } + + return $AuthModelCopyWith<$Res>(_value.authModel!, (value) { + return _then(_value.copyWith(authModel: value) as $Val); + }); + } } /// @nodoc @@ -150,8 +158,7 @@ abstract class _$$HistoryRequestModelImplCopyWith<$Res> HistoryMetaModel metaData, HttpRequestModel httpRequestModel, HttpResponseModel httpResponseModel, - String? preRequestScript, - String? postRequestScript}); + AuthModel? authModel}); @override $HistoryMetaModelCopyWith<$Res> get metaData; @@ -159,6 +166,8 @@ abstract class _$$HistoryRequestModelImplCopyWith<$Res> $HttpRequestModelCopyWith<$Res> get httpRequestModel; @override $HttpResponseModelCopyWith<$Res> get httpResponseModel; + @override + $AuthModelCopyWith<$Res>? get authModel; } /// @nodoc @@ -178,8 +187,7 @@ class __$$HistoryRequestModelImplCopyWithImpl<$Res> Object? metaData = null, Object? httpRequestModel = null, Object? httpResponseModel = null, - Object? preRequestScript = freezed, - Object? postRequestScript = freezed, + Object? authModel = freezed, }) { return _then(_$HistoryRequestModelImpl( historyId: null == historyId @@ -198,14 +206,10 @@ class __$$HistoryRequestModelImplCopyWithImpl<$Res> ? _value.httpResponseModel : httpResponseModel // ignore: cast_nullable_to_non_nullable as HttpResponseModel, - preRequestScript: freezed == preRequestScript - ? _value.preRequestScript - : preRequestScript // ignore: cast_nullable_to_non_nullable - as String?, - postRequestScript: freezed == postRequestScript - ? _value.postRequestScript - : postRequestScript // ignore: cast_nullable_to_non_nullable - as String?, + authModel: freezed == authModel + ? _value.authModel + : authModel // ignore: cast_nullable_to_non_nullable + as AuthModel?, )); } } @@ -219,8 +223,7 @@ class _$HistoryRequestModelImpl implements _HistoryRequestModel { required this.metaData, required this.httpRequestModel, required this.httpResponseModel, - this.preRequestScript, - this.postRequestScript}); + required this.authModel}); factory _$HistoryRequestModelImpl.fromJson(Map json) => _$$HistoryRequestModelImplFromJson(json); @@ -234,13 +237,11 @@ class _$HistoryRequestModelImpl implements _HistoryRequestModel { @override final HttpResponseModel httpResponseModel; @override - final String? preRequestScript; - @override - final String? postRequestScript; + final AuthModel? authModel; @override String toString() { - return 'HistoryRequestModel(historyId: $historyId, metaData: $metaData, httpRequestModel: $httpRequestModel, httpResponseModel: $httpResponseModel, preRequestScript: $preRequestScript, postRequestScript: $postRequestScript)'; + return 'HistoryRequestModel(historyId: $historyId, metaData: $metaData, httpRequestModel: $httpRequestModel, httpResponseModel: $httpResponseModel, authModel: $authModel)'; } @override @@ -256,16 +257,14 @@ class _$HistoryRequestModelImpl implements _HistoryRequestModel { other.httpRequestModel == httpRequestModel) && (identical(other.httpResponseModel, httpResponseModel) || other.httpResponseModel == httpResponseModel) && - (identical(other.preRequestScript, preRequestScript) || - other.preRequestScript == preRequestScript) && - (identical(other.postRequestScript, postRequestScript) || - other.postRequestScript == postRequestScript)); + (identical(other.authModel, authModel) || + other.authModel == authModel)); } @JsonKey(includeFromJson: false, includeToJson: false) @override int get hashCode => Object.hash(runtimeType, historyId, metaData, - httpRequestModel, httpResponseModel, preRequestScript, postRequestScript); + httpRequestModel, httpResponseModel, authModel); /// Create a copy of HistoryRequestModel /// with the given fields replaced by the non-null parameter values. @@ -290,8 +289,7 @@ abstract class _HistoryRequestModel implements HistoryRequestModel { required final HistoryMetaModel metaData, required final HttpRequestModel httpRequestModel, required final HttpResponseModel httpResponseModel, - final String? preRequestScript, - final String? postRequestScript}) = _$HistoryRequestModelImpl; + required final AuthModel? authModel}) = _$HistoryRequestModelImpl; factory _HistoryRequestModel.fromJson(Map json) = _$HistoryRequestModelImpl.fromJson; @@ -305,9 +303,7 @@ abstract class _HistoryRequestModel implements HistoryRequestModel { @override HttpResponseModel get httpResponseModel; @override - String? get preRequestScript; - @override - String? get postRequestScript; + AuthModel? get authModel; /// Create a copy of HistoryRequestModel /// with the given fields replaced by the non-null parameter values. diff --git a/lib/models/history_request_model.g.dart b/lib/models/history_request_model.g.dart index 705a2022..a3f852fd 100644 --- a/lib/models/history_request_model.g.dart +++ b/lib/models/history_request_model.g.dart @@ -15,8 +15,10 @@ _$HistoryRequestModelImpl _$$HistoryRequestModelImplFromJson(Map json) => Map.from(json['httpRequestModel'] as Map)), httpResponseModel: HttpResponseModel.fromJson( Map.from(json['httpResponseModel'] as Map)), - preRequestScript: json['preRequestScript'] as String?, - postRequestScript: json['postRequestScript'] as String?, + authModel: json['authModel'] == null + ? null + : AuthModel.fromJson( + Map.from(json['authModel'] as Map)), ); Map _$$HistoryRequestModelImplToJson( @@ -26,6 +28,5 @@ Map _$$HistoryRequestModelImplToJson( 'metaData': instance.metaData.toJson(), 'httpRequestModel': instance.httpRequestModel.toJson(), 'httpResponseModel': instance.httpResponseModel.toJson(), - 'preRequestScript': instance.preRequestScript, - 'postRequestScript': instance.postRequestScript, + 'authModel': instance.authModel?.toJson(), }; diff --git a/lib/models/request_model.dart b/lib/models/request_model.dart index a3eda0ba..4cf4eef8 100644 --- a/lib/models/request_model.dart +++ b/lib/models/request_model.dart @@ -23,8 +23,7 @@ class RequestModel with _$RequestModel { HttpResponseModel? httpResponseModel, @JsonKey(includeToJson: false) @Default(false) bool isWorking, @JsonKey(includeToJson: false) DateTime? sendingTime, - String? preRequestScript, - String? postRequestScript, + @Default(AuthModel(type: APIAuthType.none)) AuthModel? authModel, }) = _RequestModel; factory RequestModel.fromJson(Map json) => diff --git a/lib/models/request_model.freezed.dart b/lib/models/request_model.freezed.dart index 392c34f8..d8b9c417 100644 --- a/lib/models/request_model.freezed.dart +++ b/lib/models/request_model.freezed.dart @@ -36,8 +36,7 @@ mixin _$RequestModel { bool get isWorking => throw _privateConstructorUsedError; @JsonKey(includeToJson: false) DateTime? get sendingTime => throw _privateConstructorUsedError; - String? get preRequestScript => throw _privateConstructorUsedError; - String? get postRequestScript => throw _privateConstructorUsedError; + AuthModel? get authModel => throw _privateConstructorUsedError; /// Serializes this RequestModel to a JSON map. Map toJson() => throw _privateConstructorUsedError; @@ -68,12 +67,12 @@ abstract class $RequestModelCopyWith<$Res> { HttpResponseModel? httpResponseModel, @JsonKey(includeToJson: false) bool isWorking, @JsonKey(includeToJson: false) DateTime? sendingTime, - String? preRequestScript, - String? postRequestScript}); + AuthModel? authModel}); $AuthModelCopyWith<$Res>? get authModel; $HttpRequestModelCopyWith<$Res>? get httpRequestModel; $HttpResponseModelCopyWith<$Res>? get httpResponseModel; + $AuthModelCopyWith<$Res>? get authModel; } /// @nodoc @@ -103,8 +102,7 @@ class _$RequestModelCopyWithImpl<$Res, $Val extends RequestModel> Object? httpResponseModel = freezed, Object? isWorking = null, Object? sendingTime = freezed, - Object? preRequestScript = freezed, - Object? postRequestScript = freezed, + Object? authModel = freezed, }) { return _then(_value.copyWith( id: null == id @@ -155,14 +153,10 @@ class _$RequestModelCopyWithImpl<$Res, $Val extends RequestModel> ? _value.sendingTime : sendingTime // ignore: cast_nullable_to_non_nullable as DateTime?, - preRequestScript: freezed == preRequestScript - ? _value.preRequestScript - : preRequestScript // ignore: cast_nullable_to_non_nullable - as String?, - postRequestScript: freezed == postRequestScript - ? _value.postRequestScript - : postRequestScript // ignore: cast_nullable_to_non_nullable - as String?, + authModel: freezed == authModel + ? _value.authModel + : authModel // ignore: cast_nullable_to_non_nullable + as AuthModel?, ) as $Val); } @@ -207,6 +201,20 @@ class _$RequestModelCopyWithImpl<$Res, $Val extends RequestModel> return _then(_value.copyWith(httpResponseModel: value) as $Val); }); } + + /// Create a copy of RequestModel + /// with the given fields replaced by the non-null parameter values. + @override + @pragma('vm:prefer-inline') + $AuthModelCopyWith<$Res>? get authModel { + if (_value.authModel == null) { + return null; + } + + return $AuthModelCopyWith<$Res>(_value.authModel!, (value) { + return _then(_value.copyWith(authModel: value) as $Val); + }); + } } /// @nodoc @@ -230,8 +238,7 @@ abstract class _$$RequestModelImplCopyWith<$Res> HttpResponseModel? httpResponseModel, @JsonKey(includeToJson: false) bool isWorking, @JsonKey(includeToJson: false) DateTime? sendingTime, - String? preRequestScript, - String? postRequestScript}); + AuthModel? authModel}); @override $AuthModelCopyWith<$Res>? get authModel; @@ -239,6 +246,8 @@ abstract class _$$RequestModelImplCopyWith<$Res> $HttpRequestModelCopyWith<$Res>? get httpRequestModel; @override $HttpResponseModelCopyWith<$Res>? get httpResponseModel; + @override + $AuthModelCopyWith<$Res>? get authModel; } /// @nodoc @@ -266,8 +275,7 @@ class __$$RequestModelImplCopyWithImpl<$Res> Object? httpResponseModel = freezed, Object? isWorking = null, Object? sendingTime = freezed, - Object? preRequestScript = freezed, - Object? postRequestScript = freezed, + Object? authModel = freezed, }) { return _then(_$RequestModelImpl( id: null == id @@ -317,14 +325,10 @@ class __$$RequestModelImplCopyWithImpl<$Res> ? _value.sendingTime : sendingTime // ignore: cast_nullable_to_non_nullable as DateTime?, - preRequestScript: freezed == preRequestScript - ? _value.preRequestScript - : preRequestScript // ignore: cast_nullable_to_non_nullable - as String?, - postRequestScript: freezed == postRequestScript - ? _value.postRequestScript - : postRequestScript // ignore: cast_nullable_to_non_nullable - as String?, + authModel: freezed == authModel + ? _value.authModel + : authModel // ignore: cast_nullable_to_non_nullable + as AuthModel?, )); } } @@ -346,8 +350,7 @@ class _$RequestModelImpl implements _RequestModel { this.httpResponseModel, @JsonKey(includeToJson: false) this.isWorking = false, @JsonKey(includeToJson: false) this.sendingTime, - this.preRequestScript, - this.postRequestScript}); + this.authModel = const AuthModel(type: APIAuthType.none)}); factory _$RequestModelImpl.fromJson(Map json) => _$$RequestModelImplFromJson(json); @@ -384,13 +387,12 @@ class _$RequestModelImpl implements _RequestModel { @JsonKey(includeToJson: false) final DateTime? sendingTime; @override - final String? preRequestScript; - @override - final String? postRequestScript; + @JsonKey() + final AuthModel? authModel; @override String toString() { - return 'RequestModel(id: $id, apiType: $apiType, name: $name, description: $description, authModel: $authModel, requestTabIndex: $requestTabIndex, httpRequestModel: $httpRequestModel, responseStatus: $responseStatus, message: $message, httpResponseModel: $httpResponseModel, isWorking: $isWorking, sendingTime: $sendingTime)'; + return 'RequestModel(id: $id, apiType: $apiType, name: $name, description: $description, requestTabIndex: $requestTabIndex, httpRequestModel: $httpRequestModel, responseStatus: $responseStatus, message: $message, httpResponseModel: $httpResponseModel, isWorking: $isWorking, sendingTime: $sendingTime, authModel: $authModel)'; } @override @@ -418,10 +420,8 @@ class _$RequestModelImpl implements _RequestModel { other.isWorking == isWorking) && (identical(other.sendingTime, sendingTime) || other.sendingTime == sendingTime) && - (identical(other.preRequestScript, preRequestScript) || - other.preRequestScript == preRequestScript) && - (identical(other.postRequestScript, postRequestScript) || - other.postRequestScript == postRequestScript)); + (identical(other.authModel, authModel) || + other.authModel == authModel)); } @JsonKey(includeFromJson: false, includeToJson: false) @@ -440,8 +440,7 @@ class _$RequestModelImpl implements _RequestModel { httpResponseModel, isWorking, sendingTime, - preRequestScript, - postRequestScript); + authModel); /// Create a copy of RequestModel /// with the given fields replaced by the non-null parameter values. @@ -461,19 +460,18 @@ class _$RequestModelImpl implements _RequestModel { abstract class _RequestModel implements RequestModel { const factory _RequestModel( - {required final String id, - final APIType apiType, - final String name, - final String description, - final AuthModel? authModel, - @JsonKey(includeToJson: false) final dynamic requestTabIndex, - final HttpRequestModel? httpRequestModel, - final int? responseStatus, - final String? message, - final HttpResponseModel? httpResponseModel, - @JsonKey(includeToJson: false) final bool isWorking, - @JsonKey(includeToJson: false) final DateTime? sendingTime}) = - _$RequestModelImpl; + {required final String id, + final APIType apiType, + final String name, + final String description, + @JsonKey(includeToJson: false) final dynamic requestTabIndex, + final HttpRequestModel? httpRequestModel, + final int? responseStatus, + final String? message, + final HttpResponseModel? httpResponseModel, + @JsonKey(includeToJson: false) final bool isWorking, + @JsonKey(includeToJson: false) final DateTime? sendingTime, + final AuthModel? authModel}) = _$RequestModelImpl; factory _RequestModel.fromJson(Map json) = _$RequestModelImpl.fromJson; @@ -506,9 +504,7 @@ abstract class _RequestModel implements RequestModel { @JsonKey(includeToJson: false) DateTime? get sendingTime; @override - String? get preRequestScript; - @override - String? get postRequestScript; + AuthModel? get authModel; /// Create a copy of RequestModel /// with the given fields replaced by the non-null parameter values. diff --git a/lib/models/request_model.g.dart b/lib/models/request_model.g.dart index 6c633726..e5a15d1c 100644 --- a/lib/models/request_model.g.dart +++ b/lib/models/request_model.g.dart @@ -31,8 +31,10 @@ _$RequestModelImpl _$$RequestModelImplFromJson(Map json) => _$RequestModelImpl( sendingTime: json['sendingTime'] == null ? null : DateTime.parse(json['sendingTime'] as String), - preRequestScript: json['preRequestScript'] as String?, - postRequestScript: json['postRequestScript'] as String?, + authModel: json['authModel'] == null + ? const AuthModel(type: APIAuthType.none) + : AuthModel.fromJson( + Map.from(json['authModel'] as Map)), ); Map _$$RequestModelImplToJson(_$RequestModelImpl instance) => @@ -46,8 +48,7 @@ Map _$$RequestModelImplToJson(_$RequestModelImpl instance) => 'responseStatus': instance.responseStatus, 'message': instance.message, 'httpResponseModel': instance.httpResponseModel?.toJson(), - 'preRequestScript': instance.preRequestScript, - 'postRequestScript': instance.postRequestScript, + 'authModel': instance.authModel?.toJson(), }; const _$APITypeEnumMap = { diff --git a/lib/providers/collection_providers.dart b/lib/providers/collection_providers.dart index 98e5ddeb..6cf3a7b2 100644 --- a/lib/providers/collection_providers.dart +++ b/lib/providers/collection_providers.dart @@ -239,6 +239,7 @@ class CollectionStateNotifier name: name ?? currentModel.name, description: description ?? currentModel.description, requestTabIndex: requestTabIndex ?? currentModel.requestTabIndex, + authModel: authData ?? currentModel.authModel, httpRequestModel: currentHttpRequestModel?.copyWith( method: method ?? currentHttpRequestModel.method, url: url ?? currentHttpRequestModel.url, @@ -317,6 +318,7 @@ class CollectionStateNotifier requestId, apiType, requestModel.authModel, + requestModel.authModel, substitutedHttpRequestModel, defaultUriScheme: defaultUriScheme, noSSL: noSSL, @@ -343,38 +345,20 @@ class CollectionStateNotifier ); String newHistoryId = getNewUuid(); HistoryRequestModel model = HistoryRequestModel( - historyId: newHistoryId, - metaData: HistoryMetaModel( historyId: newHistoryId, - requestId: requestId, - apiType: requestModel.apiType, - name: requestModel.name, - url: substitutedHttpRequestModel.url, - method: substitutedHttpRequestModel.method, - responseStatus: statusCode, - timeStamp: DateTime.now(), - ), - httpRequestModel: substitutedHttpRequestModel, - httpResponseModel: httpResponseModel, - preRequestScript: requestModel.preRequestScript, - postRequestScript: requestModel.postRequestScript, - ); - - if (!requestModel.postRequestScript.isNullOrEmpty()) { - newRequestModel = await handlePostResponseScript( - newRequestModel, - originalEnvironmentModel, - (envModel, updatedValues) { - ref - .read(environmentsStateNotifierProvider.notifier) - .updateEnvironment( - envModel.id, - name: envModel.name, - values: updatedValues, - ); - }, - ); - } + metaData: HistoryMetaModel( + historyId: newHistoryId, + requestId: requestId, + apiType: requestModel.apiType, + name: requestModel.name, + url: substitutedHttpRequestModel.url, + method: substitutedHttpRequestModel.method, + responseStatus: statusCode, + timeStamp: DateTime.now(), + ), + httpRequestModel: substitutedHttpRequestModel, + httpResponseModel: httpResponseModel, + authModel: requestModel.authModel); ref.read(historyMetaStateNotifier.notifier).addHistoryRequest(model); } diff --git a/lib/screens/history/history_widgets/his_request_pane.dart b/lib/screens/history/history_widgets/his_request_pane.dart index 8ac2bf88..1e361827 100644 --- a/lib/screens/history/history_widgets/his_request_pane.dart +++ b/lib/screens/history/history_widgets/his_request_pane.dart @@ -42,10 +42,10 @@ class HistoryRequestPane extends ConsumerWidget { final hasAuth = ref.watch(selectedHistoryRequestModelProvider.select( (value) => - value?.httpRequestModel.authModel?.type != APIAuthType.none)); + value?.authModel?.type != APIAuthType.none)); final authModel = ref.watch(selectedHistoryRequestModelProvider - .select((value) => value?.httpRequestModel.authModel)); + .select((value) => value?.authModel)); return switch (apiType) { APIType.rest => RequestPane( diff --git a/lib/screens/home_page/editor_pane/details_card/request_pane/request_auth.dart b/lib/screens/home_page/editor_pane/details_card/request_pane/request_auth.dart index 0ef2d12f..dbf4578c 100644 --- a/lib/screens/home_page/editor_pane/details_card/request_pane/request_auth.dart +++ b/lib/screens/home_page/editor_pane/details_card/request_pane/request_auth.dart @@ -34,9 +34,9 @@ class EditAuthType extends ConsumerWidget { currentAuthType = ref.watch( selectedRequestModelProvider.select((request) => - request?.httpRequestModel?.authModel?.type ?? APIAuthType.none), + request?.authModel?.type ?? APIAuthType.none), ); - currentAuthData = selectedRequest.httpRequestModel?.authModel; + currentAuthData = selectedRequest.authModel; } return SingleChildScrollView( child: Padding( @@ -93,7 +93,7 @@ class EditAuthType extends ConsumerWidget { ref.read(selectedRequestModelProvider); if (newType != null) { ref.read(collectionStateNotifierProvider.notifier).update( - authData: selectedRequest?.httpRequestModel?.authModel + authData: selectedRequest?.authModel ?.copyWith(type: newType) ?? AuthModel(type: newType), ); diff --git a/lib/screens/home_page/editor_pane/details_card/request_pane/request_pane_graphql.dart b/lib/screens/home_page/editor_pane/details_card/request_pane/request_pane_graphql.dart index 9510c97b..66b100a2 100644 --- a/lib/screens/home_page/editor_pane/details_card/request_pane/request_pane_graphql.dart +++ b/lib/screens/home_page/editor_pane/details_card/request_pane/request_pane_graphql.dart @@ -26,7 +26,7 @@ class EditGraphQLRequestPane extends ConsumerWidget { false; final hasAuth = ref.watch(selectedRequestModelProvider.select((value) => - value?.httpRequestModel?.authModel?.type != APIAuthType.none)); + value?.authModel?.type != APIAuthType.none)); if (tabIndex >= 3) { tabIndex = 0; diff --git a/lib/screens/home_page/editor_pane/details_card/request_pane/request_pane_rest.dart b/lib/screens/home_page/editor_pane/details_card/request_pane/request_pane_rest.dart index c3177e8b..ee89918b 100644 --- a/lib/screens/home_page/editor_pane/details_card/request_pane/request_pane_rest.dart +++ b/lib/screens/home_page/editor_pane/details_card/request_pane/request_pane_rest.dart @@ -29,9 +29,8 @@ class EditRestRequestPane extends ConsumerWidget { .select((value) => value?.httpRequestModel?.hasBody)) ?? false; - final hasAuth = ref.watch(selectedRequestModelProvider - .select((value) => value?.authModel?.type != APIAuthType.none)); - false; + final hasAuth = ref.watch(selectedRequestModelProvider.select((value) => + value?.authModel?.type != APIAuthType.none)); return RequestPane( selectedId: selectedId, diff --git a/packages/apidash_core/lib/models/http_request_model.g.dart b/packages/apidash_core/lib/models/http_request_model.g.dart new file mode 100644 index 00000000..13795ded --- /dev/null +++ b/packages/apidash_core/lib/models/http_request_model.g.dart @@ -0,0 +1,68 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'http_request_model.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$HttpRequestModelImpl _$$HttpRequestModelImplFromJson(Map json) => + _$HttpRequestModelImpl( + method: $enumDecodeNullable(_$HTTPVerbEnumMap, json['method']) ?? + HTTPVerb.get, + url: json['url'] as String? ?? "", + headers: (json['headers'] as List?) + ?.map((e) => + NameValueModel.fromJson(Map.from(e as Map))) + .toList(), + params: (json['params'] as List?) + ?.map((e) => + NameValueModel.fromJson(Map.from(e as Map))) + .toList(), + isHeaderEnabledList: (json['isHeaderEnabledList'] as List?) + ?.map((e) => e as bool) + .toList(), + isParamEnabledList: (json['isParamEnabledList'] as List?) + ?.map((e) => e as bool) + .toList(), + bodyContentType: + $enumDecodeNullable(_$ContentTypeEnumMap, json['bodyContentType']) ?? + ContentType.json, + body: json['body'] as String?, + query: json['query'] as String?, + formData: (json['formData'] as List?) + ?.map((e) => + FormDataModel.fromJson(Map.from(e as Map))) + .toList(), + ); + +Map _$$HttpRequestModelImplToJson( + _$HttpRequestModelImpl instance) => + { + 'method': _$HTTPVerbEnumMap[instance.method]!, + 'url': instance.url, + 'headers': instance.headers?.map((e) => e.toJson()).toList(), + 'params': instance.params?.map((e) => e.toJson()).toList(), + 'isHeaderEnabledList': instance.isHeaderEnabledList, + 'isParamEnabledList': instance.isParamEnabledList, + 'bodyContentType': _$ContentTypeEnumMap[instance.bodyContentType]!, + 'body': instance.body, + 'query': instance.query, + 'formData': instance.formData?.map((e) => e.toJson()).toList(), + }; + +const _$HTTPVerbEnumMap = { + HTTPVerb.get: 'get', + HTTPVerb.head: 'head', + HTTPVerb.post: 'post', + HTTPVerb.put: 'put', + HTTPVerb.patch: 'patch', + HTTPVerb.delete: 'delete', + HTTPVerb.options: 'options', +}; + +const _$ContentTypeEnumMap = { + ContentType.json: 'json', + ContentType.text: 'text', + ContentType.formdata: 'formdata', +}; diff --git a/packages/apidash_core/lib/utils/handle_auth.dart b/packages/apidash_core/lib/utils/handle_auth.dart index f46c5db8..5cbf7e8f 100644 --- a/packages/apidash_core/lib/utils/handle_auth.dart +++ b/packages/apidash_core/lib/utils/handle_auth.dart @@ -5,9 +5,8 @@ import 'package:apidash_core/models/http_request_model.dart'; import 'package:apidash_core/utils/auth_utils.dart'; import 'package:seed/seed.dart'; -HttpRequestModel handleAuth( - HttpRequestModel httpRequestModel, AuthModel? auth) { - if (auth == null || auth.type == APIAuthType.none) { +HttpRequestModel handleAuth(HttpRequestModel httpRequestModel,AuthModel? authData) { + if (authData == null || authData.type == APIAuthType.none) { return httpRequestModel; } @@ -19,10 +18,10 @@ HttpRequestModel handleAuth( List updatedParamEnabledList = List.from(httpRequestModel.isParamEnabledList ?? []); - switch (auth.type) { + switch (authData.type) { case APIAuthType.basic: - if (auth.basic != null) { - final basicAuth = auth.basic!; + if (authData.basic != null) { + final basicAuth = authData.basic!; final encoded = base64Encode( utf8.encode('${basicAuth.username}:${basicAuth.password}')); updatedHeaders.add( @@ -32,8 +31,8 @@ HttpRequestModel handleAuth( break; case APIAuthType.bearer: - if (auth.bearer != null) { - final bearerAuth = auth.bearer!; + if (authData.bearer != null) { + final bearerAuth = authData.bearer!; updatedHeaders.add(NameValueModel( name: 'Authorization', value: 'Bearer ${bearerAuth.token}')); updatedHeaderEnabledList.add(true); @@ -41,8 +40,8 @@ HttpRequestModel handleAuth( break; case APIAuthType.jwt: - if (auth.jwt != null) { - final jwtAuth = auth.jwt!; + if (authData.jwt != null) { + final jwtAuth = authData.jwt!; // Generate JWT token final jwtToken = generateJWT(jwtAuth); @@ -67,8 +66,8 @@ HttpRequestModel handleAuth( break; case APIAuthType.apiKey: - if (auth.apikey != null) { - final apiKeyAuth = auth.apikey!; + if (authData.apikey != null) { + final apiKeyAuth = authData.apikey!; if (apiKeyAuth.location == 'header') { updatedHeaders.add( NameValueModel(name: apiKeyAuth.name, value: apiKeyAuth.key)); diff --git a/packages/better_networking/lib/models/http_request_model.freezed.dart b/packages/better_networking/lib/models/http_request_model.freezed.dart index 864ae7e0..73ef7423 100644 --- a/packages/better_networking/lib/models/http_request_model.freezed.dart +++ b/packages/better_networking/lib/models/http_request_model.freezed.dart @@ -61,6 +61,17 @@ abstract class $HttpRequestModelCopyWith<$Res> { String? query, List? formData, }); + $Res call( + {HTTPVerb method, + String url, + List? headers, + List? params, + List? isHeaderEnabledList, + List? isParamEnabledList, + ContentType bodyContentType, + String? body, + String? query, + List? formData}); } /// @nodoc @@ -135,6 +146,49 @@ class _$HttpRequestModelCopyWithImpl<$Res, $Val extends HttpRequestModel> as $Val, ); } + return _then(_value.copyWith( + method: null == method + ? _value.method + : method // ignore: cast_nullable_to_non_nullable + as HTTPVerb, + url: null == url + ? _value.url + : url // ignore: cast_nullable_to_non_nullable + as String, + headers: freezed == headers + ? _value.headers + : headers // ignore: cast_nullable_to_non_nullable + as List?, + params: freezed == params + ? _value.params + : params // ignore: cast_nullable_to_non_nullable + as List?, + isHeaderEnabledList: freezed == isHeaderEnabledList + ? _value.isHeaderEnabledList + : isHeaderEnabledList // ignore: cast_nullable_to_non_nullable + as List?, + isParamEnabledList: freezed == isParamEnabledList + ? _value.isParamEnabledList + : isParamEnabledList // ignore: cast_nullable_to_non_nullable + as List?, + bodyContentType: null == bodyContentType + ? _value.bodyContentType + : bodyContentType // ignore: cast_nullable_to_non_nullable + as ContentType, + body: freezed == body + ? _value.body + : body // ignore: cast_nullable_to_non_nullable + as String?, + query: freezed == query + ? _value.query + : query // ignore: cast_nullable_to_non_nullable + as String?, + formData: freezed == formData + ? _value.formData + : formData // ignore: cast_nullable_to_non_nullable + as List?, + ) as $Val); + } } /// @nodoc @@ -158,6 +212,17 @@ abstract class _$$HttpRequestModelImplCopyWith<$Res> String? query, List? formData, }); + $Res call( + {HTTPVerb method, + String url, + List? headers, + List? params, + List? isHeaderEnabledList, + List? isParamEnabledList, + ContentType bodyContentType, + String? body, + String? query, + List? formData}); } /// @nodoc @@ -229,6 +294,48 @@ class __$$HttpRequestModelImplCopyWithImpl<$Res> as List?, ), ); + return _then(_$HttpRequestModelImpl( + method: null == method + ? _value.method + : method // ignore: cast_nullable_to_non_nullable + as HTTPVerb, + url: null == url + ? _value.url + : url // ignore: cast_nullable_to_non_nullable + as String, + headers: freezed == headers + ? _value._headers + : headers // ignore: cast_nullable_to_non_nullable + as List?, + params: freezed == params + ? _value._params + : params // ignore: cast_nullable_to_non_nullable + as List?, + isHeaderEnabledList: freezed == isHeaderEnabledList + ? _value._isHeaderEnabledList + : isHeaderEnabledList // ignore: cast_nullable_to_non_nullable + as List?, + isParamEnabledList: freezed == isParamEnabledList + ? _value._isParamEnabledList + : isParamEnabledList // ignore: cast_nullable_to_non_nullable + as List?, + bodyContentType: null == bodyContentType + ? _value.bodyContentType + : bodyContentType // ignore: cast_nullable_to_non_nullable + as ContentType, + body: freezed == body + ? _value.body + : body // ignore: cast_nullable_to_non_nullable + as String?, + query: freezed == query + ? _value.query + : query // ignore: cast_nullable_to_non_nullable + as String?, + formData: freezed == formData + ? _value._formData + : formData // ignore: cast_nullable_to_non_nullable + as List?, + )); } } @@ -253,6 +360,23 @@ class _$HttpRequestModelImpl extends _HttpRequestModel { _isParamEnabledList = isParamEnabledList, _formData = formData, super._(); + const _$HttpRequestModelImpl( + {this.method = HTTPVerb.get, + this.url = "", + final List? headers, + final List? params, + final List? isHeaderEnabledList, + final List? isParamEnabledList, + this.bodyContentType = ContentType.json, + this.body, + this.query, + final List? formData}) + : _headers = headers, + _params = params, + _isHeaderEnabledList = isHeaderEnabledList, + _isParamEnabledList = isParamEnabledList, + _formData = formData, + super._(); factory _$HttpRequestModelImpl.fromJson(Map json) => _$$HttpRequestModelImplFromJson(json); @@ -325,6 +449,7 @@ class _$HttpRequestModelImpl extends _HttpRequestModel { @override String toString() { return 'HttpRequestModel(method: $method, url: $url, headers: $headers, params: $params, isHeaderEnabledList: $isHeaderEnabledList, isParamEnabledList: $isParamEnabledList, bodyContentType: $bodyContentType, body: $body, query: $query, formData: $formData)'; + return 'HttpRequestModel(method: $method, url: $url, headers: $headers, params: $params, isHeaderEnabledList: $isHeaderEnabledList, isParamEnabledList: $isParamEnabledList, bodyContentType: $bodyContentType, body: $body, query: $query, formData: $formData)'; } @override @@ -344,6 +469,10 @@ class _$HttpRequestModelImpl extends _HttpRequestModel { other._isParamEnabledList, _isParamEnabledList, ) && + const DeepCollectionEquality() + .equals(other._isHeaderEnabledList, _isHeaderEnabledList) && + const DeepCollectionEquality() + .equals(other._isParamEnabledList, _isParamEnabledList) && (identical(other.bodyContentType, bodyContentType) || other.bodyContentType == bodyContentType) && (identical(other.body, body) || other.body == body) && @@ -366,6 +495,17 @@ class _$HttpRequestModelImpl extends _HttpRequestModel { query, const DeepCollectionEquality().hash(_formData), ); + runtimeType, + method, + url, + const DeepCollectionEquality().hash(_headers), + const DeepCollectionEquality().hash(_params), + const DeepCollectionEquality().hash(_isHeaderEnabledList), + const DeepCollectionEquality().hash(_isParamEnabledList), + bodyContentType, + body, + query, + const DeepCollectionEquality().hash(_formData)); /// Create a copy of HttpRequestModel /// with the given fields replaced by the non-null parameter values. @@ -397,6 +537,17 @@ abstract class _HttpRequestModel extends HttpRequestModel { final String? query, final List? formData, }) = _$HttpRequestModelImpl; + const factory _HttpRequestModel( + {final HTTPVerb method, + final String url, + final List? headers, + final List? params, + final List? isHeaderEnabledList, + final List? isParamEnabledList, + final ContentType bodyContentType, + final String? body, + final String? query, + final List? formData}) = _$HttpRequestModelImpl; const _HttpRequestModel._() : super._(); factory _HttpRequestModel.fromJson(Map json) = diff --git a/packages/better_networking/lib/services/http_service.dart b/packages/better_networking/lib/services/http_service.dart index 62478b71..047d83af 100644 --- a/packages/better_networking/lib/services/http_service.dart +++ b/packages/better_networking/lib/services/http_service.dart @@ -17,7 +17,7 @@ final httpClientManager = HttpClientManager(); Future<(HttpResponse?, Duration?, String?)> sendHttpRequest( String requestId, APIType apiType, - AuthModel? authModel, + AuthModel? authData, HttpRequestModel requestModel, { SupportedUriSchemes defaultUriScheme = kDefaultUriScheme, bool noSSL = false, @@ -28,7 +28,11 @@ Future<(HttpResponse?, Duration?, String?)> sendHttpRequest( final client = httpClientManager.createClient(requestId, noSSL: noSSL); // Handle authentication +<<<<<<< HEAD:packages/better_networking/lib/services/http_service.dart final authenticatedRequestModel = handleAuth(requestModel, authModel); +======= + final authenticatedRequestModel = handleAuth(requestModel, authData); +>>>>>>> f24eb4e6 (feat: remove AuthModel from HttpRequestModel and integrate into HistoryRequestModel and RequestModel):packages/apidash_core/lib/services/http_service.dart (Uri?, String?) uriRec = getValidRequestUri( authenticatedRequestModel.url, diff --git a/pubspec.lock b/pubspec.lock index 97ee4871..d73a53ca 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -710,7 +710,7 @@ packages: source: path version: "0.0.1" highlight: - dependency: "direct main" + dependency: transitive description: name: highlight sha256: "5353a83ffe3e3eca7df0abfb72dcf3fa66cc56b953728e7113ad4ad88497cf21"