forked from loafle/openapi-generator-original
[dart] Fix authentication for dart (#2419)
* [dart] Fix authentication so all forms of Swagger 2.0 authentication work * Run changes on petstore examples * Amend dart2 generated README to cover basic authentication * Amend dart2 generated README to cover authentication methods * [dart] Fix authentication so all forms of Swagger 2.0 authentication work * Run changes on petstore examples
This commit is contained in:
parent
1f45ea7d1a
commit
d93fd31bb1
@ -58,18 +58,18 @@ import 'package:{{pubName}}/api.dart';
|
||||
{{#authMethods}}
|
||||
{{#isBasic}}
|
||||
// TODO Configure HTTP basic authorization: {{{name}}}
|
||||
//{{pubName}}.api.Configuration.username = 'YOUR_USERNAME';
|
||||
//{{pubName}}.api.Configuration.password = 'YOUR_PASSWORD';
|
||||
//defaultApiClient.getAuthentication<HttpBasicAuth>('{{{name}}}').username = 'YOUR_USERNAME'
|
||||
//defaultApiClient.getAuthentication<HttpBasicAuth>('{{{name}}}').password = 'YOUR_PASSWORD';
|
||||
{{/isBasic}}
|
||||
{{#isApiKey}}
|
||||
// TODO Configure API key authorization: {{{name}}}
|
||||
//{{pubName}}.api.Configuration.apiKey{'{{{keyParamName}}}'} = 'YOUR_API_KEY';
|
||||
//defaultApiClient.getAuthentication<ApiKeyAuth>('{{{name}}}').apiKey = 'YOUR_API_KEY';
|
||||
// uncomment below to setup prefix (e.g. Bearer) for API key, if needed
|
||||
//{{pubName}}.api.Configuration.apiKeyPrefix{'{{{keyParamName}}}'} = "Bearer";
|
||||
//defaultApiClient.getAuthentication<ApiKeyAuth>('{{{name}}}').apiKeyPrefix = 'Bearer';
|
||||
{{/isApiKey}}
|
||||
{{#isOAuth}}
|
||||
// TODO Configure OAuth2 access token for authorization: {{{name}}}
|
||||
//{{pubName}}.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
//defaultApiClient.getAuthentication<OAuth>('{{{name}}}').accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
{{/isOAuth}}
|
||||
{{/authMethods}}
|
||||
{{/hasAuthMethods}}
|
||||
|
@ -157,11 +157,9 @@ class ApiClient {
|
||||
});
|
||||
}
|
||||
|
||||
void setAccessToken(String accessToken) {
|
||||
_authentications.forEach((key, auth) {
|
||||
if (auth is OAuth) {
|
||||
auth.setAccessToken(accessToken);
|
||||
}
|
||||
});
|
||||
T getAuthentication<T extends Authentication>(String name) {
|
||||
var authentication = _authentications[name];
|
||||
|
||||
return authentication is T ? authentication : null;
|
||||
}
|
||||
}
|
||||
|
@ -29,18 +29,18 @@ import 'package:{{pubName}}/api.dart';
|
||||
{{#authMethods}}
|
||||
{{#isBasic}}
|
||||
// TODO Configure HTTP basic authorization: {{{name}}}
|
||||
//{{pubName}}.api.Configuration.username = 'YOUR_USERNAME';
|
||||
//{{pubName}}.api.Configuration.password = 'YOUR_PASSWORD';
|
||||
//defaultApiClient.getAuthentication<HttpBasicAuth>('{{{name}}}').username = 'YOUR_USERNAME'
|
||||
//defaultApiClient.getAuthentication<HttpBasicAuth>('{{{name}}}').password = 'YOUR_PASSWORD';
|
||||
{{/isBasic}}
|
||||
{{#isApiKey}}
|
||||
// TODO Configure API key authorization: {{{name}}}
|
||||
//{{pubName}}.api.Configuration.apiKey{'{{{keyParamName}}}'} = 'YOUR_API_KEY';
|
||||
//defaultApiClient.getAuthentication<ApiKeyAuth>('{{{name}}}').apiKey = 'YOUR_API_KEY';
|
||||
// uncomment below to setup prefix (e.g. Bearer) for API key, if needed
|
||||
//{{pubName}}.api.Configuration.apiKeyPrefix{'{{{keyParamName}}}'} = "Bearer";
|
||||
//defaultApiClient.getAuthentication<ApiKeyAuth>('{{{name}}}').apiKeyPrefix = 'Bearer';
|
||||
{{/isApiKey}}
|
||||
{{#isOAuth}}
|
||||
// TODO Configure OAuth2 access token for authorization: {{{name}}}
|
||||
//{{pubName}}.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
//defaultApiClient.getAuthentication<OAuth>('{{{name}}}').accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
{{/isOAuth}}
|
||||
{{/authMethods}}
|
||||
{{/hasAuthMethods}}
|
||||
|
@ -4,18 +4,20 @@ class ApiKeyAuth implements Authentication {
|
||||
|
||||
final String location;
|
||||
final String paramName;
|
||||
String apiKey;
|
||||
String _apiKey;
|
||||
String apiKeyPrefix;
|
||||
|
||||
set apiKey(String key) => _apiKey = key;
|
||||
|
||||
ApiKeyAuth(this.location, this.paramName);
|
||||
|
||||
@override
|
||||
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
|
||||
String value;
|
||||
if (apiKeyPrefix != null) {
|
||||
value = '$apiKeyPrefix $apiKey';
|
||||
value = '$apiKeyPrefix $_apiKey';
|
||||
} else {
|
||||
value = apiKey;
|
||||
value = _apiKey;
|
||||
}
|
||||
|
||||
if (location == 'query' && value != null) {
|
||||
|
@ -2,13 +2,15 @@ part of {{pubName}}.api;
|
||||
|
||||
class HttpBasicAuth implements Authentication {
|
||||
|
||||
String username;
|
||||
String password;
|
||||
String _username;
|
||||
String _password;
|
||||
|
||||
@override
|
||||
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
|
||||
String str = (username == null ? "" : username) + ":" + (password == null ? "" : password);
|
||||
String str = (_username == null ? "" : _username) + ":" + (_password == null ? "" : _password);
|
||||
headerParams["Authorization"] = "Basic " + base64.encode(utf8.encode(str));
|
||||
}
|
||||
|
||||
set username(String username) => _username = username;
|
||||
set password(String password) => _password = password;
|
||||
}
|
||||
|
@ -1,18 +1,16 @@
|
||||
part of {{pubName}}.api;
|
||||
|
||||
class OAuth implements Authentication {
|
||||
String accessToken;
|
||||
String _accessToken;
|
||||
|
||||
OAuth({this.accessToken});
|
||||
OAuth({String accessToken}) : _accessToken = accessToken;
|
||||
|
||||
@override
|
||||
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
|
||||
if (accessToken != null) {
|
||||
headerParams["Authorization"] = "Bearer " + accessToken;
|
||||
if (_accessToken != null) {
|
||||
headerParams["Authorization"] = "Bearer $_accessToken";
|
||||
}
|
||||
}
|
||||
|
||||
void setAccessToken(String accessToken) {
|
||||
this.accessToken = accessToken;
|
||||
}
|
||||
set accessToken(String accessToken) => _accessToken = accessToken;
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ Add a new pet to the store
|
||||
```dart
|
||||
import 'package:openapi/api.dart';
|
||||
// TODO Configure OAuth2 access token for authorization: petstore_auth
|
||||
//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
//defaultApiClient.getAuthentication<OAuth>('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
|
||||
var api_instance = new PetApi();
|
||||
var body = new Pet(); // Pet | Pet object that needs to be added to the store
|
||||
@ -70,7 +70,7 @@ Deletes a pet
|
||||
```dart
|
||||
import 'package:openapi/api.dart';
|
||||
// TODO Configure OAuth2 access token for authorization: petstore_auth
|
||||
//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
//defaultApiClient.getAuthentication<OAuth>('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
|
||||
var api_instance = new PetApi();
|
||||
var petId = 789; // int | Pet id to delete
|
||||
@ -116,7 +116,7 @@ Multiple status values can be provided with comma separated strings
|
||||
```dart
|
||||
import 'package:openapi/api.dart';
|
||||
// TODO Configure OAuth2 access token for authorization: petstore_auth
|
||||
//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
//defaultApiClient.getAuthentication<OAuth>('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
|
||||
var api_instance = new PetApi();
|
||||
var status = []; // List<String> | Status values that need to be considered for filter
|
||||
@ -161,7 +161,7 @@ Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3
|
||||
```dart
|
||||
import 'package:openapi/api.dart';
|
||||
// TODO Configure OAuth2 access token for authorization: petstore_auth
|
||||
//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
//defaultApiClient.getAuthentication<OAuth>('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
|
||||
var api_instance = new PetApi();
|
||||
var tags = []; // List<String> | Tags to filter by
|
||||
@ -206,9 +206,9 @@ Returns a single pet
|
||||
```dart
|
||||
import 'package:openapi/api.dart';
|
||||
// TODO Configure API key authorization: api_key
|
||||
//openapi.api.Configuration.apiKey{'api_key'} = 'YOUR_API_KEY';
|
||||
//defaultApiClient.getAuthentication<ApiKeyAuth>('api_key').apiKey = 'YOUR_API_KEY';
|
||||
// uncomment below to setup prefix (e.g. Bearer) for API key, if needed
|
||||
//openapi.api.Configuration.apiKeyPrefix{'api_key'} = "Bearer";
|
||||
//defaultApiClient.getAuthentication<ApiKeyAuth>('api_key').apiKeyPrefix = 'Bearer';
|
||||
|
||||
var api_instance = new PetApi();
|
||||
var petId = 789; // int | ID of pet to return
|
||||
@ -251,7 +251,7 @@ Update an existing pet
|
||||
```dart
|
||||
import 'package:openapi/api.dart';
|
||||
// TODO Configure OAuth2 access token for authorization: petstore_auth
|
||||
//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
//defaultApiClient.getAuthentication<OAuth>('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
|
||||
var api_instance = new PetApi();
|
||||
var body = new Pet(); // Pet | Pet object that needs to be added to the store
|
||||
@ -293,7 +293,7 @@ Updates a pet in the store with form data
|
||||
```dart
|
||||
import 'package:openapi/api.dart';
|
||||
// TODO Configure OAuth2 access token for authorization: petstore_auth
|
||||
//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
//defaultApiClient.getAuthentication<OAuth>('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
|
||||
var api_instance = new PetApi();
|
||||
var petId = 789; // int | ID of pet that needs to be updated
|
||||
@ -339,7 +339,7 @@ uploads an image
|
||||
```dart
|
||||
import 'package:openapi/api.dart';
|
||||
// TODO Configure OAuth2 access token for authorization: petstore_auth
|
||||
//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
//defaultApiClient.getAuthentication<OAuth>('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
|
||||
var api_instance = new PetApi();
|
||||
var petId = 789; // int | ID of pet to update
|
||||
|
@ -68,9 +68,9 @@ Returns a map of status codes to quantities
|
||||
```dart
|
||||
import 'package:openapi/api.dart';
|
||||
// TODO Configure API key authorization: api_key
|
||||
//openapi.api.Configuration.apiKey{'api_key'} = 'YOUR_API_KEY';
|
||||
//defaultApiClient.getAuthentication<ApiKeyAuth>('api_key').apiKey = 'YOUR_API_KEY';
|
||||
// uncomment below to setup prefix (e.g. Bearer) for API key, if needed
|
||||
//openapi.api.Configuration.apiKeyPrefix{'api_key'} = "Bearer";
|
||||
//defaultApiClient.getAuthentication<ApiKeyAuth>('api_key').apiKeyPrefix = 'Bearer';
|
||||
|
||||
var api_instance = new StoreApi();
|
||||
|
||||
|
@ -50,7 +50,7 @@ class PetApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
} else {
|
||||
return;
|
||||
@ -100,7 +100,7 @@ class PetApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
} else {
|
||||
return;
|
||||
@ -150,9 +150,9 @@ class PetApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
return (apiClient.deserialize(response.body, 'List<Pet>') as List).map((item) => item as Pet).toList();
|
||||
return (apiClient.deserialize(_decodeBodyBytes(response), 'List<Pet>') as List).map((item) => item as Pet).toList();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@ -201,9 +201,9 @@ class PetApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
return (apiClient.deserialize(response.body, 'List<Pet>') as List).map((item) => item as Pet).toList();
|
||||
return (apiClient.deserialize(_decodeBodyBytes(response), 'List<Pet>') as List).map((item) => item as Pet).toList();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@ -251,9 +251,9 @@ class PetApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
return apiClient.deserialize(response.body, 'Pet') as Pet;
|
||||
return apiClient.deserialize(_decodeBodyBytes(response), 'Pet') as Pet;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@ -301,7 +301,7 @@ class PetApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
} else {
|
||||
return;
|
||||
@ -362,7 +362,7 @@ class PetApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
} else {
|
||||
return;
|
||||
@ -422,9 +422,9 @@ class PetApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
return apiClient.deserialize(response.body, 'ApiResponse') as ApiResponse;
|
||||
return apiClient.deserialize(_decodeBodyBytes(response), 'ApiResponse') as ApiResponse;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ class StoreApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
} else {
|
||||
return;
|
||||
@ -96,9 +96,9 @@ class StoreApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
return new Map<String, int>.from(apiClient.deserialize(response.body, 'Map<String, int>'));
|
||||
return new Map<String, int>.from(apiClient.deserialize(_decodeBodyBytes(response), 'Map<String, int>'));
|
||||
;
|
||||
} else {
|
||||
return null;
|
||||
@ -147,9 +147,9 @@ class StoreApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
return apiClient.deserialize(response.body, 'Order') as Order;
|
||||
return apiClient.deserialize(_decodeBodyBytes(response), 'Order') as Order;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@ -197,9 +197,9 @@ class StoreApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
return apiClient.deserialize(response.body, 'Order') as Order;
|
||||
return apiClient.deserialize(_decodeBodyBytes(response), 'Order') as Order;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ class UserApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
} else {
|
||||
return;
|
||||
@ -99,7 +99,7 @@ class UserApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
} else {
|
||||
return;
|
||||
@ -148,7 +148,7 @@ class UserApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
} else {
|
||||
return;
|
||||
@ -197,7 +197,7 @@ class UserApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
} else {
|
||||
return;
|
||||
@ -246,9 +246,9 @@ class UserApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
return apiClient.deserialize(response.body, 'User') as User;
|
||||
return apiClient.deserialize(_decodeBodyBytes(response), 'User') as User;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@ -301,9 +301,9 @@ class UserApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
return apiClient.deserialize(response.body, 'String') as String;
|
||||
return apiClient.deserialize(_decodeBodyBytes(response), 'String') as String;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@ -348,7 +348,7 @@ class UserApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
} else {
|
||||
return;
|
||||
@ -400,7 +400,7 @@ class UserApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
} else {
|
||||
return;
|
||||
|
@ -105,7 +105,10 @@ class ApiClient {
|
||||
|
||||
_updateParamsForAuth(authNames, queryParams, headerParams);
|
||||
|
||||
var ps = queryParams.where((p) => p.value != null).map((p) => '${p.name}=${p.value}');
|
||||
var ps = queryParams
|
||||
.where((p) => p.value != null)
|
||||
.map((p) => '${p.name}=${Uri.encodeQueryComponent(p.value)}');
|
||||
|
||||
String queryString = ps.isNotEmpty ?
|
||||
'?' + ps.join('&') :
|
||||
'';
|
||||
@ -150,11 +153,9 @@ class ApiClient {
|
||||
});
|
||||
}
|
||||
|
||||
void setAccessToken(String accessToken) {
|
||||
_authentications.forEach((key, auth) {
|
||||
if (auth is OAuth) {
|
||||
auth.setAccessToken(accessToken);
|
||||
}
|
||||
});
|
||||
T getAuthentication<T extends Authentication>(String name) {
|
||||
var authentication = _authentications[name];
|
||||
|
||||
return authentication is T ? authentication : null;
|
||||
}
|
||||
}
|
||||
|
@ -42,3 +42,15 @@ String parameterToString(dynamic value) {
|
||||
return value.toString();
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the decoded body by utf-8 if application/json with the given headers.
|
||||
/// Else, returns the decoded body by default algorithm of dart:http.
|
||||
/// Because avoid to text garbling when header only contains "application/json" without "; charset=utf-8".
|
||||
String _decodeBodyBytes(Response response) {
|
||||
var contentType = response.headers['content-type'];
|
||||
if (contentType != null && contentType.contains("application/json")) {
|
||||
return utf8.decode(response.bodyBytes);
|
||||
} else {
|
||||
return response.body;
|
||||
}
|
||||
}
|
||||
|
@ -4,18 +4,20 @@ class ApiKeyAuth implements Authentication {
|
||||
|
||||
final String location;
|
||||
final String paramName;
|
||||
String apiKey;
|
||||
String _apiKey;
|
||||
String apiKeyPrefix;
|
||||
|
||||
set apiKey(String key) => _apiKey = key;
|
||||
|
||||
ApiKeyAuth(this.location, this.paramName);
|
||||
|
||||
@override
|
||||
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
|
||||
String value;
|
||||
if (apiKeyPrefix != null) {
|
||||
value = '$apiKeyPrefix $apiKey';
|
||||
value = '$apiKeyPrefix $_apiKey';
|
||||
} else {
|
||||
value = apiKey;
|
||||
value = _apiKey;
|
||||
}
|
||||
|
||||
if (location == 'query' && value != null) {
|
||||
|
@ -2,13 +2,15 @@ part of openapi.api;
|
||||
|
||||
class HttpBasicAuth implements Authentication {
|
||||
|
||||
String username;
|
||||
String password;
|
||||
String _username;
|
||||
String _password;
|
||||
|
||||
@override
|
||||
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
|
||||
String str = (username == null ? "" : username) + ":" + (password == null ? "" : password);
|
||||
String str = (_username == null ? "" : _username) + ":" + (_password == null ? "" : _password);
|
||||
headerParams["Authorization"] = "Basic " + base64.encode(utf8.encode(str));
|
||||
}
|
||||
|
||||
set username(String username) => _username = username;
|
||||
set password(String password) => _password = password;
|
||||
}
|
||||
|
@ -1,18 +1,16 @@
|
||||
part of openapi.api;
|
||||
|
||||
class OAuth implements Authentication {
|
||||
String accessToken;
|
||||
String _accessToken;
|
||||
|
||||
OAuth({this.accessToken});
|
||||
OAuth({String accessToken}) : _accessToken = accessToken;
|
||||
|
||||
@override
|
||||
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
|
||||
if (accessToken != null) {
|
||||
headerParams["Authorization"] = "Bearer " + accessToken;
|
||||
if (_accessToken != null) {
|
||||
headerParams["Authorization"] = "Bearer $_accessToken";
|
||||
}
|
||||
}
|
||||
|
||||
void setAccessToken(String accessToken) {
|
||||
this.accessToken = accessToken;
|
||||
}
|
||||
set accessToken(String accessToken) => _accessToken = accessToken;
|
||||
}
|
||||
|
@ -19,17 +19,17 @@ class ApiResponse {
|
||||
if (json['code'] == null) {
|
||||
code = null;
|
||||
} else {
|
||||
code = json['code'];
|
||||
code = json['code'];
|
||||
}
|
||||
if (json['type'] == null) {
|
||||
type = null;
|
||||
} else {
|
||||
type = json['type'];
|
||||
type = json['type'];
|
||||
}
|
||||
if (json['message'] == null) {
|
||||
message = null;
|
||||
} else {
|
||||
message = json['message'];
|
||||
message = json['message'];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,12 +17,12 @@ class Category {
|
||||
if (json['id'] == null) {
|
||||
id = null;
|
||||
} else {
|
||||
id = json['id'];
|
||||
id = json['id'];
|
||||
}
|
||||
if (json['name'] == null) {
|
||||
name = null;
|
||||
} else {
|
||||
name = json['name'];
|
||||
name = json['name'];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,17 +26,17 @@ class Order {
|
||||
if (json['id'] == null) {
|
||||
id = null;
|
||||
} else {
|
||||
id = json['id'];
|
||||
id = json['id'];
|
||||
}
|
||||
if (json['petId'] == null) {
|
||||
petId = null;
|
||||
} else {
|
||||
petId = json['petId'];
|
||||
petId = json['petId'];
|
||||
}
|
||||
if (json['quantity'] == null) {
|
||||
quantity = null;
|
||||
} else {
|
||||
quantity = json['quantity'];
|
||||
quantity = json['quantity'];
|
||||
}
|
||||
if (json['shipDate'] == null) {
|
||||
shipDate = null;
|
||||
@ -46,12 +46,12 @@ class Order {
|
||||
if (json['status'] == null) {
|
||||
status = null;
|
||||
} else {
|
||||
status = json['status'];
|
||||
status = json['status'];
|
||||
}
|
||||
if (json['complete'] == null) {
|
||||
complete = null;
|
||||
} else {
|
||||
complete = json['complete'];
|
||||
complete = json['complete'];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,7 @@ class Pet {
|
||||
if (json['id'] == null) {
|
||||
id = null;
|
||||
} else {
|
||||
id = json['id'];
|
||||
id = json['id'];
|
||||
}
|
||||
if (json['category'] == null) {
|
||||
category = null;
|
||||
@ -36,12 +36,12 @@ class Pet {
|
||||
if (json['name'] == null) {
|
||||
name = null;
|
||||
} else {
|
||||
name = json['name'];
|
||||
name = json['name'];
|
||||
}
|
||||
if (json['photoUrls'] == null) {
|
||||
photoUrls = null;
|
||||
} else {
|
||||
photoUrls = ((json['photoUrls'] ?? []) as List).map((item) => item as String).toList();
|
||||
photoUrls = (json['photoUrls'] as List).cast<String>();
|
||||
}
|
||||
if (json['tags'] == null) {
|
||||
tags = null;
|
||||
@ -51,7 +51,7 @@ class Pet {
|
||||
if (json['status'] == null) {
|
||||
status = null;
|
||||
} else {
|
||||
status = json['status'];
|
||||
status = json['status'];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,12 +17,12 @@ class Tag {
|
||||
if (json['id'] == null) {
|
||||
id = null;
|
||||
} else {
|
||||
id = json['id'];
|
||||
id = json['id'];
|
||||
}
|
||||
if (json['name'] == null) {
|
||||
name = null;
|
||||
} else {
|
||||
name = json['name'];
|
||||
name = json['name'];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,42 +29,42 @@ class User {
|
||||
if (json['id'] == null) {
|
||||
id = null;
|
||||
} else {
|
||||
id = json['id'];
|
||||
id = json['id'];
|
||||
}
|
||||
if (json['username'] == null) {
|
||||
username = null;
|
||||
} else {
|
||||
username = json['username'];
|
||||
username = json['username'];
|
||||
}
|
||||
if (json['firstName'] == null) {
|
||||
firstName = null;
|
||||
} else {
|
||||
firstName = json['firstName'];
|
||||
firstName = json['firstName'];
|
||||
}
|
||||
if (json['lastName'] == null) {
|
||||
lastName = null;
|
||||
} else {
|
||||
lastName = json['lastName'];
|
||||
lastName = json['lastName'];
|
||||
}
|
||||
if (json['email'] == null) {
|
||||
email = null;
|
||||
} else {
|
||||
email = json['email'];
|
||||
email = json['email'];
|
||||
}
|
||||
if (json['password'] == null) {
|
||||
password = null;
|
||||
} else {
|
||||
password = json['password'];
|
||||
password = json['password'];
|
||||
}
|
||||
if (json['phone'] == null) {
|
||||
phone = null;
|
||||
} else {
|
||||
phone = json['phone'];
|
||||
phone = json['phone'];
|
||||
}
|
||||
if (json['userStatus'] == null) {
|
||||
userStatus = null;
|
||||
} else {
|
||||
userStatus = json['userStatus'];
|
||||
userStatus = json['userStatus'];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ Add a new pet to the store
|
||||
```dart
|
||||
import 'package:openapi/api.dart';
|
||||
// TODO Configure OAuth2 access token for authorization: petstore_auth
|
||||
//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
//defaultApiClient.getAuthentication<OAuth>('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
|
||||
var api_instance = new PetApi();
|
||||
var body = new Pet(); // Pet | Pet object that needs to be added to the store
|
||||
@ -70,7 +70,7 @@ Deletes a pet
|
||||
```dart
|
||||
import 'package:openapi/api.dart';
|
||||
// TODO Configure OAuth2 access token for authorization: petstore_auth
|
||||
//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
//defaultApiClient.getAuthentication<OAuth>('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
|
||||
var api_instance = new PetApi();
|
||||
var petId = 789; // int | Pet id to delete
|
||||
@ -116,7 +116,7 @@ Multiple status values can be provided with comma separated strings
|
||||
```dart
|
||||
import 'package:openapi/api.dart';
|
||||
// TODO Configure OAuth2 access token for authorization: petstore_auth
|
||||
//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
//defaultApiClient.getAuthentication<OAuth>('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
|
||||
var api_instance = new PetApi();
|
||||
var status = []; // List<String> | Status values that need to be considered for filter
|
||||
@ -161,7 +161,7 @@ Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3
|
||||
```dart
|
||||
import 'package:openapi/api.dart';
|
||||
// TODO Configure OAuth2 access token for authorization: petstore_auth
|
||||
//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
//defaultApiClient.getAuthentication<OAuth>('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
|
||||
var api_instance = new PetApi();
|
||||
var tags = []; // List<String> | Tags to filter by
|
||||
@ -206,9 +206,9 @@ Returns a single pet
|
||||
```dart
|
||||
import 'package:openapi/api.dart';
|
||||
// TODO Configure API key authorization: api_key
|
||||
//openapi.api.Configuration.apiKey{'api_key'} = 'YOUR_API_KEY';
|
||||
//defaultApiClient.getAuthentication<ApiKeyAuth>('api_key').apiKey = 'YOUR_API_KEY';
|
||||
// uncomment below to setup prefix (e.g. Bearer) for API key, if needed
|
||||
//openapi.api.Configuration.apiKeyPrefix{'api_key'} = "Bearer";
|
||||
//defaultApiClient.getAuthentication<ApiKeyAuth>('api_key').apiKeyPrefix = 'Bearer';
|
||||
|
||||
var api_instance = new PetApi();
|
||||
var petId = 789; // int | ID of pet to return
|
||||
@ -251,7 +251,7 @@ Update an existing pet
|
||||
```dart
|
||||
import 'package:openapi/api.dart';
|
||||
// TODO Configure OAuth2 access token for authorization: petstore_auth
|
||||
//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
//defaultApiClient.getAuthentication<OAuth>('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
|
||||
var api_instance = new PetApi();
|
||||
var body = new Pet(); // Pet | Pet object that needs to be added to the store
|
||||
@ -293,7 +293,7 @@ Updates a pet in the store with form data
|
||||
```dart
|
||||
import 'package:openapi/api.dart';
|
||||
// TODO Configure OAuth2 access token for authorization: petstore_auth
|
||||
//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
//defaultApiClient.getAuthentication<OAuth>('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
|
||||
var api_instance = new PetApi();
|
||||
var petId = 789; // int | ID of pet that needs to be updated
|
||||
@ -339,7 +339,7 @@ uploads an image
|
||||
```dart
|
||||
import 'package:openapi/api.dart';
|
||||
// TODO Configure OAuth2 access token for authorization: petstore_auth
|
||||
//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
//defaultApiClient.getAuthentication<OAuth>('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
|
||||
var api_instance = new PetApi();
|
||||
var petId = 789; // int | ID of pet to update
|
||||
|
@ -68,9 +68,9 @@ Returns a map of status codes to quantities
|
||||
```dart
|
||||
import 'package:openapi/api.dart';
|
||||
// TODO Configure API key authorization: api_key
|
||||
//openapi.api.Configuration.apiKey{'api_key'} = 'YOUR_API_KEY';
|
||||
//defaultApiClient.getAuthentication<ApiKeyAuth>('api_key').apiKey = 'YOUR_API_KEY';
|
||||
// uncomment below to setup prefix (e.g. Bearer) for API key, if needed
|
||||
//openapi.api.Configuration.apiKeyPrefix{'api_key'} = "Bearer";
|
||||
//defaultApiClient.getAuthentication<ApiKeyAuth>('api_key').apiKeyPrefix = 'Bearer';
|
||||
|
||||
var api_instance = new StoreApi();
|
||||
|
||||
|
@ -50,7 +50,7 @@ class PetApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
} else {
|
||||
return;
|
||||
@ -100,7 +100,7 @@ class PetApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
} else {
|
||||
return;
|
||||
@ -150,9 +150,9 @@ class PetApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
return (apiClient.deserialize(response.body, 'List<Pet>') as List).map((item) => item as Pet).toList();
|
||||
return (apiClient.deserialize(_decodeBodyBytes(response), 'List<Pet>') as List).map((item) => item as Pet).toList();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@ -201,9 +201,9 @@ class PetApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
return (apiClient.deserialize(response.body, 'List<Pet>') as List).map((item) => item as Pet).toList();
|
||||
return (apiClient.deserialize(_decodeBodyBytes(response), 'List<Pet>') as List).map((item) => item as Pet).toList();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@ -251,9 +251,9 @@ class PetApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
return apiClient.deserialize(response.body, 'Pet') as Pet;
|
||||
return apiClient.deserialize(_decodeBodyBytes(response), 'Pet') as Pet;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@ -301,7 +301,7 @@ class PetApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
} else {
|
||||
return;
|
||||
@ -362,7 +362,7 @@ class PetApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
} else {
|
||||
return;
|
||||
@ -422,9 +422,9 @@ class PetApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
return apiClient.deserialize(response.body, 'ApiResponse') as ApiResponse;
|
||||
return apiClient.deserialize(_decodeBodyBytes(response), 'ApiResponse') as ApiResponse;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ class StoreApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
} else {
|
||||
return;
|
||||
@ -96,9 +96,9 @@ class StoreApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
return new Map<String, int>.from(apiClient.deserialize(response.body, 'Map<String, int>'));
|
||||
return new Map<String, int>.from(apiClient.deserialize(_decodeBodyBytes(response), 'Map<String, int>'));
|
||||
;
|
||||
} else {
|
||||
return null;
|
||||
@ -147,9 +147,9 @@ class StoreApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
return apiClient.deserialize(response.body, 'Order') as Order;
|
||||
return apiClient.deserialize(_decodeBodyBytes(response), 'Order') as Order;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@ -197,9 +197,9 @@ class StoreApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
return apiClient.deserialize(response.body, 'Order') as Order;
|
||||
return apiClient.deserialize(_decodeBodyBytes(response), 'Order') as Order;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ class UserApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
} else {
|
||||
return;
|
||||
@ -99,7 +99,7 @@ class UserApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
} else {
|
||||
return;
|
||||
@ -148,7 +148,7 @@ class UserApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
} else {
|
||||
return;
|
||||
@ -197,7 +197,7 @@ class UserApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
} else {
|
||||
return;
|
||||
@ -246,9 +246,9 @@ class UserApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
return apiClient.deserialize(response.body, 'User') as User;
|
||||
return apiClient.deserialize(_decodeBodyBytes(response), 'User') as User;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@ -301,9 +301,9 @@ class UserApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
return apiClient.deserialize(response.body, 'String') as String;
|
||||
return apiClient.deserialize(_decodeBodyBytes(response), 'String') as String;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@ -348,7 +348,7 @@ class UserApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
} else {
|
||||
return;
|
||||
@ -400,7 +400,7 @@ class UserApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
} else {
|
||||
return;
|
||||
|
@ -105,7 +105,10 @@ class ApiClient {
|
||||
|
||||
_updateParamsForAuth(authNames, queryParams, headerParams);
|
||||
|
||||
var ps = queryParams.where((p) => p.value != null).map((p) => '${p.name}=${p.value}');
|
||||
var ps = queryParams
|
||||
.where((p) => p.value != null)
|
||||
.map((p) => '${p.name}=${Uri.encodeQueryComponent(p.value)}');
|
||||
|
||||
String queryString = ps.isNotEmpty ?
|
||||
'?' + ps.join('&') :
|
||||
'';
|
||||
@ -150,11 +153,9 @@ class ApiClient {
|
||||
});
|
||||
}
|
||||
|
||||
void setAccessToken(String accessToken) {
|
||||
_authentications.forEach((key, auth) {
|
||||
if (auth is OAuth) {
|
||||
auth.setAccessToken(accessToken);
|
||||
}
|
||||
});
|
||||
T getAuthentication<T extends Authentication>(String name) {
|
||||
var authentication = _authentications[name];
|
||||
|
||||
return authentication is T ? authentication : null;
|
||||
}
|
||||
}
|
||||
|
@ -42,3 +42,15 @@ String parameterToString(dynamic value) {
|
||||
return value.toString();
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the decoded body by utf-8 if application/json with the given headers.
|
||||
/// Else, returns the decoded body by default algorithm of dart:http.
|
||||
/// Because avoid to text garbling when header only contains "application/json" without "; charset=utf-8".
|
||||
String _decodeBodyBytes(Response response) {
|
||||
var contentType = response.headers['content-type'];
|
||||
if (contentType != null && contentType.contains("application/json")) {
|
||||
return utf8.decode(response.bodyBytes);
|
||||
} else {
|
||||
return response.body;
|
||||
}
|
||||
}
|
||||
|
@ -4,18 +4,20 @@ class ApiKeyAuth implements Authentication {
|
||||
|
||||
final String location;
|
||||
final String paramName;
|
||||
String apiKey;
|
||||
String _apiKey;
|
||||
String apiKeyPrefix;
|
||||
|
||||
set apiKey(String key) => _apiKey = key;
|
||||
|
||||
ApiKeyAuth(this.location, this.paramName);
|
||||
|
||||
@override
|
||||
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
|
||||
String value;
|
||||
if (apiKeyPrefix != null) {
|
||||
value = '$apiKeyPrefix $apiKey';
|
||||
value = '$apiKeyPrefix $_apiKey';
|
||||
} else {
|
||||
value = apiKey;
|
||||
value = _apiKey;
|
||||
}
|
||||
|
||||
if (location == 'query' && value != null) {
|
||||
|
@ -2,13 +2,15 @@ part of openapi.api;
|
||||
|
||||
class HttpBasicAuth implements Authentication {
|
||||
|
||||
String username;
|
||||
String password;
|
||||
String _username;
|
||||
String _password;
|
||||
|
||||
@override
|
||||
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
|
||||
String str = (username == null ? "" : username) + ":" + (password == null ? "" : password);
|
||||
String str = (_username == null ? "" : _username) + ":" + (_password == null ? "" : _password);
|
||||
headerParams["Authorization"] = "Basic " + base64.encode(utf8.encode(str));
|
||||
}
|
||||
|
||||
set username(String username) => _username = username;
|
||||
set password(String password) => _password = password;
|
||||
}
|
||||
|
@ -1,18 +1,16 @@
|
||||
part of openapi.api;
|
||||
|
||||
class OAuth implements Authentication {
|
||||
String accessToken;
|
||||
String _accessToken;
|
||||
|
||||
OAuth({this.accessToken});
|
||||
OAuth({String accessToken}) : _accessToken = accessToken;
|
||||
|
||||
@override
|
||||
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
|
||||
if (accessToken != null) {
|
||||
headerParams["Authorization"] = "Bearer " + accessToken;
|
||||
if (_accessToken != null) {
|
||||
headerParams["Authorization"] = "Bearer $_accessToken";
|
||||
}
|
||||
}
|
||||
|
||||
void setAccessToken(String accessToken) {
|
||||
this.accessToken = accessToken;
|
||||
}
|
||||
set accessToken(String accessToken) => _accessToken = accessToken;
|
||||
}
|
||||
|
@ -19,17 +19,17 @@ class ApiResponse {
|
||||
if (json['code'] == null) {
|
||||
code = null;
|
||||
} else {
|
||||
code = json['code'];
|
||||
code = json['code'];
|
||||
}
|
||||
if (json['type'] == null) {
|
||||
type = null;
|
||||
} else {
|
||||
type = json['type'];
|
||||
type = json['type'];
|
||||
}
|
||||
if (json['message'] == null) {
|
||||
message = null;
|
||||
} else {
|
||||
message = json['message'];
|
||||
message = json['message'];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,12 +17,12 @@ class Category {
|
||||
if (json['id'] == null) {
|
||||
id = null;
|
||||
} else {
|
||||
id = json['id'];
|
||||
id = json['id'];
|
||||
}
|
||||
if (json['name'] == null) {
|
||||
name = null;
|
||||
} else {
|
||||
name = json['name'];
|
||||
name = json['name'];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,17 +26,17 @@ class Order {
|
||||
if (json['id'] == null) {
|
||||
id = null;
|
||||
} else {
|
||||
id = json['id'];
|
||||
id = json['id'];
|
||||
}
|
||||
if (json['petId'] == null) {
|
||||
petId = null;
|
||||
} else {
|
||||
petId = json['petId'];
|
||||
petId = json['petId'];
|
||||
}
|
||||
if (json['quantity'] == null) {
|
||||
quantity = null;
|
||||
} else {
|
||||
quantity = json['quantity'];
|
||||
quantity = json['quantity'];
|
||||
}
|
||||
if (json['shipDate'] == null) {
|
||||
shipDate = null;
|
||||
@ -46,12 +46,12 @@ class Order {
|
||||
if (json['status'] == null) {
|
||||
status = null;
|
||||
} else {
|
||||
status = json['status'];
|
||||
status = json['status'];
|
||||
}
|
||||
if (json['complete'] == null) {
|
||||
complete = null;
|
||||
} else {
|
||||
complete = json['complete'];
|
||||
complete = json['complete'];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,7 @@ class Pet {
|
||||
if (json['id'] == null) {
|
||||
id = null;
|
||||
} else {
|
||||
id = json['id'];
|
||||
id = json['id'];
|
||||
}
|
||||
if (json['category'] == null) {
|
||||
category = null;
|
||||
@ -36,12 +36,12 @@ class Pet {
|
||||
if (json['name'] == null) {
|
||||
name = null;
|
||||
} else {
|
||||
name = json['name'];
|
||||
name = json['name'];
|
||||
}
|
||||
if (json['photoUrls'] == null) {
|
||||
photoUrls = null;
|
||||
} else {
|
||||
photoUrls = ((json['photoUrls'] ?? []) as List).map((item) => item as String).toList();
|
||||
photoUrls = (json['photoUrls'] as List).cast<String>();
|
||||
}
|
||||
if (json['tags'] == null) {
|
||||
tags = null;
|
||||
@ -51,7 +51,7 @@ class Pet {
|
||||
if (json['status'] == null) {
|
||||
status = null;
|
||||
} else {
|
||||
status = json['status'];
|
||||
status = json['status'];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,12 +17,12 @@ class Tag {
|
||||
if (json['id'] == null) {
|
||||
id = null;
|
||||
} else {
|
||||
id = json['id'];
|
||||
id = json['id'];
|
||||
}
|
||||
if (json['name'] == null) {
|
||||
name = null;
|
||||
} else {
|
||||
name = json['name'];
|
||||
name = json['name'];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,42 +29,42 @@ class User {
|
||||
if (json['id'] == null) {
|
||||
id = null;
|
||||
} else {
|
||||
id = json['id'];
|
||||
id = json['id'];
|
||||
}
|
||||
if (json['username'] == null) {
|
||||
username = null;
|
||||
} else {
|
||||
username = json['username'];
|
||||
username = json['username'];
|
||||
}
|
||||
if (json['firstName'] == null) {
|
||||
firstName = null;
|
||||
} else {
|
||||
firstName = json['firstName'];
|
||||
firstName = json['firstName'];
|
||||
}
|
||||
if (json['lastName'] == null) {
|
||||
lastName = null;
|
||||
} else {
|
||||
lastName = json['lastName'];
|
||||
lastName = json['lastName'];
|
||||
}
|
||||
if (json['email'] == null) {
|
||||
email = null;
|
||||
} else {
|
||||
email = json['email'];
|
||||
email = json['email'];
|
||||
}
|
||||
if (json['password'] == null) {
|
||||
password = null;
|
||||
} else {
|
||||
password = json['password'];
|
||||
password = json['password'];
|
||||
}
|
||||
if (json['phone'] == null) {
|
||||
phone = null;
|
||||
} else {
|
||||
phone = json['phone'];
|
||||
phone = json['phone'];
|
||||
}
|
||||
if (json['userStatus'] == null) {
|
||||
userStatus = null;
|
||||
} else {
|
||||
userStatus = json['userStatus'];
|
||||
userStatus = json['userStatus'];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ Add a new pet to the store
|
||||
```dart
|
||||
import 'package:openapi/api.dart';
|
||||
// TODO Configure OAuth2 access token for authorization: petstore_auth
|
||||
//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
//defaultApiClient.getAuthentication<OAuth>('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
|
||||
var api_instance = new PetApi();
|
||||
var body = new Pet(); // Pet | Pet object that needs to be added to the store
|
||||
@ -70,7 +70,7 @@ Deletes a pet
|
||||
```dart
|
||||
import 'package:openapi/api.dart';
|
||||
// TODO Configure OAuth2 access token for authorization: petstore_auth
|
||||
//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
//defaultApiClient.getAuthentication<OAuth>('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
|
||||
var api_instance = new PetApi();
|
||||
var petId = 789; // int | Pet id to delete
|
||||
@ -116,7 +116,7 @@ Multiple status values can be provided with comma separated strings
|
||||
```dart
|
||||
import 'package:openapi/api.dart';
|
||||
// TODO Configure OAuth2 access token for authorization: petstore_auth
|
||||
//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
//defaultApiClient.getAuthentication<OAuth>('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
|
||||
var api_instance = new PetApi();
|
||||
var status = []; // List<String> | Status values that need to be considered for filter
|
||||
@ -161,7 +161,7 @@ Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3
|
||||
```dart
|
||||
import 'package:openapi/api.dart';
|
||||
// TODO Configure OAuth2 access token for authorization: petstore_auth
|
||||
//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
//defaultApiClient.getAuthentication<OAuth>('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
|
||||
var api_instance = new PetApi();
|
||||
var tags = []; // List<String> | Tags to filter by
|
||||
@ -206,9 +206,9 @@ Returns a single pet
|
||||
```dart
|
||||
import 'package:openapi/api.dart';
|
||||
// TODO Configure API key authorization: api_key
|
||||
//openapi.api.Configuration.apiKey{'api_key'} = 'YOUR_API_KEY';
|
||||
//defaultApiClient.getAuthentication<ApiKeyAuth>('api_key').apiKey = 'YOUR_API_KEY';
|
||||
// uncomment below to setup prefix (e.g. Bearer) for API key, if needed
|
||||
//openapi.api.Configuration.apiKeyPrefix{'api_key'} = "Bearer";
|
||||
//defaultApiClient.getAuthentication<ApiKeyAuth>('api_key').apiKeyPrefix = 'Bearer';
|
||||
|
||||
var api_instance = new PetApi();
|
||||
var petId = 789; // int | ID of pet to return
|
||||
@ -251,7 +251,7 @@ Update an existing pet
|
||||
```dart
|
||||
import 'package:openapi/api.dart';
|
||||
// TODO Configure OAuth2 access token for authorization: petstore_auth
|
||||
//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
//defaultApiClient.getAuthentication<OAuth>('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
|
||||
var api_instance = new PetApi();
|
||||
var body = new Pet(); // Pet | Pet object that needs to be added to the store
|
||||
@ -293,7 +293,7 @@ Updates a pet in the store with form data
|
||||
```dart
|
||||
import 'package:openapi/api.dart';
|
||||
// TODO Configure OAuth2 access token for authorization: petstore_auth
|
||||
//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
//defaultApiClient.getAuthentication<OAuth>('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
|
||||
var api_instance = new PetApi();
|
||||
var petId = 789; // int | ID of pet that needs to be updated
|
||||
@ -339,7 +339,7 @@ uploads an image
|
||||
```dart
|
||||
import 'package:openapi/api.dart';
|
||||
// TODO Configure OAuth2 access token for authorization: petstore_auth
|
||||
//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
//defaultApiClient.getAuthentication<OAuth>('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
|
||||
var api_instance = new PetApi();
|
||||
var petId = 789; // int | ID of pet to update
|
||||
|
@ -68,9 +68,9 @@ Returns a map of status codes to quantities
|
||||
```dart
|
||||
import 'package:openapi/api.dart';
|
||||
// TODO Configure API key authorization: api_key
|
||||
//openapi.api.Configuration.apiKey{'api_key'} = 'YOUR_API_KEY';
|
||||
//defaultApiClient.getAuthentication<ApiKeyAuth>('api_key').apiKey = 'YOUR_API_KEY';
|
||||
// uncomment below to setup prefix (e.g. Bearer) for API key, if needed
|
||||
//openapi.api.Configuration.apiKeyPrefix{'api_key'} = "Bearer";
|
||||
//defaultApiClient.getAuthentication<ApiKeyAuth>('api_key').apiKeyPrefix = 'Bearer';
|
||||
|
||||
var api_instance = new StoreApi();
|
||||
|
||||
|
@ -50,7 +50,7 @@ class PetApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
} else {
|
||||
return;
|
||||
@ -100,7 +100,7 @@ class PetApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
} else {
|
||||
return;
|
||||
@ -150,9 +150,9 @@ class PetApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
return (apiClient.deserialize(response.body, 'List<Pet>') as List).map((item) => item as Pet).toList();
|
||||
return (apiClient.deserialize(_decodeBodyBytes(response), 'List<Pet>') as List).map((item) => item as Pet).toList();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@ -201,9 +201,9 @@ class PetApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
return (apiClient.deserialize(response.body, 'List<Pet>') as List).map((item) => item as Pet).toList();
|
||||
return (apiClient.deserialize(_decodeBodyBytes(response), 'List<Pet>') as List).map((item) => item as Pet).toList();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@ -251,9 +251,9 @@ class PetApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
return apiClient.deserialize(response.body, 'Pet') as Pet;
|
||||
return apiClient.deserialize(_decodeBodyBytes(response), 'Pet') as Pet;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@ -301,7 +301,7 @@ class PetApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
} else {
|
||||
return;
|
||||
@ -362,7 +362,7 @@ class PetApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
} else {
|
||||
return;
|
||||
@ -422,9 +422,9 @@ class PetApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
return apiClient.deserialize(response.body, 'ApiResponse') as ApiResponse;
|
||||
return apiClient.deserialize(_decodeBodyBytes(response), 'ApiResponse') as ApiResponse;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ class StoreApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
} else {
|
||||
return;
|
||||
@ -96,9 +96,9 @@ class StoreApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
return new Map<String, int>.from(apiClient.deserialize(response.body, 'Map<String, int>'));
|
||||
return new Map<String, int>.from(apiClient.deserialize(_decodeBodyBytes(response), 'Map<String, int>'));
|
||||
;
|
||||
} else {
|
||||
return null;
|
||||
@ -147,9 +147,9 @@ class StoreApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
return apiClient.deserialize(response.body, 'Order') as Order;
|
||||
return apiClient.deserialize(_decodeBodyBytes(response), 'Order') as Order;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@ -197,9 +197,9 @@ class StoreApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
return apiClient.deserialize(response.body, 'Order') as Order;
|
||||
return apiClient.deserialize(_decodeBodyBytes(response), 'Order') as Order;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ class UserApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
} else {
|
||||
return;
|
||||
@ -99,7 +99,7 @@ class UserApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
} else {
|
||||
return;
|
||||
@ -148,7 +148,7 @@ class UserApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
} else {
|
||||
return;
|
||||
@ -197,7 +197,7 @@ class UserApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
} else {
|
||||
return;
|
||||
@ -246,9 +246,9 @@ class UserApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
return apiClient.deserialize(response.body, 'User') as User;
|
||||
return apiClient.deserialize(_decodeBodyBytes(response), 'User') as User;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@ -301,9 +301,9 @@ class UserApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
return apiClient.deserialize(response.body, 'String') as String;
|
||||
return apiClient.deserialize(_decodeBodyBytes(response), 'String') as String;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@ -348,7 +348,7 @@ class UserApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
} else {
|
||||
return;
|
||||
@ -400,7 +400,7 @@ class UserApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
} else {
|
||||
return;
|
||||
|
@ -105,7 +105,10 @@ class ApiClient {
|
||||
|
||||
_updateParamsForAuth(authNames, queryParams, headerParams);
|
||||
|
||||
var ps = queryParams.where((p) => p.value != null).map((p) => '${p.name}=${p.value}');
|
||||
var ps = queryParams
|
||||
.where((p) => p.value != null)
|
||||
.map((p) => '${p.name}=${Uri.encodeQueryComponent(p.value)}');
|
||||
|
||||
String queryString = ps.isNotEmpty ?
|
||||
'?' + ps.join('&') :
|
||||
'';
|
||||
@ -150,11 +153,9 @@ class ApiClient {
|
||||
});
|
||||
}
|
||||
|
||||
void setAccessToken(String accessToken) {
|
||||
_authentications.forEach((key, auth) {
|
||||
if (auth is OAuth) {
|
||||
auth.setAccessToken(accessToken);
|
||||
}
|
||||
});
|
||||
T getAuthentication<T extends Authentication>(String name) {
|
||||
var authentication = _authentications[name];
|
||||
|
||||
return authentication is T ? authentication : null;
|
||||
}
|
||||
}
|
||||
|
@ -42,3 +42,15 @@ String parameterToString(dynamic value) {
|
||||
return value.toString();
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the decoded body by utf-8 if application/json with the given headers.
|
||||
/// Else, returns the decoded body by default algorithm of dart:http.
|
||||
/// Because avoid to text garbling when header only contains "application/json" without "; charset=utf-8".
|
||||
String _decodeBodyBytes(Response response) {
|
||||
var contentType = response.headers['content-type'];
|
||||
if (contentType != null && contentType.contains("application/json")) {
|
||||
return utf8.decode(response.bodyBytes);
|
||||
} else {
|
||||
return response.body;
|
||||
}
|
||||
}
|
||||
|
@ -4,18 +4,20 @@ class ApiKeyAuth implements Authentication {
|
||||
|
||||
final String location;
|
||||
final String paramName;
|
||||
String apiKey;
|
||||
String _apiKey;
|
||||
String apiKeyPrefix;
|
||||
|
||||
set apiKey(String key) => _apiKey = key;
|
||||
|
||||
ApiKeyAuth(this.location, this.paramName);
|
||||
|
||||
@override
|
||||
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
|
||||
String value;
|
||||
if (apiKeyPrefix != null) {
|
||||
value = '$apiKeyPrefix $apiKey';
|
||||
value = '$apiKeyPrefix $_apiKey';
|
||||
} else {
|
||||
value = apiKey;
|
||||
value = _apiKey;
|
||||
}
|
||||
|
||||
if (location == 'query' && value != null) {
|
||||
|
@ -2,13 +2,15 @@ part of openapi.api;
|
||||
|
||||
class HttpBasicAuth implements Authentication {
|
||||
|
||||
String username;
|
||||
String password;
|
||||
String _username;
|
||||
String _password;
|
||||
|
||||
@override
|
||||
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
|
||||
String str = (username == null ? "" : username) + ":" + (password == null ? "" : password);
|
||||
String str = (_username == null ? "" : _username) + ":" + (_password == null ? "" : _password);
|
||||
headerParams["Authorization"] = "Basic " + base64.encode(utf8.encode(str));
|
||||
}
|
||||
|
||||
set username(String username) => _username = username;
|
||||
set password(String password) => _password = password;
|
||||
}
|
||||
|
@ -1,18 +1,16 @@
|
||||
part of openapi.api;
|
||||
|
||||
class OAuth implements Authentication {
|
||||
String accessToken;
|
||||
String _accessToken;
|
||||
|
||||
OAuth({this.accessToken});
|
||||
OAuth({String accessToken}) : _accessToken = accessToken;
|
||||
|
||||
@override
|
||||
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
|
||||
if (accessToken != null) {
|
||||
headerParams["Authorization"] = "Bearer " + accessToken;
|
||||
if (_accessToken != null) {
|
||||
headerParams["Authorization"] = "Bearer $_accessToken";
|
||||
}
|
||||
}
|
||||
|
||||
void setAccessToken(String accessToken) {
|
||||
this.accessToken = accessToken;
|
||||
}
|
||||
set accessToken(String accessToken) => _accessToken = accessToken;
|
||||
}
|
||||
|
@ -19,17 +19,17 @@ class ApiResponse {
|
||||
if (json['code'] == null) {
|
||||
code = null;
|
||||
} else {
|
||||
code = json['code'];
|
||||
code = json['code'];
|
||||
}
|
||||
if (json['type'] == null) {
|
||||
type = null;
|
||||
} else {
|
||||
type = json['type'];
|
||||
type = json['type'];
|
||||
}
|
||||
if (json['message'] == null) {
|
||||
message = null;
|
||||
} else {
|
||||
message = json['message'];
|
||||
message = json['message'];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,12 +17,12 @@ class Category {
|
||||
if (json['id'] == null) {
|
||||
id = null;
|
||||
} else {
|
||||
id = json['id'];
|
||||
id = json['id'];
|
||||
}
|
||||
if (json['name'] == null) {
|
||||
name = null;
|
||||
} else {
|
||||
name = json['name'];
|
||||
name = json['name'];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,17 +26,17 @@ class Order {
|
||||
if (json['id'] == null) {
|
||||
id = null;
|
||||
} else {
|
||||
id = json['id'];
|
||||
id = json['id'];
|
||||
}
|
||||
if (json['petId'] == null) {
|
||||
petId = null;
|
||||
} else {
|
||||
petId = json['petId'];
|
||||
petId = json['petId'];
|
||||
}
|
||||
if (json['quantity'] == null) {
|
||||
quantity = null;
|
||||
} else {
|
||||
quantity = json['quantity'];
|
||||
quantity = json['quantity'];
|
||||
}
|
||||
if (json['shipDate'] == null) {
|
||||
shipDate = null;
|
||||
@ -46,12 +46,12 @@ class Order {
|
||||
if (json['status'] == null) {
|
||||
status = null;
|
||||
} else {
|
||||
status = json['status'];
|
||||
status = json['status'];
|
||||
}
|
||||
if (json['complete'] == null) {
|
||||
complete = null;
|
||||
} else {
|
||||
complete = json['complete'];
|
||||
complete = json['complete'];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,7 @@ class Pet {
|
||||
if (json['id'] == null) {
|
||||
id = null;
|
||||
} else {
|
||||
id = json['id'];
|
||||
id = json['id'];
|
||||
}
|
||||
if (json['category'] == null) {
|
||||
category = null;
|
||||
@ -36,12 +36,12 @@ class Pet {
|
||||
if (json['name'] == null) {
|
||||
name = null;
|
||||
} else {
|
||||
name = json['name'];
|
||||
name = json['name'];
|
||||
}
|
||||
if (json['photoUrls'] == null) {
|
||||
photoUrls = null;
|
||||
} else {
|
||||
photoUrls = ((json['photoUrls'] ?? []) as List).map((item) => item as String).toList();
|
||||
photoUrls = (json['photoUrls'] as List).cast<String>();
|
||||
}
|
||||
if (json['tags'] == null) {
|
||||
tags = null;
|
||||
@ -51,7 +51,7 @@ class Pet {
|
||||
if (json['status'] == null) {
|
||||
status = null;
|
||||
} else {
|
||||
status = json['status'];
|
||||
status = json['status'];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,12 +17,12 @@ class Tag {
|
||||
if (json['id'] == null) {
|
||||
id = null;
|
||||
} else {
|
||||
id = json['id'];
|
||||
id = json['id'];
|
||||
}
|
||||
if (json['name'] == null) {
|
||||
name = null;
|
||||
} else {
|
||||
name = json['name'];
|
||||
name = json['name'];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,42 +29,42 @@ class User {
|
||||
if (json['id'] == null) {
|
||||
id = null;
|
||||
} else {
|
||||
id = json['id'];
|
||||
id = json['id'];
|
||||
}
|
||||
if (json['username'] == null) {
|
||||
username = null;
|
||||
} else {
|
||||
username = json['username'];
|
||||
username = json['username'];
|
||||
}
|
||||
if (json['firstName'] == null) {
|
||||
firstName = null;
|
||||
} else {
|
||||
firstName = json['firstName'];
|
||||
firstName = json['firstName'];
|
||||
}
|
||||
if (json['lastName'] == null) {
|
||||
lastName = null;
|
||||
} else {
|
||||
lastName = json['lastName'];
|
||||
lastName = json['lastName'];
|
||||
}
|
||||
if (json['email'] == null) {
|
||||
email = null;
|
||||
} else {
|
||||
email = json['email'];
|
||||
email = json['email'];
|
||||
}
|
||||
if (json['password'] == null) {
|
||||
password = null;
|
||||
} else {
|
||||
password = json['password'];
|
||||
password = json['password'];
|
||||
}
|
||||
if (json['phone'] == null) {
|
||||
phone = null;
|
||||
} else {
|
||||
phone = json['phone'];
|
||||
phone = json['phone'];
|
||||
}
|
||||
if (json['userStatus'] == null) {
|
||||
userStatus = null;
|
||||
} else {
|
||||
userStatus = json['userStatus'];
|
||||
userStatus = json['userStatus'];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ Add a new pet to the store
|
||||
```dart
|
||||
import 'package:openapi/api.dart';
|
||||
// TODO Configure OAuth2 access token for authorization: petstore_auth
|
||||
//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
//defaultApiClient.getAuthentication<OAuth>('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
|
||||
var api_instance = new PetApi();
|
||||
var body = new Pet(); // Pet | Pet object that needs to be added to the store
|
||||
@ -70,7 +70,7 @@ Deletes a pet
|
||||
```dart
|
||||
import 'package:openapi/api.dart';
|
||||
// TODO Configure OAuth2 access token for authorization: petstore_auth
|
||||
//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
//defaultApiClient.getAuthentication<OAuth>('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
|
||||
var api_instance = new PetApi();
|
||||
var petId = 789; // int | Pet id to delete
|
||||
@ -116,7 +116,7 @@ Multiple status values can be provided with comma separated strings
|
||||
```dart
|
||||
import 'package:openapi/api.dart';
|
||||
// TODO Configure OAuth2 access token for authorization: petstore_auth
|
||||
//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
//defaultApiClient.getAuthentication<OAuth>('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
|
||||
var api_instance = new PetApi();
|
||||
var status = []; // List<String> | Status values that need to be considered for filter
|
||||
@ -161,7 +161,7 @@ Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3
|
||||
```dart
|
||||
import 'package:openapi/api.dart';
|
||||
// TODO Configure OAuth2 access token for authorization: petstore_auth
|
||||
//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
//defaultApiClient.getAuthentication<OAuth>('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
|
||||
var api_instance = new PetApi();
|
||||
var tags = []; // List<String> | Tags to filter by
|
||||
@ -206,9 +206,9 @@ Returns a single pet
|
||||
```dart
|
||||
import 'package:openapi/api.dart';
|
||||
// TODO Configure API key authorization: api_key
|
||||
//openapi.api.Configuration.apiKey{'api_key'} = 'YOUR_API_KEY';
|
||||
//defaultApiClient.getAuthentication<ApiKeyAuth>('api_key').apiKey = 'YOUR_API_KEY';
|
||||
// uncomment below to setup prefix (e.g. Bearer) for API key, if needed
|
||||
//openapi.api.Configuration.apiKeyPrefix{'api_key'} = "Bearer";
|
||||
//defaultApiClient.getAuthentication<ApiKeyAuth>('api_key').apiKeyPrefix = 'Bearer';
|
||||
|
||||
var api_instance = new PetApi();
|
||||
var petId = 789; // int | ID of pet to return
|
||||
@ -251,7 +251,7 @@ Update an existing pet
|
||||
```dart
|
||||
import 'package:openapi/api.dart';
|
||||
// TODO Configure OAuth2 access token for authorization: petstore_auth
|
||||
//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
//defaultApiClient.getAuthentication<OAuth>('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
|
||||
var api_instance = new PetApi();
|
||||
var body = new Pet(); // Pet | Pet object that needs to be added to the store
|
||||
@ -293,7 +293,7 @@ Updates a pet in the store with form data
|
||||
```dart
|
||||
import 'package:openapi/api.dart';
|
||||
// TODO Configure OAuth2 access token for authorization: petstore_auth
|
||||
//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
//defaultApiClient.getAuthentication<OAuth>('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
|
||||
var api_instance = new PetApi();
|
||||
var petId = 789; // int | ID of pet that needs to be updated
|
||||
@ -339,7 +339,7 @@ uploads an image
|
||||
```dart
|
||||
import 'package:openapi/api.dart';
|
||||
// TODO Configure OAuth2 access token for authorization: petstore_auth
|
||||
//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
//defaultApiClient.getAuthentication<OAuth>('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN';
|
||||
|
||||
var api_instance = new PetApi();
|
||||
var petId = 789; // int | ID of pet to update
|
||||
|
@ -68,9 +68,9 @@ Returns a map of status codes to quantities
|
||||
```dart
|
||||
import 'package:openapi/api.dart';
|
||||
// TODO Configure API key authorization: api_key
|
||||
//openapi.api.Configuration.apiKey{'api_key'} = 'YOUR_API_KEY';
|
||||
//defaultApiClient.getAuthentication<ApiKeyAuth>('api_key').apiKey = 'YOUR_API_KEY';
|
||||
// uncomment below to setup prefix (e.g. Bearer) for API key, if needed
|
||||
//openapi.api.Configuration.apiKeyPrefix{'api_key'} = "Bearer";
|
||||
//defaultApiClient.getAuthentication<ApiKeyAuth>('api_key').apiKeyPrefix = 'Bearer';
|
||||
|
||||
var api_instance = new StoreApi();
|
||||
|
||||
|
@ -50,7 +50,7 @@ class PetApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
} else {
|
||||
return;
|
||||
@ -100,7 +100,7 @@ class PetApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
} else {
|
||||
return;
|
||||
@ -150,9 +150,9 @@ class PetApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
return (apiClient.deserialize(response.body, 'List<Pet>') as List).map((item) => item as Pet).toList();
|
||||
return (apiClient.deserialize(_decodeBodyBytes(response), 'List<Pet>') as List).map((item) => item as Pet).toList();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@ -201,9 +201,9 @@ class PetApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
return (apiClient.deserialize(response.body, 'List<Pet>') as List).map((item) => item as Pet).toList();
|
||||
return (apiClient.deserialize(_decodeBodyBytes(response), 'List<Pet>') as List).map((item) => item as Pet).toList();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@ -251,9 +251,9 @@ class PetApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
return apiClient.deserialize(response.body, 'Pet') as Pet;
|
||||
return apiClient.deserialize(_decodeBodyBytes(response), 'Pet') as Pet;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@ -301,7 +301,7 @@ class PetApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
} else {
|
||||
return;
|
||||
@ -362,7 +362,7 @@ class PetApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
} else {
|
||||
return;
|
||||
@ -422,9 +422,9 @@ class PetApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
return apiClient.deserialize(response.body, 'ApiResponse') as ApiResponse;
|
||||
return apiClient.deserialize(_decodeBodyBytes(response), 'ApiResponse') as ApiResponse;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ class StoreApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
} else {
|
||||
return;
|
||||
@ -96,9 +96,9 @@ class StoreApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
return new Map<String, int>.from(apiClient.deserialize(response.body, 'Map<String, int>'));
|
||||
return new Map<String, int>.from(apiClient.deserialize(_decodeBodyBytes(response), 'Map<String, int>'));
|
||||
;
|
||||
} else {
|
||||
return null;
|
||||
@ -147,9 +147,9 @@ class StoreApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
return apiClient.deserialize(response.body, 'Order') as Order;
|
||||
return apiClient.deserialize(_decodeBodyBytes(response), 'Order') as Order;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@ -197,9 +197,9 @@ class StoreApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
return apiClient.deserialize(response.body, 'Order') as Order;
|
||||
return apiClient.deserialize(_decodeBodyBytes(response), 'Order') as Order;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ class UserApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
} else {
|
||||
return;
|
||||
@ -99,7 +99,7 @@ class UserApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
} else {
|
||||
return;
|
||||
@ -148,7 +148,7 @@ class UserApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
} else {
|
||||
return;
|
||||
@ -197,7 +197,7 @@ class UserApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
} else {
|
||||
return;
|
||||
@ -246,9 +246,9 @@ class UserApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
return apiClient.deserialize(response.body, 'User') as User;
|
||||
return apiClient.deserialize(_decodeBodyBytes(response), 'User') as User;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@ -301,9 +301,9 @@ class UserApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
return apiClient.deserialize(response.body, 'String') as String;
|
||||
return apiClient.deserialize(_decodeBodyBytes(response), 'String') as String;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@ -348,7 +348,7 @@ class UserApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
} else {
|
||||
return;
|
||||
@ -400,7 +400,7 @@ class UserApi {
|
||||
authNames);
|
||||
|
||||
if(response.statusCode >= 400) {
|
||||
throw new ApiException(response.statusCode, response.body);
|
||||
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||
} else if(response.body != null) {
|
||||
} else {
|
||||
return;
|
||||
|
@ -105,7 +105,10 @@ class ApiClient {
|
||||
|
||||
_updateParamsForAuth(authNames, queryParams, headerParams);
|
||||
|
||||
var ps = queryParams.where((p) => p.value != null).map((p) => '${p.name}=${p.value}');
|
||||
var ps = queryParams
|
||||
.where((p) => p.value != null)
|
||||
.map((p) => '${p.name}=${Uri.encodeQueryComponent(p.value)}');
|
||||
|
||||
String queryString = ps.isNotEmpty ?
|
||||
'?' + ps.join('&') :
|
||||
'';
|
||||
@ -150,11 +153,9 @@ class ApiClient {
|
||||
});
|
||||
}
|
||||
|
||||
void setAccessToken(String accessToken) {
|
||||
_authentications.forEach((key, auth) {
|
||||
if (auth is OAuth) {
|
||||
auth.setAccessToken(accessToken);
|
||||
}
|
||||
});
|
||||
T getAuthentication<T extends Authentication>(String name) {
|
||||
var authentication = _authentications[name];
|
||||
|
||||
return authentication is T ? authentication : null;
|
||||
}
|
||||
}
|
||||
|
@ -42,3 +42,15 @@ String parameterToString(dynamic value) {
|
||||
return value.toString();
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the decoded body by utf-8 if application/json with the given headers.
|
||||
/// Else, returns the decoded body by default algorithm of dart:http.
|
||||
/// Because avoid to text garbling when header only contains "application/json" without "; charset=utf-8".
|
||||
String _decodeBodyBytes(Response response) {
|
||||
var contentType = response.headers['content-type'];
|
||||
if (contentType != null && contentType.contains("application/json")) {
|
||||
return utf8.decode(response.bodyBytes);
|
||||
} else {
|
||||
return response.body;
|
||||
}
|
||||
}
|
||||
|
@ -4,18 +4,20 @@ class ApiKeyAuth implements Authentication {
|
||||
|
||||
final String location;
|
||||
final String paramName;
|
||||
String apiKey;
|
||||
String _apiKey;
|
||||
String apiKeyPrefix;
|
||||
|
||||
set apiKey(String key) => _apiKey = key;
|
||||
|
||||
ApiKeyAuth(this.location, this.paramName);
|
||||
|
||||
@override
|
||||
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
|
||||
String value;
|
||||
if (apiKeyPrefix != null) {
|
||||
value = '$apiKeyPrefix $apiKey';
|
||||
value = '$apiKeyPrefix $_apiKey';
|
||||
} else {
|
||||
value = apiKey;
|
||||
value = _apiKey;
|
||||
}
|
||||
|
||||
if (location == 'query' && value != null) {
|
||||
|
@ -2,13 +2,15 @@ part of openapi.api;
|
||||
|
||||
class HttpBasicAuth implements Authentication {
|
||||
|
||||
String username;
|
||||
String password;
|
||||
String _username;
|
||||
String _password;
|
||||
|
||||
@override
|
||||
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
|
||||
String str = (username == null ? "" : username) + ":" + (password == null ? "" : password);
|
||||
String str = (_username == null ? "" : _username) + ":" + (_password == null ? "" : _password);
|
||||
headerParams["Authorization"] = "Basic " + base64.encode(utf8.encode(str));
|
||||
}
|
||||
|
||||
set username(String username) => _username = username;
|
||||
set password(String password) => _password = password;
|
||||
}
|
||||
|
@ -1,18 +1,16 @@
|
||||
part of openapi.api;
|
||||
|
||||
class OAuth implements Authentication {
|
||||
String accessToken;
|
||||
String _accessToken;
|
||||
|
||||
OAuth({this.accessToken});
|
||||
OAuth({String accessToken}) : _accessToken = accessToken;
|
||||
|
||||
@override
|
||||
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
|
||||
if (accessToken != null) {
|
||||
headerParams["Authorization"] = "Bearer " + accessToken;
|
||||
if (_accessToken != null) {
|
||||
headerParams["Authorization"] = "Bearer $_accessToken";
|
||||
}
|
||||
}
|
||||
|
||||
void setAccessToken(String accessToken) {
|
||||
this.accessToken = accessToken;
|
||||
}
|
||||
set accessToken(String accessToken) => _accessToken = accessToken;
|
||||
}
|
||||
|
@ -19,17 +19,17 @@ class ApiResponse {
|
||||
if (json['code'] == null) {
|
||||
code = null;
|
||||
} else {
|
||||
code = json['code'];
|
||||
code = json['code'];
|
||||
}
|
||||
if (json['type'] == null) {
|
||||
type = null;
|
||||
} else {
|
||||
type = json['type'];
|
||||
type = json['type'];
|
||||
}
|
||||
if (json['message'] == null) {
|
||||
message = null;
|
||||
} else {
|
||||
message = json['message'];
|
||||
message = json['message'];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,12 +17,12 @@ class Category {
|
||||
if (json['id'] == null) {
|
||||
id = null;
|
||||
} else {
|
||||
id = json['id'];
|
||||
id = json['id'];
|
||||
}
|
||||
if (json['name'] == null) {
|
||||
name = null;
|
||||
} else {
|
||||
name = json['name'];
|
||||
name = json['name'];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,17 +26,17 @@ class Order {
|
||||
if (json['id'] == null) {
|
||||
id = null;
|
||||
} else {
|
||||
id = json['id'];
|
||||
id = json['id'];
|
||||
}
|
||||
if (json['petId'] == null) {
|
||||
petId = null;
|
||||
} else {
|
||||
petId = json['petId'];
|
||||
petId = json['petId'];
|
||||
}
|
||||
if (json['quantity'] == null) {
|
||||
quantity = null;
|
||||
} else {
|
||||
quantity = json['quantity'];
|
||||
quantity = json['quantity'];
|
||||
}
|
||||
if (json['shipDate'] == null) {
|
||||
shipDate = null;
|
||||
@ -46,12 +46,12 @@ class Order {
|
||||
if (json['status'] == null) {
|
||||
status = null;
|
||||
} else {
|
||||
status = json['status'];
|
||||
status = json['status'];
|
||||
}
|
||||
if (json['complete'] == null) {
|
||||
complete = null;
|
||||
} else {
|
||||
complete = json['complete'];
|
||||
complete = json['complete'];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,7 @@ class Pet {
|
||||
if (json['id'] == null) {
|
||||
id = null;
|
||||
} else {
|
||||
id = json['id'];
|
||||
id = json['id'];
|
||||
}
|
||||
if (json['category'] == null) {
|
||||
category = null;
|
||||
@ -36,12 +36,12 @@ class Pet {
|
||||
if (json['name'] == null) {
|
||||
name = null;
|
||||
} else {
|
||||
name = json['name'];
|
||||
name = json['name'];
|
||||
}
|
||||
if (json['photoUrls'] == null) {
|
||||
photoUrls = null;
|
||||
} else {
|
||||
photoUrls = ((json['photoUrls'] ?? []) as List).map((item) => item as String).toList();
|
||||
photoUrls = (json['photoUrls'] as List).cast<String>();
|
||||
}
|
||||
if (json['tags'] == null) {
|
||||
tags = null;
|
||||
@ -51,7 +51,7 @@ class Pet {
|
||||
if (json['status'] == null) {
|
||||
status = null;
|
||||
} else {
|
||||
status = json['status'];
|
||||
status = json['status'];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,12 +17,12 @@ class Tag {
|
||||
if (json['id'] == null) {
|
||||
id = null;
|
||||
} else {
|
||||
id = json['id'];
|
||||
id = json['id'];
|
||||
}
|
||||
if (json['name'] == null) {
|
||||
name = null;
|
||||
} else {
|
||||
name = json['name'];
|
||||
name = json['name'];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,42 +29,42 @@ class User {
|
||||
if (json['id'] == null) {
|
||||
id = null;
|
||||
} else {
|
||||
id = json['id'];
|
||||
id = json['id'];
|
||||
}
|
||||
if (json['username'] == null) {
|
||||
username = null;
|
||||
} else {
|
||||
username = json['username'];
|
||||
username = json['username'];
|
||||
}
|
||||
if (json['firstName'] == null) {
|
||||
firstName = null;
|
||||
} else {
|
||||
firstName = json['firstName'];
|
||||
firstName = json['firstName'];
|
||||
}
|
||||
if (json['lastName'] == null) {
|
||||
lastName = null;
|
||||
} else {
|
||||
lastName = json['lastName'];
|
||||
lastName = json['lastName'];
|
||||
}
|
||||
if (json['email'] == null) {
|
||||
email = null;
|
||||
} else {
|
||||
email = json['email'];
|
||||
email = json['email'];
|
||||
}
|
||||
if (json['password'] == null) {
|
||||
password = null;
|
||||
} else {
|
||||
password = json['password'];
|
||||
password = json['password'];
|
||||
}
|
||||
if (json['phone'] == null) {
|
||||
phone = null;
|
||||
} else {
|
||||
phone = json['phone'];
|
||||
phone = json['phone'];
|
||||
}
|
||||
if (json['userStatus'] == null) {
|
||||
userStatus = null;
|
||||
} else {
|
||||
userStatus = json['userStatus'];
|
||||
userStatus = json['userStatus'];
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user