Skip to content

Commit

Permalink
Regenerated Petstore source code.
Browse files Browse the repository at this point in the history
  • Loading branch information
noordawod committed Dec 20, 2021
1 parent 07d2f91 commit 4adb204
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,27 @@ class ApiKeyAuth implements Authentication {
final String location;
final String paramName;

String? apiKeyPrefix;
String? apiKey;
String apiKeyPrefix = '';
String apiKey = '';

@override
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
final value = apiKeyPrefix == null ? apiKey : '$apiKeyPrefix $apiKey';

if (location == 'query' && value != null) {
queryParams.add(QueryParam(paramName, value));
} else if (location == 'header' && value != null) {
headerParams[paramName] = value;
} else if (location == 'cookie' && value != null) {
headerParams.update(
'Cookie',
(existingCookie) => '$existingCookie; $paramName=$value',
ifAbsent: () => '$paramName=$value',
);
apiKeyPrefix = apiKeyPrefix.trim();

final paramValue = (apiKeyPrefix.isEmpty ? apiKey : '$apiKeyPrefix $apiKey').trim();

if (paramValue.isNotEmpty) {
if (location == 'query') {
queryParams.add(QueryParam(paramName, paramValue));
} else if (location == 'header') {
headerParams[paramName] = paramValue;
} else if (location == 'cookie') {
headerParams.update(
'Cookie',
(existingCookie) => '$existingCookie; $paramName=$paramValue',
ifAbsent: () => '$paramName=$paramValue',
);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,19 @@
part of openapi.api;

class HttpBasicAuth implements Authentication {
HttpBasicAuth({this.username, this.password});
HttpBasicAuth({this.username = '', this.password = ''});

String? username;
String? password;
String username;
String password;

@override
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
final credentials = '${username ?? ''}:${password ?? ''}';
headerParams['Authorization'] = 'Basic ${base64.encode(utf8.encode(credentials))}';
username = username.trim();
password = password.trim();

if (username.isNotEmpty && password.isNotEmpty) {
final credentials = '$username:$password';
headerParams['Authorization'] = 'Basic ${base64.encode(utf8.encode(credentials))}';
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,31 @@ class HttpBearerAuth implements Authentication {

set accessToken(dynamic accessToken) {
if (accessToken is! String && accessToken is! HttpBearerAuthProvider) {
throw ArgumentError('Type of Bearer accessToken should be a String or a String Function().');
throw ArgumentError('accessToken value must be either a String or a String Function().');
}
_accessToken = accessToken;
}

@override
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
if (_accessToken == null) {
return;
}

String accessToken;

if (_accessToken is String) {
headerParams['Authorization'] = 'Bearer $_accessToken';
accessToken = _accessToken;
} else if (_accessToken is HttpBearerAuthProvider) {
headerParams['Authorization'] = 'Bearer ${_accessToken()}';
accessToken = _accessToken!();
} else {
throw ArgumentError('Type of Bearer accessToken should be a String or a String Function().');
return;
}

accessToken = accessToken.trim();

if (accessToken.isNotEmpty) {
headerParams['Authorization'] = 'Bearer $accessToken';
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
part of openapi.api;

class OAuth implements Authentication {
OAuth({this.accessToken});
OAuth({this.accessToken = ''});

String? accessToken;
String accessToken;

@override
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
if (accessToken != null) {
accessToken = accessToken.trim();
if (accessToken.isNotEmpty) {
headerParams['Authorization'] = 'Bearer $accessToken';
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,27 @@ class ApiKeyAuth implements Authentication {
final String location;
final String paramName;

String? apiKeyPrefix;
String? apiKey;
String apiKeyPrefix = '';
String apiKey = '';

@override
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
final value = apiKeyPrefix == null ? apiKey : '$apiKeyPrefix $apiKey';

if (location == 'query' && value != null) {
queryParams.add(QueryParam(paramName, value));
} else if (location == 'header' && value != null) {
headerParams[paramName] = value;
} else if (location == 'cookie' && value != null) {
headerParams.update(
'Cookie',
(existingCookie) => '$existingCookie; $paramName=$value',
ifAbsent: () => '$paramName=$value',
);
apiKeyPrefix = apiKeyPrefix.trim();

final paramValue = (apiKeyPrefix.isEmpty ? apiKey : '$apiKeyPrefix $apiKey').trim();

if (paramValue.isNotEmpty) {
if (location == 'query') {
queryParams.add(QueryParam(paramName, paramValue));
} else if (location == 'header') {
headerParams[paramName] = paramValue;
} else if (location == 'cookie') {
headerParams.update(
'Cookie',
(existingCookie) => '$existingCookie; $paramName=$paramValue',
ifAbsent: () => '$paramName=$paramValue',
);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,19 @@
part of openapi.api;

class HttpBasicAuth implements Authentication {
HttpBasicAuth({this.username, this.password});
HttpBasicAuth({this.username = '', this.password = ''});

String? username;
String? password;
String username;
String password;

@override
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
final credentials = '${username ?? ''}:${password ?? ''}';
headerParams['Authorization'] = 'Basic ${base64.encode(utf8.encode(credentials))}';
username = username.trim();
password = password.trim();

if (username.isNotEmpty && password.isNotEmpty) {
final credentials = '$username:$password';
headerParams['Authorization'] = 'Basic ${base64.encode(utf8.encode(credentials))}';
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,31 @@ class HttpBearerAuth implements Authentication {

set accessToken(dynamic accessToken) {
if (accessToken is! String && accessToken is! HttpBearerAuthProvider) {
throw ArgumentError('Type of Bearer accessToken should be a String or a String Function().');
throw ArgumentError('accessToken value must be either a String or a String Function().');
}
_accessToken = accessToken;
}

@override
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
if (_accessToken == null) {
return;
}

String accessToken;

if (_accessToken is String) {
headerParams['Authorization'] = 'Bearer $_accessToken';
accessToken = _accessToken;
} else if (_accessToken is HttpBearerAuthProvider) {
headerParams['Authorization'] = 'Bearer ${_accessToken()}';
accessToken = _accessToken!();
} else {
throw ArgumentError('Type of Bearer accessToken should be a String or a String Function().');
return;
}

accessToken = accessToken.trim();

if (accessToken.isNotEmpty) {
headerParams['Authorization'] = 'Bearer $accessToken';
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
part of openapi.api;

class OAuth implements Authentication {
OAuth({this.accessToken});
OAuth({this.accessToken = ''});

String? accessToken;
String accessToken;

@override
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
if (accessToken != null) {
accessToken = accessToken.trim();
if (accessToken.isNotEmpty) {
headerParams['Authorization'] = 'Bearer $accessToken';
}
}
Expand Down

0 comments on commit 4adb204

Please sign in to comment.