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 94670580..8a5e8534 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 @@ -22,44 +22,51 @@ class EditAuthType extends ConsumerWidget { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - // Auth Type Dropdown + Text( + "Authentication Type", + style: TextStyle( + fontWeight: FontWeight.bold, + ), + ), + SizedBox( + height: 8, + ), DropdownButtonFormField( value: currentAuthType, - decoration: const InputDecoration( - labelText: 'Authentication Type', - border: OutlineInputBorder(), + elevation: 4, + decoration: InputDecoration( + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(9), + ), ), items: APIAuthType.values.map((type) { return DropdownMenuItem( value: type, - child: Text(type.name), + child: Text(type.name.capitalize()), ); }).toList(), onChanged: (APIAuthType? newType) { if (newType != null) { ref.read(collectionStateNotifierProvider.notifier).update( authType: newType, - authData: null, // reset when auth type changes + authData: null, ); } }, ), - const SizedBox(height: 16), - - // Dynamic Auth Input Fields - _buildAuthFields(ref, currentAuthType, currentAuthData), + const SizedBox(height: 48), + _buildAuthFields(context, ref, currentAuthType, currentAuthData), ], ), ); } Widget _buildAuthFields( + BuildContext context, WidgetRef ref, APIAuthType authType, APIAuthModel? authData, ) { - final controllerMap = {}; - void updateAuth(APIAuthModel model) { ref.read(collectionStateNotifierProvider.notifier).update( authData: model, @@ -75,17 +82,59 @@ class EditAuthType extends ConsumerWidget { text: (authData is BasicAuth) ? authData.password : '', ); return Column( + crossAxisAlignment: CrossAxisAlignment.start, children: [ + Text( + "Username", + style: TextStyle( + fontWeight: FontWeight.bold, + ), + ), + SizedBox( + height: 4, + ), TextField( controller: usernameController, - decoration: const InputDecoration(labelText: 'Username'), - onChanged: (value) => updateAuth(BasicAuth( - username: value, password: passwordController.text)), + decoration: InputDecoration( + constraints: BoxConstraints( + maxWidth: MediaQuery.sizeOf(context).width - 100, + ), + contentPadding: const EdgeInsets.all(18), + hintText: "Username", + hintStyle: Theme.of(context).textTheme.bodyMedium, + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(8), + ), + ), + onChanged: (value) => updateAuth( + BasicAuth(username: value, password: passwordController.text), + ), + ), + SizedBox( + height: 16, + ), + Text( + "Password", + style: TextStyle( + fontWeight: FontWeight.bold, + ), + ), + SizedBox( + height: 4, ), - const SizedBox(height: 8), TextField( controller: passwordController, - decoration: const InputDecoration(labelText: 'Password'), + decoration: InputDecoration( + constraints: BoxConstraints( + maxWidth: MediaQuery.sizeOf(context).width - 100, + ), + contentPadding: const EdgeInsets.all(18), + hintText: "Password", + hintStyle: Theme.of(context).textTheme.bodyMedium, + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(8), + ), + ), obscureText: true, onChanged: (value) => updateAuth(BasicAuth( username: usernameController.text, password: value)), @@ -93,7 +142,187 @@ class EditAuthType extends ConsumerWidget { ], ); - // + case APIAuthType.bearerToken: + final tokenController = TextEditingController( + text: (authData is BearerTokenAuth) ? authData.token : '', + ); + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + "Token", + style: TextStyle( + fontWeight: FontWeight.bold, + ), + ), + SizedBox( + height: 4, + ), + TextField( + controller: tokenController, + decoration: InputDecoration( + constraints: BoxConstraints( + maxWidth: MediaQuery.sizeOf(context).width - 100, + ), + contentPadding: const EdgeInsets.all(18), + hintText: "Token", + hintStyle: Theme.of(context).textTheme.bodyMedium, + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(8), + ), + ), + onChanged: (value) => updateAuth(BearerTokenAuth(token: value)), + ), + ], + ); + + case APIAuthType.apiKey: + final keyController = TextEditingController( + text: (authData is APIKeyAuth) ? authData.key : '', + ); + final nameController = TextEditingController( + text: (authData is APIKeyAuth) ? authData.name : 'x-api-key', + ); + final currentLocation = + (authData is APIKeyAuth) ? authData.location : 'header'; + + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + "Add to", + style: TextStyle( + fontWeight: FontWeight.bold, + ), + ), + SizedBox( + height: 4, + ), + DropdownButtonFormField( + value: currentLocation, + decoration: InputDecoration( + constraints: BoxConstraints( + maxWidth: MediaQuery.sizeOf(context).width - 100, + ), + contentPadding: const EdgeInsets.all(18), + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(8), + ), + ), + items: [ + DropdownMenuItem( + value: 'header', + child: Text('Header'), + ), + DropdownMenuItem( + value: 'query', + child: Text('Query Params'), + ), + ], + onChanged: (String? newLocation) { + if (newLocation != null) { + updateAuth(APIKeyAuth( + key: keyController.text, + name: nameController.text, + location: newLocation, + )); + } + }, + ), + const SizedBox(height: 16), + Text( + "Header/Query Param Name", + style: TextStyle( + fontWeight: FontWeight.bold, + ), + ), + SizedBox( + height: 4, + ), + TextField( + controller: nameController, + decoration: InputDecoration( + constraints: BoxConstraints( + maxWidth: MediaQuery.sizeOf(context).width - 100, + ), + contentPadding: const EdgeInsets.all(18), + hintText: "Header/Query Param Name", + hintStyle: Theme.of(context).textTheme.bodyMedium, + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(8), + ), + ), + onChanged: (value) => updateAuth(APIKeyAuth( + key: keyController.text, + name: value, + location: currentLocation, + )), + ), + const SizedBox(height: 16), + Text( + "API Key", + style: TextStyle( + fontWeight: FontWeight.bold, + ), + ), + SizedBox( + height: 4, + ), + TextField( + controller: keyController, + decoration: InputDecoration( + constraints: BoxConstraints( + maxWidth: MediaQuery.sizeOf(context).width - 100, + ), + contentPadding: const EdgeInsets.all(18), + hintText: "API Key", + hintStyle: Theme.of(context).textTheme.bodyMedium, + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(8), + ), + ), + onChanged: (value) => updateAuth(APIKeyAuth( + key: value, + name: nameController.text, + location: currentLocation, + )), + ), + ], + ); + + case APIAuthType.jwtBearer: + final jwtController = TextEditingController( + text: (authData is JWTBearerAuth) ? authData.jwt : '', + ); + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + "JWT Token", + style: TextStyle( + fontWeight: FontWeight.bold, + ), + ), + SizedBox( + height: 4, + ), + TextField( + controller: jwtController, + decoration: InputDecoration( + constraints: BoxConstraints( + maxWidth: MediaQuery.sizeOf(context).width - 100, + ), + contentPadding: const EdgeInsets.all(18), + hintText: "JWT Token", + hintStyle: Theme.of(context).textTheme.bodyMedium, + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(8), + ), + ), + onChanged: (value) => updateAuth(JWTBearerAuth(jwt: value)), + ), + ], + ); case APIAuthType.none: return const Text("No authentication selected."); diff --git a/packages/apidash_core/lib/models/api_auth_model.dart b/packages/apidash_core/lib/models/api_auth_model.dart index 6a3449a1..3765939e 100644 --- a/packages/apidash_core/lib/models/api_auth_model.dart +++ b/packages/apidash_core/lib/models/api_auth_model.dart @@ -14,4 +14,18 @@ class APIAuthModel with _$APIAuthModel { factory APIAuthModel.fromJson(Map json) => _$APIAuthModelFromJson(json); + + const factory APIAuthModel.bearerToken({ + required String token, + }) = BearerTokenAuth; + + const factory APIAuthModel.apiKey({ + required String key, + @Default('header') String location, // or 'query' + @Default('x-api-key') String name, + }) = APIKeyAuth; + + const factory APIAuthModel.jwtBearer({ + required String jwt, + }) = JWTBearerAuth; } diff --git a/packages/apidash_core/lib/models/api_auth_model.freezed.dart b/packages/apidash_core/lib/models/api_auth_model.freezed.dart index c7cc47e6..68b24d48 100644 --- a/packages/apidash_core/lib/models/api_auth_model.freezed.dart +++ b/packages/apidash_core/lib/models/api_auth_model.freezed.dart @@ -20,6 +20,12 @@ APIAuthModel _$APIAuthModelFromJson(Map json) { return None.fromJson(json); case 'basic': return BasicAuth.fromJson(json); + case 'bearerToken': + return BearerTokenAuth.fromJson(json); + case 'apiKey': + return APIKeyAuth.fromJson(json); + case 'jwtBearer': + return JWTBearerAuth.fromJson(json); default: throw CheckedFromJsonException(json, 'runtimeType', 'APIAuthModel', @@ -33,18 +39,27 @@ mixin _$APIAuthModel { TResult when({ required TResult Function() none, required TResult Function(String username, String password) basic, + required TResult Function(String token) bearerToken, + required TResult Function(String key, String location, String name) apiKey, + required TResult Function(String jwt) jwtBearer, }) => throw _privateConstructorUsedError; @optionalTypeArgs TResult? whenOrNull({ TResult? Function()? none, TResult? Function(String username, String password)? basic, + TResult? Function(String token)? bearerToken, + TResult? Function(String key, String location, String name)? apiKey, + TResult? Function(String jwt)? jwtBearer, }) => throw _privateConstructorUsedError; @optionalTypeArgs TResult maybeWhen({ TResult Function()? none, TResult Function(String username, String password)? basic, + TResult Function(String token)? bearerToken, + TResult Function(String key, String location, String name)? apiKey, + TResult Function(String jwt)? jwtBearer, required TResult orElse(), }) => throw _privateConstructorUsedError; @@ -52,18 +67,27 @@ mixin _$APIAuthModel { TResult map({ required TResult Function(None value) none, required TResult Function(BasicAuth value) basic, + required TResult Function(BearerTokenAuth value) bearerToken, + required TResult Function(APIKeyAuth value) apiKey, + required TResult Function(JWTBearerAuth value) jwtBearer, }) => throw _privateConstructorUsedError; @optionalTypeArgs TResult? mapOrNull({ TResult? Function(None value)? none, TResult? Function(BasicAuth value)? basic, + TResult? Function(BearerTokenAuth value)? bearerToken, + TResult? Function(APIKeyAuth value)? apiKey, + TResult? Function(JWTBearerAuth value)? jwtBearer, }) => throw _privateConstructorUsedError; @optionalTypeArgs TResult maybeMap({ TResult Function(None value)? none, TResult Function(BasicAuth value)? basic, + TResult Function(BearerTokenAuth value)? bearerToken, + TResult Function(APIKeyAuth value)? apiKey, + TResult Function(JWTBearerAuth value)? jwtBearer, required TResult orElse(), }) => throw _privateConstructorUsedError; @@ -142,6 +166,9 @@ class _$NoneImpl implements None { TResult when({ required TResult Function() none, required TResult Function(String username, String password) basic, + required TResult Function(String token) bearerToken, + required TResult Function(String key, String location, String name) apiKey, + required TResult Function(String jwt) jwtBearer, }) { return none(); } @@ -151,6 +178,9 @@ class _$NoneImpl implements None { TResult? whenOrNull({ TResult? Function()? none, TResult? Function(String username, String password)? basic, + TResult? Function(String token)? bearerToken, + TResult? Function(String key, String location, String name)? apiKey, + TResult? Function(String jwt)? jwtBearer, }) { return none?.call(); } @@ -160,6 +190,9 @@ class _$NoneImpl implements None { TResult maybeWhen({ TResult Function()? none, TResult Function(String username, String password)? basic, + TResult Function(String token)? bearerToken, + TResult Function(String key, String location, String name)? apiKey, + TResult Function(String jwt)? jwtBearer, required TResult orElse(), }) { if (none != null) { @@ -173,6 +206,9 @@ class _$NoneImpl implements None { TResult map({ required TResult Function(None value) none, required TResult Function(BasicAuth value) basic, + required TResult Function(BearerTokenAuth value) bearerToken, + required TResult Function(APIKeyAuth value) apiKey, + required TResult Function(JWTBearerAuth value) jwtBearer, }) { return none(this); } @@ -182,6 +218,9 @@ class _$NoneImpl implements None { TResult? mapOrNull({ TResult? Function(None value)? none, TResult? Function(BasicAuth value)? basic, + TResult? Function(BearerTokenAuth value)? bearerToken, + TResult? Function(APIKeyAuth value)? apiKey, + TResult? Function(JWTBearerAuth value)? jwtBearer, }) { return none?.call(this); } @@ -191,6 +230,9 @@ class _$NoneImpl implements None { TResult maybeMap({ TResult Function(None value)? none, TResult Function(BasicAuth value)? basic, + TResult Function(BearerTokenAuth value)? bearerToken, + TResult Function(APIKeyAuth value)? apiKey, + TResult Function(JWTBearerAuth value)? jwtBearer, required TResult orElse(), }) { if (none != null) { @@ -302,6 +344,9 @@ class _$BasicAuthImpl implements BasicAuth { TResult when({ required TResult Function() none, required TResult Function(String username, String password) basic, + required TResult Function(String token) bearerToken, + required TResult Function(String key, String location, String name) apiKey, + required TResult Function(String jwt) jwtBearer, }) { return basic(username, password); } @@ -311,6 +356,9 @@ class _$BasicAuthImpl implements BasicAuth { TResult? whenOrNull({ TResult? Function()? none, TResult? Function(String username, String password)? basic, + TResult? Function(String token)? bearerToken, + TResult? Function(String key, String location, String name)? apiKey, + TResult? Function(String jwt)? jwtBearer, }) { return basic?.call(username, password); } @@ -320,6 +368,9 @@ class _$BasicAuthImpl implements BasicAuth { TResult maybeWhen({ TResult Function()? none, TResult Function(String username, String password)? basic, + TResult Function(String token)? bearerToken, + TResult Function(String key, String location, String name)? apiKey, + TResult Function(String jwt)? jwtBearer, required TResult orElse(), }) { if (basic != null) { @@ -333,6 +384,9 @@ class _$BasicAuthImpl implements BasicAuth { TResult map({ required TResult Function(None value) none, required TResult Function(BasicAuth value) basic, + required TResult Function(BearerTokenAuth value) bearerToken, + required TResult Function(APIKeyAuth value) apiKey, + required TResult Function(JWTBearerAuth value) jwtBearer, }) { return basic(this); } @@ -342,6 +396,9 @@ class _$BasicAuthImpl implements BasicAuth { TResult? mapOrNull({ TResult? Function(None value)? none, TResult? Function(BasicAuth value)? basic, + TResult? Function(BearerTokenAuth value)? bearerToken, + TResult? Function(APIKeyAuth value)? apiKey, + TResult? Function(JWTBearerAuth value)? jwtBearer, }) { return basic?.call(this); } @@ -351,6 +408,9 @@ class _$BasicAuthImpl implements BasicAuth { TResult maybeMap({ TResult Function(None value)? none, TResult Function(BasicAuth value)? basic, + TResult Function(BearerTokenAuth value)? bearerToken, + TResult Function(APIKeyAuth value)? apiKey, + TResult Function(JWTBearerAuth value)? jwtBearer, required TResult orElse(), }) { if (basic != null) { @@ -384,3 +444,563 @@ abstract class BasicAuth implements APIAuthModel { _$$BasicAuthImplCopyWith<_$BasicAuthImpl> get copyWith => throw _privateConstructorUsedError; } + +/// @nodoc +abstract class _$$BearerTokenAuthImplCopyWith<$Res> { + factory _$$BearerTokenAuthImplCopyWith(_$BearerTokenAuthImpl value, + $Res Function(_$BearerTokenAuthImpl) then) = + __$$BearerTokenAuthImplCopyWithImpl<$Res>; + @useResult + $Res call({String token}); +} + +/// @nodoc +class __$$BearerTokenAuthImplCopyWithImpl<$Res> + extends _$APIAuthModelCopyWithImpl<$Res, _$BearerTokenAuthImpl> + implements _$$BearerTokenAuthImplCopyWith<$Res> { + __$$BearerTokenAuthImplCopyWithImpl( + _$BearerTokenAuthImpl _value, $Res Function(_$BearerTokenAuthImpl) _then) + : super(_value, _then); + + /// Create a copy of APIAuthModel + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? token = null, + }) { + return _then(_$BearerTokenAuthImpl( + token: null == token + ? _value.token + : token // ignore: cast_nullable_to_non_nullable + as String, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$BearerTokenAuthImpl implements BearerTokenAuth { + const _$BearerTokenAuthImpl({required this.token, final String? $type}) + : $type = $type ?? 'bearerToken'; + + factory _$BearerTokenAuthImpl.fromJson(Map json) => + _$$BearerTokenAuthImplFromJson(json); + + @override + final String token; + + @JsonKey(name: 'runtimeType') + final String $type; + + @override + String toString() { + return 'APIAuthModel.bearerToken(token: $token)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$BearerTokenAuthImpl && + (identical(other.token, token) || other.token == token)); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => Object.hash(runtimeType, token); + + /// Create a copy of APIAuthModel + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$BearerTokenAuthImplCopyWith<_$BearerTokenAuthImpl> get copyWith => + __$$BearerTokenAuthImplCopyWithImpl<_$BearerTokenAuthImpl>( + this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() none, + required TResult Function(String username, String password) basic, + required TResult Function(String token) bearerToken, + required TResult Function(String key, String location, String name) apiKey, + required TResult Function(String jwt) jwtBearer, + }) { + return bearerToken(token); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function()? none, + TResult? Function(String username, String password)? basic, + TResult? Function(String token)? bearerToken, + TResult? Function(String key, String location, String name)? apiKey, + TResult? Function(String jwt)? jwtBearer, + }) { + return bearerToken?.call(token); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? none, + TResult Function(String username, String password)? basic, + TResult Function(String token)? bearerToken, + TResult Function(String key, String location, String name)? apiKey, + TResult Function(String jwt)? jwtBearer, + required TResult orElse(), + }) { + if (bearerToken != null) { + return bearerToken(token); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(None value) none, + required TResult Function(BasicAuth value) basic, + required TResult Function(BearerTokenAuth value) bearerToken, + required TResult Function(APIKeyAuth value) apiKey, + required TResult Function(JWTBearerAuth value) jwtBearer, + }) { + return bearerToken(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(None value)? none, + TResult? Function(BasicAuth value)? basic, + TResult? Function(BearerTokenAuth value)? bearerToken, + TResult? Function(APIKeyAuth value)? apiKey, + TResult? Function(JWTBearerAuth value)? jwtBearer, + }) { + return bearerToken?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(None value)? none, + TResult Function(BasicAuth value)? basic, + TResult Function(BearerTokenAuth value)? bearerToken, + TResult Function(APIKeyAuth value)? apiKey, + TResult Function(JWTBearerAuth value)? jwtBearer, + required TResult orElse(), + }) { + if (bearerToken != null) { + return bearerToken(this); + } + return orElse(); + } + + @override + Map toJson() { + return _$$BearerTokenAuthImplToJson( + this, + ); + } +} + +abstract class BearerTokenAuth implements APIAuthModel { + const factory BearerTokenAuth({required final String token}) = + _$BearerTokenAuthImpl; + + factory BearerTokenAuth.fromJson(Map json) = + _$BearerTokenAuthImpl.fromJson; + + String get token; + + /// Create a copy of APIAuthModel + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + _$$BearerTokenAuthImplCopyWith<_$BearerTokenAuthImpl> get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class _$$APIKeyAuthImplCopyWith<$Res> { + factory _$$APIKeyAuthImplCopyWith( + _$APIKeyAuthImpl value, $Res Function(_$APIKeyAuthImpl) then) = + __$$APIKeyAuthImplCopyWithImpl<$Res>; + @useResult + $Res call({String key, String location, String name}); +} + +/// @nodoc +class __$$APIKeyAuthImplCopyWithImpl<$Res> + extends _$APIAuthModelCopyWithImpl<$Res, _$APIKeyAuthImpl> + implements _$$APIKeyAuthImplCopyWith<$Res> { + __$$APIKeyAuthImplCopyWithImpl( + _$APIKeyAuthImpl _value, $Res Function(_$APIKeyAuthImpl) _then) + : super(_value, _then); + + /// Create a copy of APIAuthModel + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? key = null, + Object? location = null, + Object? name = null, + }) { + return _then(_$APIKeyAuthImpl( + key: null == key + ? _value.key + : key // ignore: cast_nullable_to_non_nullable + as String, + location: null == location + ? _value.location + : location // ignore: cast_nullable_to_non_nullable + as String, + name: null == name + ? _value.name + : name // ignore: cast_nullable_to_non_nullable + as String, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$APIKeyAuthImpl implements APIKeyAuth { + const _$APIKeyAuthImpl( + {required this.key, + this.location = 'header', + this.name = 'x-api-key', + final String? $type}) + : $type = $type ?? 'apiKey'; + + factory _$APIKeyAuthImpl.fromJson(Map json) => + _$$APIKeyAuthImplFromJson(json); + + @override + final String key; + @override + @JsonKey() + final String location; +// or 'query' + @override + @JsonKey() + final String name; + + @JsonKey(name: 'runtimeType') + final String $type; + + @override + String toString() { + return 'APIAuthModel.apiKey(key: $key, location: $location, name: $name)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$APIKeyAuthImpl && + (identical(other.key, key) || other.key == key) && + (identical(other.location, location) || + other.location == location) && + (identical(other.name, name) || other.name == name)); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => Object.hash(runtimeType, key, location, name); + + /// Create a copy of APIAuthModel + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$APIKeyAuthImplCopyWith<_$APIKeyAuthImpl> get copyWith => + __$$APIKeyAuthImplCopyWithImpl<_$APIKeyAuthImpl>(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() none, + required TResult Function(String username, String password) basic, + required TResult Function(String token) bearerToken, + required TResult Function(String key, String location, String name) apiKey, + required TResult Function(String jwt) jwtBearer, + }) { + return apiKey(key, location, name); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function()? none, + TResult? Function(String username, String password)? basic, + TResult? Function(String token)? bearerToken, + TResult? Function(String key, String location, String name)? apiKey, + TResult? Function(String jwt)? jwtBearer, + }) { + return apiKey?.call(key, location, name); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? none, + TResult Function(String username, String password)? basic, + TResult Function(String token)? bearerToken, + TResult Function(String key, String location, String name)? apiKey, + TResult Function(String jwt)? jwtBearer, + required TResult orElse(), + }) { + if (apiKey != null) { + return apiKey(key, location, name); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(None value) none, + required TResult Function(BasicAuth value) basic, + required TResult Function(BearerTokenAuth value) bearerToken, + required TResult Function(APIKeyAuth value) apiKey, + required TResult Function(JWTBearerAuth value) jwtBearer, + }) { + return apiKey(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(None value)? none, + TResult? Function(BasicAuth value)? basic, + TResult? Function(BearerTokenAuth value)? bearerToken, + TResult? Function(APIKeyAuth value)? apiKey, + TResult? Function(JWTBearerAuth value)? jwtBearer, + }) { + return apiKey?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(None value)? none, + TResult Function(BasicAuth value)? basic, + TResult Function(BearerTokenAuth value)? bearerToken, + TResult Function(APIKeyAuth value)? apiKey, + TResult Function(JWTBearerAuth value)? jwtBearer, + required TResult orElse(), + }) { + if (apiKey != null) { + return apiKey(this); + } + return orElse(); + } + + @override + Map toJson() { + return _$$APIKeyAuthImplToJson( + this, + ); + } +} + +abstract class APIKeyAuth implements APIAuthModel { + const factory APIKeyAuth( + {required final String key, + final String location, + final String name}) = _$APIKeyAuthImpl; + + factory APIKeyAuth.fromJson(Map json) = + _$APIKeyAuthImpl.fromJson; + + String get key; + String get location; // or 'query' + String get name; + + /// Create a copy of APIAuthModel + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + _$$APIKeyAuthImplCopyWith<_$APIKeyAuthImpl> get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class _$$JWTBearerAuthImplCopyWith<$Res> { + factory _$$JWTBearerAuthImplCopyWith( + _$JWTBearerAuthImpl value, $Res Function(_$JWTBearerAuthImpl) then) = + __$$JWTBearerAuthImplCopyWithImpl<$Res>; + @useResult + $Res call({String jwt}); +} + +/// @nodoc +class __$$JWTBearerAuthImplCopyWithImpl<$Res> + extends _$APIAuthModelCopyWithImpl<$Res, _$JWTBearerAuthImpl> + implements _$$JWTBearerAuthImplCopyWith<$Res> { + __$$JWTBearerAuthImplCopyWithImpl( + _$JWTBearerAuthImpl _value, $Res Function(_$JWTBearerAuthImpl) _then) + : super(_value, _then); + + /// Create a copy of APIAuthModel + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? jwt = null, + }) { + return _then(_$JWTBearerAuthImpl( + jwt: null == jwt + ? _value.jwt + : jwt // ignore: cast_nullable_to_non_nullable + as String, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$JWTBearerAuthImpl implements JWTBearerAuth { + const _$JWTBearerAuthImpl({required this.jwt, final String? $type}) + : $type = $type ?? 'jwtBearer'; + + factory _$JWTBearerAuthImpl.fromJson(Map json) => + _$$JWTBearerAuthImplFromJson(json); + + @override + final String jwt; + + @JsonKey(name: 'runtimeType') + final String $type; + + @override + String toString() { + return 'APIAuthModel.jwtBearer(jwt: $jwt)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$JWTBearerAuthImpl && + (identical(other.jwt, jwt) || other.jwt == jwt)); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => Object.hash(runtimeType, jwt); + + /// Create a copy of APIAuthModel + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$JWTBearerAuthImplCopyWith<_$JWTBearerAuthImpl> get copyWith => + __$$JWTBearerAuthImplCopyWithImpl<_$JWTBearerAuthImpl>(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() none, + required TResult Function(String username, String password) basic, + required TResult Function(String token) bearerToken, + required TResult Function(String key, String location, String name) apiKey, + required TResult Function(String jwt) jwtBearer, + }) { + return jwtBearer(jwt); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function()? none, + TResult? Function(String username, String password)? basic, + TResult? Function(String token)? bearerToken, + TResult? Function(String key, String location, String name)? apiKey, + TResult? Function(String jwt)? jwtBearer, + }) { + return jwtBearer?.call(jwt); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? none, + TResult Function(String username, String password)? basic, + TResult Function(String token)? bearerToken, + TResult Function(String key, String location, String name)? apiKey, + TResult Function(String jwt)? jwtBearer, + required TResult orElse(), + }) { + if (jwtBearer != null) { + return jwtBearer(jwt); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(None value) none, + required TResult Function(BasicAuth value) basic, + required TResult Function(BearerTokenAuth value) bearerToken, + required TResult Function(APIKeyAuth value) apiKey, + required TResult Function(JWTBearerAuth value) jwtBearer, + }) { + return jwtBearer(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(None value)? none, + TResult? Function(BasicAuth value)? basic, + TResult? Function(BearerTokenAuth value)? bearerToken, + TResult? Function(APIKeyAuth value)? apiKey, + TResult? Function(JWTBearerAuth value)? jwtBearer, + }) { + return jwtBearer?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(None value)? none, + TResult Function(BasicAuth value)? basic, + TResult Function(BearerTokenAuth value)? bearerToken, + TResult Function(APIKeyAuth value)? apiKey, + TResult Function(JWTBearerAuth value)? jwtBearer, + required TResult orElse(), + }) { + if (jwtBearer != null) { + return jwtBearer(this); + } + return orElse(); + } + + @override + Map toJson() { + return _$$JWTBearerAuthImplToJson( + this, + ); + } +} + +abstract class JWTBearerAuth implements APIAuthModel { + const factory JWTBearerAuth({required final String jwt}) = + _$JWTBearerAuthImpl; + + factory JWTBearerAuth.fromJson(Map json) = + _$JWTBearerAuthImpl.fromJson; + + String get jwt; + + /// Create a copy of APIAuthModel + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + _$$JWTBearerAuthImplCopyWith<_$JWTBearerAuthImpl> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/packages/apidash_core/lib/models/api_auth_model.g.dart b/packages/apidash_core/lib/models/api_auth_model.g.dart index 83a5b868..0c25143b 100644 --- a/packages/apidash_core/lib/models/api_auth_model.g.dart +++ b/packages/apidash_core/lib/models/api_auth_model.g.dart @@ -28,3 +28,45 @@ Map _$$BasicAuthImplToJson(_$BasicAuthImpl instance) => 'password': instance.password, 'runtimeType': instance.$type, }; + +_$BearerTokenAuthImpl _$$BearerTokenAuthImplFromJson( + Map json) => + _$BearerTokenAuthImpl( + token: json['token'] as String, + $type: json['runtimeType'] as String?, + ); + +Map _$$BearerTokenAuthImplToJson( + _$BearerTokenAuthImpl instance) => + { + 'token': instance.token, + 'runtimeType': instance.$type, + }; + +_$APIKeyAuthImpl _$$APIKeyAuthImplFromJson(Map json) => + _$APIKeyAuthImpl( + key: json['key'] as String, + location: json['location'] as String? ?? 'header', + name: json['name'] as String? ?? 'x-api-key', + $type: json['runtimeType'] as String?, + ); + +Map _$$APIKeyAuthImplToJson(_$APIKeyAuthImpl instance) => + { + 'key': instance.key, + 'location': instance.location, + 'name': instance.name, + 'runtimeType': instance.$type, + }; + +_$JWTBearerAuthImpl _$$JWTBearerAuthImplFromJson(Map json) => + _$JWTBearerAuthImpl( + jwt: json['jwt'] as String, + $type: json['runtimeType'] as String?, + ); + +Map _$$JWTBearerAuthImplToJson(_$JWTBearerAuthImpl instance) => + { + 'jwt': instance.jwt, + 'runtimeType': instance.$type, + };