mirror of
https://github.com/foss42/apidash.git
synced 2025-12-01 10:17:47 +08:00
feat: remove AuthModel from HttpRequestModel and integrate into HistoryRequestModel and RequestModel
This commit is contained in:
68
packages/apidash_core/lib/models/http_request_model.g.dart
Normal file
68
packages/apidash_core/lib/models/http_request_model.g.dart
Normal file
@@ -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<dynamic>?)
|
||||
?.map((e) =>
|
||||
NameValueModel.fromJson(Map<String, Object?>.from(e as Map)))
|
||||
.toList(),
|
||||
params: (json['params'] as List<dynamic>?)
|
||||
?.map((e) =>
|
||||
NameValueModel.fromJson(Map<String, Object?>.from(e as Map)))
|
||||
.toList(),
|
||||
isHeaderEnabledList: (json['isHeaderEnabledList'] as List<dynamic>?)
|
||||
?.map((e) => e as bool)
|
||||
.toList(),
|
||||
isParamEnabledList: (json['isParamEnabledList'] as List<dynamic>?)
|
||||
?.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<dynamic>?)
|
||||
?.map((e) =>
|
||||
FormDataModel.fromJson(Map<String, Object?>.from(e as Map)))
|
||||
.toList(),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$HttpRequestModelImplToJson(
|
||||
_$HttpRequestModelImpl instance) =>
|
||||
<String, dynamic>{
|
||||
'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',
|
||||
};
|
||||
@@ -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<bool> 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));
|
||||
|
||||
Reference in New Issue
Block a user