mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-07-03 22:20:56 +00:00
[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}}
|
{{#authMethods}}
|
||||||
{{#isBasic}}
|
{{#isBasic}}
|
||||||
// TODO Configure HTTP basic authorization: {{{name}}}
|
// TODO Configure HTTP basic authorization: {{{name}}}
|
||||||
//{{pubName}}.api.Configuration.username = 'YOUR_USERNAME';
|
//defaultApiClient.getAuthentication<HttpBasicAuth>('{{{name}}}').username = 'YOUR_USERNAME'
|
||||||
//{{pubName}}.api.Configuration.password = 'YOUR_PASSWORD';
|
//defaultApiClient.getAuthentication<HttpBasicAuth>('{{{name}}}').password = 'YOUR_PASSWORD';
|
||||||
{{/isBasic}}
|
{{/isBasic}}
|
||||||
{{#isApiKey}}
|
{{#isApiKey}}
|
||||||
// TODO Configure API key authorization: {{{name}}}
|
// 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
|
// 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}}
|
{{/isApiKey}}
|
||||||
{{#isOAuth}}
|
{{#isOAuth}}
|
||||||
// TODO Configure OAuth2 access token for authorization: {{{name}}}
|
// TODO Configure OAuth2 access token for authorization: {{{name}}}
|
||||||
//{{pubName}}.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN';
|
//defaultApiClient.getAuthentication<OAuth>('{{{name}}}').accessToken = 'YOUR_ACCESS_TOKEN';
|
||||||
{{/isOAuth}}
|
{{/isOAuth}}
|
||||||
{{/authMethods}}
|
{{/authMethods}}
|
||||||
{{/hasAuthMethods}}
|
{{/hasAuthMethods}}
|
||||||
|
@ -157,11 +157,9 @@ class ApiClient {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void setAccessToken(String accessToken) {
|
T getAuthentication<T extends Authentication>(String name) {
|
||||||
_authentications.forEach((key, auth) {
|
var authentication = _authentications[name];
|
||||||
if (auth is OAuth) {
|
|
||||||
auth.setAccessToken(accessToken);
|
return authentication is T ? authentication : null;
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,18 +29,18 @@ import 'package:{{pubName}}/api.dart';
|
|||||||
{{#authMethods}}
|
{{#authMethods}}
|
||||||
{{#isBasic}}
|
{{#isBasic}}
|
||||||
// TODO Configure HTTP basic authorization: {{{name}}}
|
// TODO Configure HTTP basic authorization: {{{name}}}
|
||||||
//{{pubName}}.api.Configuration.username = 'YOUR_USERNAME';
|
//defaultApiClient.getAuthentication<HttpBasicAuth>('{{{name}}}').username = 'YOUR_USERNAME'
|
||||||
//{{pubName}}.api.Configuration.password = 'YOUR_PASSWORD';
|
//defaultApiClient.getAuthentication<HttpBasicAuth>('{{{name}}}').password = 'YOUR_PASSWORD';
|
||||||
{{/isBasic}}
|
{{/isBasic}}
|
||||||
{{#isApiKey}}
|
{{#isApiKey}}
|
||||||
// TODO Configure API key authorization: {{{name}}}
|
// 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
|
// 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}}
|
{{/isApiKey}}
|
||||||
{{#isOAuth}}
|
{{#isOAuth}}
|
||||||
// TODO Configure OAuth2 access token for authorization: {{{name}}}
|
// TODO Configure OAuth2 access token for authorization: {{{name}}}
|
||||||
//{{pubName}}.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN';
|
//defaultApiClient.getAuthentication<OAuth>('{{{name}}}').accessToken = 'YOUR_ACCESS_TOKEN';
|
||||||
{{/isOAuth}}
|
{{/isOAuth}}
|
||||||
{{/authMethods}}
|
{{/authMethods}}
|
||||||
{{/hasAuthMethods}}
|
{{/hasAuthMethods}}
|
||||||
|
@ -4,18 +4,20 @@ class ApiKeyAuth implements Authentication {
|
|||||||
|
|
||||||
final String location;
|
final String location;
|
||||||
final String paramName;
|
final String paramName;
|
||||||
String apiKey;
|
String _apiKey;
|
||||||
String apiKeyPrefix;
|
String apiKeyPrefix;
|
||||||
|
|
||||||
|
set apiKey(String key) => _apiKey = key;
|
||||||
|
|
||||||
ApiKeyAuth(this.location, this.paramName);
|
ApiKeyAuth(this.location, this.paramName);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
|
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
|
||||||
String value;
|
String value;
|
||||||
if (apiKeyPrefix != null) {
|
if (apiKeyPrefix != null) {
|
||||||
value = '$apiKeyPrefix $apiKey';
|
value = '$apiKeyPrefix $_apiKey';
|
||||||
} else {
|
} else {
|
||||||
value = apiKey;
|
value = _apiKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (location == 'query' && value != null) {
|
if (location == 'query' && value != null) {
|
||||||
|
@ -2,13 +2,15 @@ part of {{pubName}}.api;
|
|||||||
|
|
||||||
class HttpBasicAuth implements Authentication {
|
class HttpBasicAuth implements Authentication {
|
||||||
|
|
||||||
String username;
|
String _username;
|
||||||
String password;
|
String _password;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
|
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));
|
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;
|
part of {{pubName}}.api;
|
||||||
|
|
||||||
class OAuth implements Authentication {
|
class OAuth implements Authentication {
|
||||||
String accessToken;
|
String _accessToken;
|
||||||
|
|
||||||
OAuth({this.accessToken});
|
OAuth({String accessToken}) : _accessToken = accessToken;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
|
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
|
||||||
if (accessToken != null) {
|
if (_accessToken != null) {
|
||||||
headerParams["Authorization"] = "Bearer " + accessToken;
|
headerParams["Authorization"] = "Bearer $_accessToken";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setAccessToken(String accessToken) {
|
set accessToken(String accessToken) => _accessToken = accessToken;
|
||||||
this.accessToken = accessToken;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ Add a new pet to the store
|
|||||||
```dart
|
```dart
|
||||||
import 'package:openapi/api.dart';
|
import 'package:openapi/api.dart';
|
||||||
// TODO Configure OAuth2 access token for authorization: petstore_auth
|
// 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 api_instance = new PetApi();
|
||||||
var body = new Pet(); // Pet | Pet object that needs to be added to the store
|
var body = new Pet(); // Pet | Pet object that needs to be added to the store
|
||||||
@ -70,7 +70,7 @@ Deletes a pet
|
|||||||
```dart
|
```dart
|
||||||
import 'package:openapi/api.dart';
|
import 'package:openapi/api.dart';
|
||||||
// TODO Configure OAuth2 access token for authorization: petstore_auth
|
// 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 api_instance = new PetApi();
|
||||||
var petId = 789; // int | Pet id to delete
|
var petId = 789; // int | Pet id to delete
|
||||||
@ -116,7 +116,7 @@ Multiple status values can be provided with comma separated strings
|
|||||||
```dart
|
```dart
|
||||||
import 'package:openapi/api.dart';
|
import 'package:openapi/api.dart';
|
||||||
// TODO Configure OAuth2 access token for authorization: petstore_auth
|
// 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 api_instance = new PetApi();
|
||||||
var status = []; // List<String> | Status values that need to be considered for filter
|
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
|
```dart
|
||||||
import 'package:openapi/api.dart';
|
import 'package:openapi/api.dart';
|
||||||
// TODO Configure OAuth2 access token for authorization: petstore_auth
|
// 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 api_instance = new PetApi();
|
||||||
var tags = []; // List<String> | Tags to filter by
|
var tags = []; // List<String> | Tags to filter by
|
||||||
@ -206,9 +206,9 @@ Returns a single pet
|
|||||||
```dart
|
```dart
|
||||||
import 'package:openapi/api.dart';
|
import 'package:openapi/api.dart';
|
||||||
// TODO Configure API key authorization: api_key
|
// 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
|
// 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 api_instance = new PetApi();
|
||||||
var petId = 789; // int | ID of pet to return
|
var petId = 789; // int | ID of pet to return
|
||||||
@ -251,7 +251,7 @@ Update an existing pet
|
|||||||
```dart
|
```dart
|
||||||
import 'package:openapi/api.dart';
|
import 'package:openapi/api.dart';
|
||||||
// TODO Configure OAuth2 access token for authorization: petstore_auth
|
// 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 api_instance = new PetApi();
|
||||||
var body = new Pet(); // Pet | Pet object that needs to be added to the store
|
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
|
```dart
|
||||||
import 'package:openapi/api.dart';
|
import 'package:openapi/api.dart';
|
||||||
// TODO Configure OAuth2 access token for authorization: petstore_auth
|
// 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 api_instance = new PetApi();
|
||||||
var petId = 789; // int | ID of pet that needs to be updated
|
var petId = 789; // int | ID of pet that needs to be updated
|
||||||
@ -339,7 +339,7 @@ uploads an image
|
|||||||
```dart
|
```dart
|
||||||
import 'package:openapi/api.dart';
|
import 'package:openapi/api.dart';
|
||||||
// TODO Configure OAuth2 access token for authorization: petstore_auth
|
// 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 api_instance = new PetApi();
|
||||||
var petId = 789; // int | ID of pet to update
|
var petId = 789; // int | ID of pet to update
|
||||||
|
@ -68,9 +68,9 @@ Returns a map of status codes to quantities
|
|||||||
```dart
|
```dart
|
||||||
import 'package:openapi/api.dart';
|
import 'package:openapi/api.dart';
|
||||||
// TODO Configure API key authorization: api_key
|
// 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
|
// 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();
|
var api_instance = new StoreApi();
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ class PetApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
@ -100,7 +100,7 @@ class PetApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
@ -150,9 +150,9 @@ class PetApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} 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 {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -201,9 +201,9 @@ class PetApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} 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 {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -251,9 +251,9 @@ class PetApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
return apiClient.deserialize(response.body, 'Pet') as Pet;
|
return apiClient.deserialize(_decodeBodyBytes(response), 'Pet') as Pet;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -301,7 +301,7 @@ class PetApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
@ -362,7 +362,7 @@ class PetApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
@ -422,9 +422,9 @@ class PetApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
return apiClient.deserialize(response.body, 'ApiResponse') as ApiResponse;
|
return apiClient.deserialize(_decodeBodyBytes(response), 'ApiResponse') as ApiResponse;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ class StoreApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
@ -96,9 +96,9 @@ class StoreApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} 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 {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
@ -147,9 +147,9 @@ class StoreApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
return apiClient.deserialize(response.body, 'Order') as Order;
|
return apiClient.deserialize(_decodeBodyBytes(response), 'Order') as Order;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -197,9 +197,9 @@ class StoreApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
return apiClient.deserialize(response.body, 'Order') as Order;
|
return apiClient.deserialize(_decodeBodyBytes(response), 'Order') as Order;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ class UserApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
@ -99,7 +99,7 @@ class UserApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
@ -148,7 +148,7 @@ class UserApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
@ -197,7 +197,7 @@ class UserApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
@ -246,9 +246,9 @@ class UserApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
return apiClient.deserialize(response.body, 'User') as User;
|
return apiClient.deserialize(_decodeBodyBytes(response), 'User') as User;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -301,9 +301,9 @@ class UserApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
return apiClient.deserialize(response.body, 'String') as String;
|
return apiClient.deserialize(_decodeBodyBytes(response), 'String') as String;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -348,7 +348,7 @@ class UserApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
@ -400,7 +400,7 @@ class UserApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
|
@ -105,7 +105,10 @@ class ApiClient {
|
|||||||
|
|
||||||
_updateParamsForAuth(authNames, queryParams, headerParams);
|
_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 ?
|
String queryString = ps.isNotEmpty ?
|
||||||
'?' + ps.join('&') :
|
'?' + ps.join('&') :
|
||||||
'';
|
'';
|
||||||
@ -150,11 +153,9 @@ class ApiClient {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void setAccessToken(String accessToken) {
|
T getAuthentication<T extends Authentication>(String name) {
|
||||||
_authentications.forEach((key, auth) {
|
var authentication = _authentications[name];
|
||||||
if (auth is OAuth) {
|
|
||||||
auth.setAccessToken(accessToken);
|
return authentication is T ? authentication : null;
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,3 +42,15 @@ String parameterToString(dynamic value) {
|
|||||||
return value.toString();
|
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 location;
|
||||||
final String paramName;
|
final String paramName;
|
||||||
String apiKey;
|
String _apiKey;
|
||||||
String apiKeyPrefix;
|
String apiKeyPrefix;
|
||||||
|
|
||||||
|
set apiKey(String key) => _apiKey = key;
|
||||||
|
|
||||||
ApiKeyAuth(this.location, this.paramName);
|
ApiKeyAuth(this.location, this.paramName);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
|
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
|
||||||
String value;
|
String value;
|
||||||
if (apiKeyPrefix != null) {
|
if (apiKeyPrefix != null) {
|
||||||
value = '$apiKeyPrefix $apiKey';
|
value = '$apiKeyPrefix $_apiKey';
|
||||||
} else {
|
} else {
|
||||||
value = apiKey;
|
value = _apiKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (location == 'query' && value != null) {
|
if (location == 'query' && value != null) {
|
||||||
|
@ -2,13 +2,15 @@ part of openapi.api;
|
|||||||
|
|
||||||
class HttpBasicAuth implements Authentication {
|
class HttpBasicAuth implements Authentication {
|
||||||
|
|
||||||
String username;
|
String _username;
|
||||||
String password;
|
String _password;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
|
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));
|
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;
|
part of openapi.api;
|
||||||
|
|
||||||
class OAuth implements Authentication {
|
class OAuth implements Authentication {
|
||||||
String accessToken;
|
String _accessToken;
|
||||||
|
|
||||||
OAuth({this.accessToken});
|
OAuth({String accessToken}) : _accessToken = accessToken;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
|
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
|
||||||
if (accessToken != null) {
|
if (_accessToken != null) {
|
||||||
headerParams["Authorization"] = "Bearer " + accessToken;
|
headerParams["Authorization"] = "Bearer $_accessToken";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setAccessToken(String accessToken) {
|
set accessToken(String accessToken) => _accessToken = accessToken;
|
||||||
this.accessToken = accessToken;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -19,17 +19,17 @@ class ApiResponse {
|
|||||||
if (json['code'] == null) {
|
if (json['code'] == null) {
|
||||||
code = null;
|
code = null;
|
||||||
} else {
|
} else {
|
||||||
code = json['code'];
|
code = json['code'];
|
||||||
}
|
}
|
||||||
if (json['type'] == null) {
|
if (json['type'] == null) {
|
||||||
type = null;
|
type = null;
|
||||||
} else {
|
} else {
|
||||||
type = json['type'];
|
type = json['type'];
|
||||||
}
|
}
|
||||||
if (json['message'] == null) {
|
if (json['message'] == null) {
|
||||||
message = null;
|
message = null;
|
||||||
} else {
|
} else {
|
||||||
message = json['message'];
|
message = json['message'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,12 +17,12 @@ class Category {
|
|||||||
if (json['id'] == null) {
|
if (json['id'] == null) {
|
||||||
id = null;
|
id = null;
|
||||||
} else {
|
} else {
|
||||||
id = json['id'];
|
id = json['id'];
|
||||||
}
|
}
|
||||||
if (json['name'] == null) {
|
if (json['name'] == null) {
|
||||||
name = null;
|
name = null;
|
||||||
} else {
|
} else {
|
||||||
name = json['name'];
|
name = json['name'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,17 +26,17 @@ class Order {
|
|||||||
if (json['id'] == null) {
|
if (json['id'] == null) {
|
||||||
id = null;
|
id = null;
|
||||||
} else {
|
} else {
|
||||||
id = json['id'];
|
id = json['id'];
|
||||||
}
|
}
|
||||||
if (json['petId'] == null) {
|
if (json['petId'] == null) {
|
||||||
petId = null;
|
petId = null;
|
||||||
} else {
|
} else {
|
||||||
petId = json['petId'];
|
petId = json['petId'];
|
||||||
}
|
}
|
||||||
if (json['quantity'] == null) {
|
if (json['quantity'] == null) {
|
||||||
quantity = null;
|
quantity = null;
|
||||||
} else {
|
} else {
|
||||||
quantity = json['quantity'];
|
quantity = json['quantity'];
|
||||||
}
|
}
|
||||||
if (json['shipDate'] == null) {
|
if (json['shipDate'] == null) {
|
||||||
shipDate = null;
|
shipDate = null;
|
||||||
@ -46,12 +46,12 @@ class Order {
|
|||||||
if (json['status'] == null) {
|
if (json['status'] == null) {
|
||||||
status = null;
|
status = null;
|
||||||
} else {
|
} else {
|
||||||
status = json['status'];
|
status = json['status'];
|
||||||
}
|
}
|
||||||
if (json['complete'] == null) {
|
if (json['complete'] == null) {
|
||||||
complete = null;
|
complete = null;
|
||||||
} else {
|
} else {
|
||||||
complete = json['complete'];
|
complete = json['complete'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ class Pet {
|
|||||||
if (json['id'] == null) {
|
if (json['id'] == null) {
|
||||||
id = null;
|
id = null;
|
||||||
} else {
|
} else {
|
||||||
id = json['id'];
|
id = json['id'];
|
||||||
}
|
}
|
||||||
if (json['category'] == null) {
|
if (json['category'] == null) {
|
||||||
category = null;
|
category = null;
|
||||||
@ -36,12 +36,12 @@ class Pet {
|
|||||||
if (json['name'] == null) {
|
if (json['name'] == null) {
|
||||||
name = null;
|
name = null;
|
||||||
} else {
|
} else {
|
||||||
name = json['name'];
|
name = json['name'];
|
||||||
}
|
}
|
||||||
if (json['photoUrls'] == null) {
|
if (json['photoUrls'] == null) {
|
||||||
photoUrls = null;
|
photoUrls = null;
|
||||||
} else {
|
} else {
|
||||||
photoUrls = ((json['photoUrls'] ?? []) as List).map((item) => item as String).toList();
|
photoUrls = (json['photoUrls'] as List).cast<String>();
|
||||||
}
|
}
|
||||||
if (json['tags'] == null) {
|
if (json['tags'] == null) {
|
||||||
tags = null;
|
tags = null;
|
||||||
@ -51,7 +51,7 @@ class Pet {
|
|||||||
if (json['status'] == null) {
|
if (json['status'] == null) {
|
||||||
status = null;
|
status = null;
|
||||||
} else {
|
} else {
|
||||||
status = json['status'];
|
status = json['status'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,12 +17,12 @@ class Tag {
|
|||||||
if (json['id'] == null) {
|
if (json['id'] == null) {
|
||||||
id = null;
|
id = null;
|
||||||
} else {
|
} else {
|
||||||
id = json['id'];
|
id = json['id'];
|
||||||
}
|
}
|
||||||
if (json['name'] == null) {
|
if (json['name'] == null) {
|
||||||
name = null;
|
name = null;
|
||||||
} else {
|
} else {
|
||||||
name = json['name'];
|
name = json['name'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,42 +29,42 @@ class User {
|
|||||||
if (json['id'] == null) {
|
if (json['id'] == null) {
|
||||||
id = null;
|
id = null;
|
||||||
} else {
|
} else {
|
||||||
id = json['id'];
|
id = json['id'];
|
||||||
}
|
}
|
||||||
if (json['username'] == null) {
|
if (json['username'] == null) {
|
||||||
username = null;
|
username = null;
|
||||||
} else {
|
} else {
|
||||||
username = json['username'];
|
username = json['username'];
|
||||||
}
|
}
|
||||||
if (json['firstName'] == null) {
|
if (json['firstName'] == null) {
|
||||||
firstName = null;
|
firstName = null;
|
||||||
} else {
|
} else {
|
||||||
firstName = json['firstName'];
|
firstName = json['firstName'];
|
||||||
}
|
}
|
||||||
if (json['lastName'] == null) {
|
if (json['lastName'] == null) {
|
||||||
lastName = null;
|
lastName = null;
|
||||||
} else {
|
} else {
|
||||||
lastName = json['lastName'];
|
lastName = json['lastName'];
|
||||||
}
|
}
|
||||||
if (json['email'] == null) {
|
if (json['email'] == null) {
|
||||||
email = null;
|
email = null;
|
||||||
} else {
|
} else {
|
||||||
email = json['email'];
|
email = json['email'];
|
||||||
}
|
}
|
||||||
if (json['password'] == null) {
|
if (json['password'] == null) {
|
||||||
password = null;
|
password = null;
|
||||||
} else {
|
} else {
|
||||||
password = json['password'];
|
password = json['password'];
|
||||||
}
|
}
|
||||||
if (json['phone'] == null) {
|
if (json['phone'] == null) {
|
||||||
phone = null;
|
phone = null;
|
||||||
} else {
|
} else {
|
||||||
phone = json['phone'];
|
phone = json['phone'];
|
||||||
}
|
}
|
||||||
if (json['userStatus'] == null) {
|
if (json['userStatus'] == null) {
|
||||||
userStatus = null;
|
userStatus = null;
|
||||||
} else {
|
} else {
|
||||||
userStatus = json['userStatus'];
|
userStatus = json['userStatus'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ Add a new pet to the store
|
|||||||
```dart
|
```dart
|
||||||
import 'package:openapi/api.dart';
|
import 'package:openapi/api.dart';
|
||||||
// TODO Configure OAuth2 access token for authorization: petstore_auth
|
// 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 api_instance = new PetApi();
|
||||||
var body = new Pet(); // Pet | Pet object that needs to be added to the store
|
var body = new Pet(); // Pet | Pet object that needs to be added to the store
|
||||||
@ -70,7 +70,7 @@ Deletes a pet
|
|||||||
```dart
|
```dart
|
||||||
import 'package:openapi/api.dart';
|
import 'package:openapi/api.dart';
|
||||||
// TODO Configure OAuth2 access token for authorization: petstore_auth
|
// 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 api_instance = new PetApi();
|
||||||
var petId = 789; // int | Pet id to delete
|
var petId = 789; // int | Pet id to delete
|
||||||
@ -116,7 +116,7 @@ Multiple status values can be provided with comma separated strings
|
|||||||
```dart
|
```dart
|
||||||
import 'package:openapi/api.dart';
|
import 'package:openapi/api.dart';
|
||||||
// TODO Configure OAuth2 access token for authorization: petstore_auth
|
// 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 api_instance = new PetApi();
|
||||||
var status = []; // List<String> | Status values that need to be considered for filter
|
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
|
```dart
|
||||||
import 'package:openapi/api.dart';
|
import 'package:openapi/api.dart';
|
||||||
// TODO Configure OAuth2 access token for authorization: petstore_auth
|
// 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 api_instance = new PetApi();
|
||||||
var tags = []; // List<String> | Tags to filter by
|
var tags = []; // List<String> | Tags to filter by
|
||||||
@ -206,9 +206,9 @@ Returns a single pet
|
|||||||
```dart
|
```dart
|
||||||
import 'package:openapi/api.dart';
|
import 'package:openapi/api.dart';
|
||||||
// TODO Configure API key authorization: api_key
|
// 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
|
// 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 api_instance = new PetApi();
|
||||||
var petId = 789; // int | ID of pet to return
|
var petId = 789; // int | ID of pet to return
|
||||||
@ -251,7 +251,7 @@ Update an existing pet
|
|||||||
```dart
|
```dart
|
||||||
import 'package:openapi/api.dart';
|
import 'package:openapi/api.dart';
|
||||||
// TODO Configure OAuth2 access token for authorization: petstore_auth
|
// 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 api_instance = new PetApi();
|
||||||
var body = new Pet(); // Pet | Pet object that needs to be added to the store
|
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
|
```dart
|
||||||
import 'package:openapi/api.dart';
|
import 'package:openapi/api.dart';
|
||||||
// TODO Configure OAuth2 access token for authorization: petstore_auth
|
// 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 api_instance = new PetApi();
|
||||||
var petId = 789; // int | ID of pet that needs to be updated
|
var petId = 789; // int | ID of pet that needs to be updated
|
||||||
@ -339,7 +339,7 @@ uploads an image
|
|||||||
```dart
|
```dart
|
||||||
import 'package:openapi/api.dart';
|
import 'package:openapi/api.dart';
|
||||||
// TODO Configure OAuth2 access token for authorization: petstore_auth
|
// 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 api_instance = new PetApi();
|
||||||
var petId = 789; // int | ID of pet to update
|
var petId = 789; // int | ID of pet to update
|
||||||
|
@ -68,9 +68,9 @@ Returns a map of status codes to quantities
|
|||||||
```dart
|
```dart
|
||||||
import 'package:openapi/api.dart';
|
import 'package:openapi/api.dart';
|
||||||
// TODO Configure API key authorization: api_key
|
// 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
|
// 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();
|
var api_instance = new StoreApi();
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ class PetApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
@ -100,7 +100,7 @@ class PetApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
@ -150,9 +150,9 @@ class PetApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} 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 {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -201,9 +201,9 @@ class PetApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} 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 {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -251,9 +251,9 @@ class PetApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
return apiClient.deserialize(response.body, 'Pet') as Pet;
|
return apiClient.deserialize(_decodeBodyBytes(response), 'Pet') as Pet;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -301,7 +301,7 @@ class PetApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
@ -362,7 +362,7 @@ class PetApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
@ -422,9 +422,9 @@ class PetApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
return apiClient.deserialize(response.body, 'ApiResponse') as ApiResponse;
|
return apiClient.deserialize(_decodeBodyBytes(response), 'ApiResponse') as ApiResponse;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ class StoreApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
@ -96,9 +96,9 @@ class StoreApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} 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 {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
@ -147,9 +147,9 @@ class StoreApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
return apiClient.deserialize(response.body, 'Order') as Order;
|
return apiClient.deserialize(_decodeBodyBytes(response), 'Order') as Order;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -197,9 +197,9 @@ class StoreApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
return apiClient.deserialize(response.body, 'Order') as Order;
|
return apiClient.deserialize(_decodeBodyBytes(response), 'Order') as Order;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ class UserApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
@ -99,7 +99,7 @@ class UserApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
@ -148,7 +148,7 @@ class UserApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
@ -197,7 +197,7 @@ class UserApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
@ -246,9 +246,9 @@ class UserApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
return apiClient.deserialize(response.body, 'User') as User;
|
return apiClient.deserialize(_decodeBodyBytes(response), 'User') as User;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -301,9 +301,9 @@ class UserApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
return apiClient.deserialize(response.body, 'String') as String;
|
return apiClient.deserialize(_decodeBodyBytes(response), 'String') as String;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -348,7 +348,7 @@ class UserApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
@ -400,7 +400,7 @@ class UserApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
|
@ -105,7 +105,10 @@ class ApiClient {
|
|||||||
|
|
||||||
_updateParamsForAuth(authNames, queryParams, headerParams);
|
_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 ?
|
String queryString = ps.isNotEmpty ?
|
||||||
'?' + ps.join('&') :
|
'?' + ps.join('&') :
|
||||||
'';
|
'';
|
||||||
@ -150,11 +153,9 @@ class ApiClient {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void setAccessToken(String accessToken) {
|
T getAuthentication<T extends Authentication>(String name) {
|
||||||
_authentications.forEach((key, auth) {
|
var authentication = _authentications[name];
|
||||||
if (auth is OAuth) {
|
|
||||||
auth.setAccessToken(accessToken);
|
return authentication is T ? authentication : null;
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,3 +42,15 @@ String parameterToString(dynamic value) {
|
|||||||
return value.toString();
|
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 location;
|
||||||
final String paramName;
|
final String paramName;
|
||||||
String apiKey;
|
String _apiKey;
|
||||||
String apiKeyPrefix;
|
String apiKeyPrefix;
|
||||||
|
|
||||||
|
set apiKey(String key) => _apiKey = key;
|
||||||
|
|
||||||
ApiKeyAuth(this.location, this.paramName);
|
ApiKeyAuth(this.location, this.paramName);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
|
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
|
||||||
String value;
|
String value;
|
||||||
if (apiKeyPrefix != null) {
|
if (apiKeyPrefix != null) {
|
||||||
value = '$apiKeyPrefix $apiKey';
|
value = '$apiKeyPrefix $_apiKey';
|
||||||
} else {
|
} else {
|
||||||
value = apiKey;
|
value = _apiKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (location == 'query' && value != null) {
|
if (location == 'query' && value != null) {
|
||||||
|
@ -2,13 +2,15 @@ part of openapi.api;
|
|||||||
|
|
||||||
class HttpBasicAuth implements Authentication {
|
class HttpBasicAuth implements Authentication {
|
||||||
|
|
||||||
String username;
|
String _username;
|
||||||
String password;
|
String _password;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
|
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));
|
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;
|
part of openapi.api;
|
||||||
|
|
||||||
class OAuth implements Authentication {
|
class OAuth implements Authentication {
|
||||||
String accessToken;
|
String _accessToken;
|
||||||
|
|
||||||
OAuth({this.accessToken});
|
OAuth({String accessToken}) : _accessToken = accessToken;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
|
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
|
||||||
if (accessToken != null) {
|
if (_accessToken != null) {
|
||||||
headerParams["Authorization"] = "Bearer " + accessToken;
|
headerParams["Authorization"] = "Bearer $_accessToken";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setAccessToken(String accessToken) {
|
set accessToken(String accessToken) => _accessToken = accessToken;
|
||||||
this.accessToken = accessToken;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -19,17 +19,17 @@ class ApiResponse {
|
|||||||
if (json['code'] == null) {
|
if (json['code'] == null) {
|
||||||
code = null;
|
code = null;
|
||||||
} else {
|
} else {
|
||||||
code = json['code'];
|
code = json['code'];
|
||||||
}
|
}
|
||||||
if (json['type'] == null) {
|
if (json['type'] == null) {
|
||||||
type = null;
|
type = null;
|
||||||
} else {
|
} else {
|
||||||
type = json['type'];
|
type = json['type'];
|
||||||
}
|
}
|
||||||
if (json['message'] == null) {
|
if (json['message'] == null) {
|
||||||
message = null;
|
message = null;
|
||||||
} else {
|
} else {
|
||||||
message = json['message'];
|
message = json['message'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,12 +17,12 @@ class Category {
|
|||||||
if (json['id'] == null) {
|
if (json['id'] == null) {
|
||||||
id = null;
|
id = null;
|
||||||
} else {
|
} else {
|
||||||
id = json['id'];
|
id = json['id'];
|
||||||
}
|
}
|
||||||
if (json['name'] == null) {
|
if (json['name'] == null) {
|
||||||
name = null;
|
name = null;
|
||||||
} else {
|
} else {
|
||||||
name = json['name'];
|
name = json['name'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,17 +26,17 @@ class Order {
|
|||||||
if (json['id'] == null) {
|
if (json['id'] == null) {
|
||||||
id = null;
|
id = null;
|
||||||
} else {
|
} else {
|
||||||
id = json['id'];
|
id = json['id'];
|
||||||
}
|
}
|
||||||
if (json['petId'] == null) {
|
if (json['petId'] == null) {
|
||||||
petId = null;
|
petId = null;
|
||||||
} else {
|
} else {
|
||||||
petId = json['petId'];
|
petId = json['petId'];
|
||||||
}
|
}
|
||||||
if (json['quantity'] == null) {
|
if (json['quantity'] == null) {
|
||||||
quantity = null;
|
quantity = null;
|
||||||
} else {
|
} else {
|
||||||
quantity = json['quantity'];
|
quantity = json['quantity'];
|
||||||
}
|
}
|
||||||
if (json['shipDate'] == null) {
|
if (json['shipDate'] == null) {
|
||||||
shipDate = null;
|
shipDate = null;
|
||||||
@ -46,12 +46,12 @@ class Order {
|
|||||||
if (json['status'] == null) {
|
if (json['status'] == null) {
|
||||||
status = null;
|
status = null;
|
||||||
} else {
|
} else {
|
||||||
status = json['status'];
|
status = json['status'];
|
||||||
}
|
}
|
||||||
if (json['complete'] == null) {
|
if (json['complete'] == null) {
|
||||||
complete = null;
|
complete = null;
|
||||||
} else {
|
} else {
|
||||||
complete = json['complete'];
|
complete = json['complete'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ class Pet {
|
|||||||
if (json['id'] == null) {
|
if (json['id'] == null) {
|
||||||
id = null;
|
id = null;
|
||||||
} else {
|
} else {
|
||||||
id = json['id'];
|
id = json['id'];
|
||||||
}
|
}
|
||||||
if (json['category'] == null) {
|
if (json['category'] == null) {
|
||||||
category = null;
|
category = null;
|
||||||
@ -36,12 +36,12 @@ class Pet {
|
|||||||
if (json['name'] == null) {
|
if (json['name'] == null) {
|
||||||
name = null;
|
name = null;
|
||||||
} else {
|
} else {
|
||||||
name = json['name'];
|
name = json['name'];
|
||||||
}
|
}
|
||||||
if (json['photoUrls'] == null) {
|
if (json['photoUrls'] == null) {
|
||||||
photoUrls = null;
|
photoUrls = null;
|
||||||
} else {
|
} else {
|
||||||
photoUrls = ((json['photoUrls'] ?? []) as List).map((item) => item as String).toList();
|
photoUrls = (json['photoUrls'] as List).cast<String>();
|
||||||
}
|
}
|
||||||
if (json['tags'] == null) {
|
if (json['tags'] == null) {
|
||||||
tags = null;
|
tags = null;
|
||||||
@ -51,7 +51,7 @@ class Pet {
|
|||||||
if (json['status'] == null) {
|
if (json['status'] == null) {
|
||||||
status = null;
|
status = null;
|
||||||
} else {
|
} else {
|
||||||
status = json['status'];
|
status = json['status'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,12 +17,12 @@ class Tag {
|
|||||||
if (json['id'] == null) {
|
if (json['id'] == null) {
|
||||||
id = null;
|
id = null;
|
||||||
} else {
|
} else {
|
||||||
id = json['id'];
|
id = json['id'];
|
||||||
}
|
}
|
||||||
if (json['name'] == null) {
|
if (json['name'] == null) {
|
||||||
name = null;
|
name = null;
|
||||||
} else {
|
} else {
|
||||||
name = json['name'];
|
name = json['name'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,42 +29,42 @@ class User {
|
|||||||
if (json['id'] == null) {
|
if (json['id'] == null) {
|
||||||
id = null;
|
id = null;
|
||||||
} else {
|
} else {
|
||||||
id = json['id'];
|
id = json['id'];
|
||||||
}
|
}
|
||||||
if (json['username'] == null) {
|
if (json['username'] == null) {
|
||||||
username = null;
|
username = null;
|
||||||
} else {
|
} else {
|
||||||
username = json['username'];
|
username = json['username'];
|
||||||
}
|
}
|
||||||
if (json['firstName'] == null) {
|
if (json['firstName'] == null) {
|
||||||
firstName = null;
|
firstName = null;
|
||||||
} else {
|
} else {
|
||||||
firstName = json['firstName'];
|
firstName = json['firstName'];
|
||||||
}
|
}
|
||||||
if (json['lastName'] == null) {
|
if (json['lastName'] == null) {
|
||||||
lastName = null;
|
lastName = null;
|
||||||
} else {
|
} else {
|
||||||
lastName = json['lastName'];
|
lastName = json['lastName'];
|
||||||
}
|
}
|
||||||
if (json['email'] == null) {
|
if (json['email'] == null) {
|
||||||
email = null;
|
email = null;
|
||||||
} else {
|
} else {
|
||||||
email = json['email'];
|
email = json['email'];
|
||||||
}
|
}
|
||||||
if (json['password'] == null) {
|
if (json['password'] == null) {
|
||||||
password = null;
|
password = null;
|
||||||
} else {
|
} else {
|
||||||
password = json['password'];
|
password = json['password'];
|
||||||
}
|
}
|
||||||
if (json['phone'] == null) {
|
if (json['phone'] == null) {
|
||||||
phone = null;
|
phone = null;
|
||||||
} else {
|
} else {
|
||||||
phone = json['phone'];
|
phone = json['phone'];
|
||||||
}
|
}
|
||||||
if (json['userStatus'] == null) {
|
if (json['userStatus'] == null) {
|
||||||
userStatus = null;
|
userStatus = null;
|
||||||
} else {
|
} else {
|
||||||
userStatus = json['userStatus'];
|
userStatus = json['userStatus'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ Add a new pet to the store
|
|||||||
```dart
|
```dart
|
||||||
import 'package:openapi/api.dart';
|
import 'package:openapi/api.dart';
|
||||||
// TODO Configure OAuth2 access token for authorization: petstore_auth
|
// 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 api_instance = new PetApi();
|
||||||
var body = new Pet(); // Pet | Pet object that needs to be added to the store
|
var body = new Pet(); // Pet | Pet object that needs to be added to the store
|
||||||
@ -70,7 +70,7 @@ Deletes a pet
|
|||||||
```dart
|
```dart
|
||||||
import 'package:openapi/api.dart';
|
import 'package:openapi/api.dart';
|
||||||
// TODO Configure OAuth2 access token for authorization: petstore_auth
|
// 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 api_instance = new PetApi();
|
||||||
var petId = 789; // int | Pet id to delete
|
var petId = 789; // int | Pet id to delete
|
||||||
@ -116,7 +116,7 @@ Multiple status values can be provided with comma separated strings
|
|||||||
```dart
|
```dart
|
||||||
import 'package:openapi/api.dart';
|
import 'package:openapi/api.dart';
|
||||||
// TODO Configure OAuth2 access token for authorization: petstore_auth
|
// 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 api_instance = new PetApi();
|
||||||
var status = []; // List<String> | Status values that need to be considered for filter
|
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
|
```dart
|
||||||
import 'package:openapi/api.dart';
|
import 'package:openapi/api.dart';
|
||||||
// TODO Configure OAuth2 access token for authorization: petstore_auth
|
// 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 api_instance = new PetApi();
|
||||||
var tags = []; // List<String> | Tags to filter by
|
var tags = []; // List<String> | Tags to filter by
|
||||||
@ -206,9 +206,9 @@ Returns a single pet
|
|||||||
```dart
|
```dart
|
||||||
import 'package:openapi/api.dart';
|
import 'package:openapi/api.dart';
|
||||||
// TODO Configure API key authorization: api_key
|
// 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
|
// 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 api_instance = new PetApi();
|
||||||
var petId = 789; // int | ID of pet to return
|
var petId = 789; // int | ID of pet to return
|
||||||
@ -251,7 +251,7 @@ Update an existing pet
|
|||||||
```dart
|
```dart
|
||||||
import 'package:openapi/api.dart';
|
import 'package:openapi/api.dart';
|
||||||
// TODO Configure OAuth2 access token for authorization: petstore_auth
|
// 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 api_instance = new PetApi();
|
||||||
var body = new Pet(); // Pet | Pet object that needs to be added to the store
|
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
|
```dart
|
||||||
import 'package:openapi/api.dart';
|
import 'package:openapi/api.dart';
|
||||||
// TODO Configure OAuth2 access token for authorization: petstore_auth
|
// 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 api_instance = new PetApi();
|
||||||
var petId = 789; // int | ID of pet that needs to be updated
|
var petId = 789; // int | ID of pet that needs to be updated
|
||||||
@ -339,7 +339,7 @@ uploads an image
|
|||||||
```dart
|
```dart
|
||||||
import 'package:openapi/api.dart';
|
import 'package:openapi/api.dart';
|
||||||
// TODO Configure OAuth2 access token for authorization: petstore_auth
|
// 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 api_instance = new PetApi();
|
||||||
var petId = 789; // int | ID of pet to update
|
var petId = 789; // int | ID of pet to update
|
||||||
|
@ -68,9 +68,9 @@ Returns a map of status codes to quantities
|
|||||||
```dart
|
```dart
|
||||||
import 'package:openapi/api.dart';
|
import 'package:openapi/api.dart';
|
||||||
// TODO Configure API key authorization: api_key
|
// 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
|
// 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();
|
var api_instance = new StoreApi();
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ class PetApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
@ -100,7 +100,7 @@ class PetApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
@ -150,9 +150,9 @@ class PetApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} 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 {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -201,9 +201,9 @@ class PetApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} 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 {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -251,9 +251,9 @@ class PetApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
return apiClient.deserialize(response.body, 'Pet') as Pet;
|
return apiClient.deserialize(_decodeBodyBytes(response), 'Pet') as Pet;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -301,7 +301,7 @@ class PetApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
@ -362,7 +362,7 @@ class PetApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
@ -422,9 +422,9 @@ class PetApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
return apiClient.deserialize(response.body, 'ApiResponse') as ApiResponse;
|
return apiClient.deserialize(_decodeBodyBytes(response), 'ApiResponse') as ApiResponse;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ class StoreApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
@ -96,9 +96,9 @@ class StoreApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} 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 {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
@ -147,9 +147,9 @@ class StoreApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
return apiClient.deserialize(response.body, 'Order') as Order;
|
return apiClient.deserialize(_decodeBodyBytes(response), 'Order') as Order;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -197,9 +197,9 @@ class StoreApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
return apiClient.deserialize(response.body, 'Order') as Order;
|
return apiClient.deserialize(_decodeBodyBytes(response), 'Order') as Order;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ class UserApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
@ -99,7 +99,7 @@ class UserApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
@ -148,7 +148,7 @@ class UserApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
@ -197,7 +197,7 @@ class UserApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
@ -246,9 +246,9 @@ class UserApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
return apiClient.deserialize(response.body, 'User') as User;
|
return apiClient.deserialize(_decodeBodyBytes(response), 'User') as User;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -301,9 +301,9 @@ class UserApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
return apiClient.deserialize(response.body, 'String') as String;
|
return apiClient.deserialize(_decodeBodyBytes(response), 'String') as String;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -348,7 +348,7 @@ class UserApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
@ -400,7 +400,7 @@ class UserApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
|
@ -105,7 +105,10 @@ class ApiClient {
|
|||||||
|
|
||||||
_updateParamsForAuth(authNames, queryParams, headerParams);
|
_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 ?
|
String queryString = ps.isNotEmpty ?
|
||||||
'?' + ps.join('&') :
|
'?' + ps.join('&') :
|
||||||
'';
|
'';
|
||||||
@ -150,11 +153,9 @@ class ApiClient {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void setAccessToken(String accessToken) {
|
T getAuthentication<T extends Authentication>(String name) {
|
||||||
_authentications.forEach((key, auth) {
|
var authentication = _authentications[name];
|
||||||
if (auth is OAuth) {
|
|
||||||
auth.setAccessToken(accessToken);
|
return authentication is T ? authentication : null;
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,3 +42,15 @@ String parameterToString(dynamic value) {
|
|||||||
return value.toString();
|
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 location;
|
||||||
final String paramName;
|
final String paramName;
|
||||||
String apiKey;
|
String _apiKey;
|
||||||
String apiKeyPrefix;
|
String apiKeyPrefix;
|
||||||
|
|
||||||
|
set apiKey(String key) => _apiKey = key;
|
||||||
|
|
||||||
ApiKeyAuth(this.location, this.paramName);
|
ApiKeyAuth(this.location, this.paramName);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
|
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
|
||||||
String value;
|
String value;
|
||||||
if (apiKeyPrefix != null) {
|
if (apiKeyPrefix != null) {
|
||||||
value = '$apiKeyPrefix $apiKey';
|
value = '$apiKeyPrefix $_apiKey';
|
||||||
} else {
|
} else {
|
||||||
value = apiKey;
|
value = _apiKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (location == 'query' && value != null) {
|
if (location == 'query' && value != null) {
|
||||||
|
@ -2,13 +2,15 @@ part of openapi.api;
|
|||||||
|
|
||||||
class HttpBasicAuth implements Authentication {
|
class HttpBasicAuth implements Authentication {
|
||||||
|
|
||||||
String username;
|
String _username;
|
||||||
String password;
|
String _password;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
|
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));
|
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;
|
part of openapi.api;
|
||||||
|
|
||||||
class OAuth implements Authentication {
|
class OAuth implements Authentication {
|
||||||
String accessToken;
|
String _accessToken;
|
||||||
|
|
||||||
OAuth({this.accessToken});
|
OAuth({String accessToken}) : _accessToken = accessToken;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
|
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
|
||||||
if (accessToken != null) {
|
if (_accessToken != null) {
|
||||||
headerParams["Authorization"] = "Bearer " + accessToken;
|
headerParams["Authorization"] = "Bearer $_accessToken";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setAccessToken(String accessToken) {
|
set accessToken(String accessToken) => _accessToken = accessToken;
|
||||||
this.accessToken = accessToken;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -19,17 +19,17 @@ class ApiResponse {
|
|||||||
if (json['code'] == null) {
|
if (json['code'] == null) {
|
||||||
code = null;
|
code = null;
|
||||||
} else {
|
} else {
|
||||||
code = json['code'];
|
code = json['code'];
|
||||||
}
|
}
|
||||||
if (json['type'] == null) {
|
if (json['type'] == null) {
|
||||||
type = null;
|
type = null;
|
||||||
} else {
|
} else {
|
||||||
type = json['type'];
|
type = json['type'];
|
||||||
}
|
}
|
||||||
if (json['message'] == null) {
|
if (json['message'] == null) {
|
||||||
message = null;
|
message = null;
|
||||||
} else {
|
} else {
|
||||||
message = json['message'];
|
message = json['message'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,12 +17,12 @@ class Category {
|
|||||||
if (json['id'] == null) {
|
if (json['id'] == null) {
|
||||||
id = null;
|
id = null;
|
||||||
} else {
|
} else {
|
||||||
id = json['id'];
|
id = json['id'];
|
||||||
}
|
}
|
||||||
if (json['name'] == null) {
|
if (json['name'] == null) {
|
||||||
name = null;
|
name = null;
|
||||||
} else {
|
} else {
|
||||||
name = json['name'];
|
name = json['name'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,17 +26,17 @@ class Order {
|
|||||||
if (json['id'] == null) {
|
if (json['id'] == null) {
|
||||||
id = null;
|
id = null;
|
||||||
} else {
|
} else {
|
||||||
id = json['id'];
|
id = json['id'];
|
||||||
}
|
}
|
||||||
if (json['petId'] == null) {
|
if (json['petId'] == null) {
|
||||||
petId = null;
|
petId = null;
|
||||||
} else {
|
} else {
|
||||||
petId = json['petId'];
|
petId = json['petId'];
|
||||||
}
|
}
|
||||||
if (json['quantity'] == null) {
|
if (json['quantity'] == null) {
|
||||||
quantity = null;
|
quantity = null;
|
||||||
} else {
|
} else {
|
||||||
quantity = json['quantity'];
|
quantity = json['quantity'];
|
||||||
}
|
}
|
||||||
if (json['shipDate'] == null) {
|
if (json['shipDate'] == null) {
|
||||||
shipDate = null;
|
shipDate = null;
|
||||||
@ -46,12 +46,12 @@ class Order {
|
|||||||
if (json['status'] == null) {
|
if (json['status'] == null) {
|
||||||
status = null;
|
status = null;
|
||||||
} else {
|
} else {
|
||||||
status = json['status'];
|
status = json['status'];
|
||||||
}
|
}
|
||||||
if (json['complete'] == null) {
|
if (json['complete'] == null) {
|
||||||
complete = null;
|
complete = null;
|
||||||
} else {
|
} else {
|
||||||
complete = json['complete'];
|
complete = json['complete'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ class Pet {
|
|||||||
if (json['id'] == null) {
|
if (json['id'] == null) {
|
||||||
id = null;
|
id = null;
|
||||||
} else {
|
} else {
|
||||||
id = json['id'];
|
id = json['id'];
|
||||||
}
|
}
|
||||||
if (json['category'] == null) {
|
if (json['category'] == null) {
|
||||||
category = null;
|
category = null;
|
||||||
@ -36,12 +36,12 @@ class Pet {
|
|||||||
if (json['name'] == null) {
|
if (json['name'] == null) {
|
||||||
name = null;
|
name = null;
|
||||||
} else {
|
} else {
|
||||||
name = json['name'];
|
name = json['name'];
|
||||||
}
|
}
|
||||||
if (json['photoUrls'] == null) {
|
if (json['photoUrls'] == null) {
|
||||||
photoUrls = null;
|
photoUrls = null;
|
||||||
} else {
|
} else {
|
||||||
photoUrls = ((json['photoUrls'] ?? []) as List).map((item) => item as String).toList();
|
photoUrls = (json['photoUrls'] as List).cast<String>();
|
||||||
}
|
}
|
||||||
if (json['tags'] == null) {
|
if (json['tags'] == null) {
|
||||||
tags = null;
|
tags = null;
|
||||||
@ -51,7 +51,7 @@ class Pet {
|
|||||||
if (json['status'] == null) {
|
if (json['status'] == null) {
|
||||||
status = null;
|
status = null;
|
||||||
} else {
|
} else {
|
||||||
status = json['status'];
|
status = json['status'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,12 +17,12 @@ class Tag {
|
|||||||
if (json['id'] == null) {
|
if (json['id'] == null) {
|
||||||
id = null;
|
id = null;
|
||||||
} else {
|
} else {
|
||||||
id = json['id'];
|
id = json['id'];
|
||||||
}
|
}
|
||||||
if (json['name'] == null) {
|
if (json['name'] == null) {
|
||||||
name = null;
|
name = null;
|
||||||
} else {
|
} else {
|
||||||
name = json['name'];
|
name = json['name'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,42 +29,42 @@ class User {
|
|||||||
if (json['id'] == null) {
|
if (json['id'] == null) {
|
||||||
id = null;
|
id = null;
|
||||||
} else {
|
} else {
|
||||||
id = json['id'];
|
id = json['id'];
|
||||||
}
|
}
|
||||||
if (json['username'] == null) {
|
if (json['username'] == null) {
|
||||||
username = null;
|
username = null;
|
||||||
} else {
|
} else {
|
||||||
username = json['username'];
|
username = json['username'];
|
||||||
}
|
}
|
||||||
if (json['firstName'] == null) {
|
if (json['firstName'] == null) {
|
||||||
firstName = null;
|
firstName = null;
|
||||||
} else {
|
} else {
|
||||||
firstName = json['firstName'];
|
firstName = json['firstName'];
|
||||||
}
|
}
|
||||||
if (json['lastName'] == null) {
|
if (json['lastName'] == null) {
|
||||||
lastName = null;
|
lastName = null;
|
||||||
} else {
|
} else {
|
||||||
lastName = json['lastName'];
|
lastName = json['lastName'];
|
||||||
}
|
}
|
||||||
if (json['email'] == null) {
|
if (json['email'] == null) {
|
||||||
email = null;
|
email = null;
|
||||||
} else {
|
} else {
|
||||||
email = json['email'];
|
email = json['email'];
|
||||||
}
|
}
|
||||||
if (json['password'] == null) {
|
if (json['password'] == null) {
|
||||||
password = null;
|
password = null;
|
||||||
} else {
|
} else {
|
||||||
password = json['password'];
|
password = json['password'];
|
||||||
}
|
}
|
||||||
if (json['phone'] == null) {
|
if (json['phone'] == null) {
|
||||||
phone = null;
|
phone = null;
|
||||||
} else {
|
} else {
|
||||||
phone = json['phone'];
|
phone = json['phone'];
|
||||||
}
|
}
|
||||||
if (json['userStatus'] == null) {
|
if (json['userStatus'] == null) {
|
||||||
userStatus = null;
|
userStatus = null;
|
||||||
} else {
|
} else {
|
||||||
userStatus = json['userStatus'];
|
userStatus = json['userStatus'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ Add a new pet to the store
|
|||||||
```dart
|
```dart
|
||||||
import 'package:openapi/api.dart';
|
import 'package:openapi/api.dart';
|
||||||
// TODO Configure OAuth2 access token for authorization: petstore_auth
|
// 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 api_instance = new PetApi();
|
||||||
var body = new Pet(); // Pet | Pet object that needs to be added to the store
|
var body = new Pet(); // Pet | Pet object that needs to be added to the store
|
||||||
@ -70,7 +70,7 @@ Deletes a pet
|
|||||||
```dart
|
```dart
|
||||||
import 'package:openapi/api.dart';
|
import 'package:openapi/api.dart';
|
||||||
// TODO Configure OAuth2 access token for authorization: petstore_auth
|
// 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 api_instance = new PetApi();
|
||||||
var petId = 789; // int | Pet id to delete
|
var petId = 789; // int | Pet id to delete
|
||||||
@ -116,7 +116,7 @@ Multiple status values can be provided with comma separated strings
|
|||||||
```dart
|
```dart
|
||||||
import 'package:openapi/api.dart';
|
import 'package:openapi/api.dart';
|
||||||
// TODO Configure OAuth2 access token for authorization: petstore_auth
|
// 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 api_instance = new PetApi();
|
||||||
var status = []; // List<String> | Status values that need to be considered for filter
|
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
|
```dart
|
||||||
import 'package:openapi/api.dart';
|
import 'package:openapi/api.dart';
|
||||||
// TODO Configure OAuth2 access token for authorization: petstore_auth
|
// 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 api_instance = new PetApi();
|
||||||
var tags = []; // List<String> | Tags to filter by
|
var tags = []; // List<String> | Tags to filter by
|
||||||
@ -206,9 +206,9 @@ Returns a single pet
|
|||||||
```dart
|
```dart
|
||||||
import 'package:openapi/api.dart';
|
import 'package:openapi/api.dart';
|
||||||
// TODO Configure API key authorization: api_key
|
// 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
|
// 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 api_instance = new PetApi();
|
||||||
var petId = 789; // int | ID of pet to return
|
var petId = 789; // int | ID of pet to return
|
||||||
@ -251,7 +251,7 @@ Update an existing pet
|
|||||||
```dart
|
```dart
|
||||||
import 'package:openapi/api.dart';
|
import 'package:openapi/api.dart';
|
||||||
// TODO Configure OAuth2 access token for authorization: petstore_auth
|
// 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 api_instance = new PetApi();
|
||||||
var body = new Pet(); // Pet | Pet object that needs to be added to the store
|
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
|
```dart
|
||||||
import 'package:openapi/api.dart';
|
import 'package:openapi/api.dart';
|
||||||
// TODO Configure OAuth2 access token for authorization: petstore_auth
|
// 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 api_instance = new PetApi();
|
||||||
var petId = 789; // int | ID of pet that needs to be updated
|
var petId = 789; // int | ID of pet that needs to be updated
|
||||||
@ -339,7 +339,7 @@ uploads an image
|
|||||||
```dart
|
```dart
|
||||||
import 'package:openapi/api.dart';
|
import 'package:openapi/api.dart';
|
||||||
// TODO Configure OAuth2 access token for authorization: petstore_auth
|
// 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 api_instance = new PetApi();
|
||||||
var petId = 789; // int | ID of pet to update
|
var petId = 789; // int | ID of pet to update
|
||||||
|
@ -68,9 +68,9 @@ Returns a map of status codes to quantities
|
|||||||
```dart
|
```dart
|
||||||
import 'package:openapi/api.dart';
|
import 'package:openapi/api.dart';
|
||||||
// TODO Configure API key authorization: api_key
|
// 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
|
// 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();
|
var api_instance = new StoreApi();
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ class PetApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
@ -100,7 +100,7 @@ class PetApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
@ -150,9 +150,9 @@ class PetApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} 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 {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -201,9 +201,9 @@ class PetApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} 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 {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -251,9 +251,9 @@ class PetApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
return apiClient.deserialize(response.body, 'Pet') as Pet;
|
return apiClient.deserialize(_decodeBodyBytes(response), 'Pet') as Pet;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -301,7 +301,7 @@ class PetApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
@ -362,7 +362,7 @@ class PetApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
@ -422,9 +422,9 @@ class PetApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
return apiClient.deserialize(response.body, 'ApiResponse') as ApiResponse;
|
return apiClient.deserialize(_decodeBodyBytes(response), 'ApiResponse') as ApiResponse;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ class StoreApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
@ -96,9 +96,9 @@ class StoreApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} 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 {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
@ -147,9 +147,9 @@ class StoreApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
return apiClient.deserialize(response.body, 'Order') as Order;
|
return apiClient.deserialize(_decodeBodyBytes(response), 'Order') as Order;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -197,9 +197,9 @@ class StoreApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
return apiClient.deserialize(response.body, 'Order') as Order;
|
return apiClient.deserialize(_decodeBodyBytes(response), 'Order') as Order;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ class UserApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
@ -99,7 +99,7 @@ class UserApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
@ -148,7 +148,7 @@ class UserApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
@ -197,7 +197,7 @@ class UserApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
@ -246,9 +246,9 @@ class UserApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
return apiClient.deserialize(response.body, 'User') as User;
|
return apiClient.deserialize(_decodeBodyBytes(response), 'User') as User;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -301,9 +301,9 @@ class UserApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
return apiClient.deserialize(response.body, 'String') as String;
|
return apiClient.deserialize(_decodeBodyBytes(response), 'String') as String;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -348,7 +348,7 @@ class UserApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
@ -400,7 +400,7 @@ class UserApi {
|
|||||||
authNames);
|
authNames);
|
||||||
|
|
||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
|
@ -105,7 +105,10 @@ class ApiClient {
|
|||||||
|
|
||||||
_updateParamsForAuth(authNames, queryParams, headerParams);
|
_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 ?
|
String queryString = ps.isNotEmpty ?
|
||||||
'?' + ps.join('&') :
|
'?' + ps.join('&') :
|
||||||
'';
|
'';
|
||||||
@ -150,11 +153,9 @@ class ApiClient {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void setAccessToken(String accessToken) {
|
T getAuthentication<T extends Authentication>(String name) {
|
||||||
_authentications.forEach((key, auth) {
|
var authentication = _authentications[name];
|
||||||
if (auth is OAuth) {
|
|
||||||
auth.setAccessToken(accessToken);
|
return authentication is T ? authentication : null;
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,3 +42,15 @@ String parameterToString(dynamic value) {
|
|||||||
return value.toString();
|
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 location;
|
||||||
final String paramName;
|
final String paramName;
|
||||||
String apiKey;
|
String _apiKey;
|
||||||
String apiKeyPrefix;
|
String apiKeyPrefix;
|
||||||
|
|
||||||
|
set apiKey(String key) => _apiKey = key;
|
||||||
|
|
||||||
ApiKeyAuth(this.location, this.paramName);
|
ApiKeyAuth(this.location, this.paramName);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
|
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
|
||||||
String value;
|
String value;
|
||||||
if (apiKeyPrefix != null) {
|
if (apiKeyPrefix != null) {
|
||||||
value = '$apiKeyPrefix $apiKey';
|
value = '$apiKeyPrefix $_apiKey';
|
||||||
} else {
|
} else {
|
||||||
value = apiKey;
|
value = _apiKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (location == 'query' && value != null) {
|
if (location == 'query' && value != null) {
|
||||||
|
@ -2,13 +2,15 @@ part of openapi.api;
|
|||||||
|
|
||||||
class HttpBasicAuth implements Authentication {
|
class HttpBasicAuth implements Authentication {
|
||||||
|
|
||||||
String username;
|
String _username;
|
||||||
String password;
|
String _password;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
|
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));
|
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;
|
part of openapi.api;
|
||||||
|
|
||||||
class OAuth implements Authentication {
|
class OAuth implements Authentication {
|
||||||
String accessToken;
|
String _accessToken;
|
||||||
|
|
||||||
OAuth({this.accessToken});
|
OAuth({String accessToken}) : _accessToken = accessToken;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
|
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
|
||||||
if (accessToken != null) {
|
if (_accessToken != null) {
|
||||||
headerParams["Authorization"] = "Bearer " + accessToken;
|
headerParams["Authorization"] = "Bearer $_accessToken";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setAccessToken(String accessToken) {
|
set accessToken(String accessToken) => _accessToken = accessToken;
|
||||||
this.accessToken = accessToken;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -19,17 +19,17 @@ class ApiResponse {
|
|||||||
if (json['code'] == null) {
|
if (json['code'] == null) {
|
||||||
code = null;
|
code = null;
|
||||||
} else {
|
} else {
|
||||||
code = json['code'];
|
code = json['code'];
|
||||||
}
|
}
|
||||||
if (json['type'] == null) {
|
if (json['type'] == null) {
|
||||||
type = null;
|
type = null;
|
||||||
} else {
|
} else {
|
||||||
type = json['type'];
|
type = json['type'];
|
||||||
}
|
}
|
||||||
if (json['message'] == null) {
|
if (json['message'] == null) {
|
||||||
message = null;
|
message = null;
|
||||||
} else {
|
} else {
|
||||||
message = json['message'];
|
message = json['message'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,12 +17,12 @@ class Category {
|
|||||||
if (json['id'] == null) {
|
if (json['id'] == null) {
|
||||||
id = null;
|
id = null;
|
||||||
} else {
|
} else {
|
||||||
id = json['id'];
|
id = json['id'];
|
||||||
}
|
}
|
||||||
if (json['name'] == null) {
|
if (json['name'] == null) {
|
||||||
name = null;
|
name = null;
|
||||||
} else {
|
} else {
|
||||||
name = json['name'];
|
name = json['name'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,17 +26,17 @@ class Order {
|
|||||||
if (json['id'] == null) {
|
if (json['id'] == null) {
|
||||||
id = null;
|
id = null;
|
||||||
} else {
|
} else {
|
||||||
id = json['id'];
|
id = json['id'];
|
||||||
}
|
}
|
||||||
if (json['petId'] == null) {
|
if (json['petId'] == null) {
|
||||||
petId = null;
|
petId = null;
|
||||||
} else {
|
} else {
|
||||||
petId = json['petId'];
|
petId = json['petId'];
|
||||||
}
|
}
|
||||||
if (json['quantity'] == null) {
|
if (json['quantity'] == null) {
|
||||||
quantity = null;
|
quantity = null;
|
||||||
} else {
|
} else {
|
||||||
quantity = json['quantity'];
|
quantity = json['quantity'];
|
||||||
}
|
}
|
||||||
if (json['shipDate'] == null) {
|
if (json['shipDate'] == null) {
|
||||||
shipDate = null;
|
shipDate = null;
|
||||||
@ -46,12 +46,12 @@ class Order {
|
|||||||
if (json['status'] == null) {
|
if (json['status'] == null) {
|
||||||
status = null;
|
status = null;
|
||||||
} else {
|
} else {
|
||||||
status = json['status'];
|
status = json['status'];
|
||||||
}
|
}
|
||||||
if (json['complete'] == null) {
|
if (json['complete'] == null) {
|
||||||
complete = null;
|
complete = null;
|
||||||
} else {
|
} else {
|
||||||
complete = json['complete'];
|
complete = json['complete'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ class Pet {
|
|||||||
if (json['id'] == null) {
|
if (json['id'] == null) {
|
||||||
id = null;
|
id = null;
|
||||||
} else {
|
} else {
|
||||||
id = json['id'];
|
id = json['id'];
|
||||||
}
|
}
|
||||||
if (json['category'] == null) {
|
if (json['category'] == null) {
|
||||||
category = null;
|
category = null;
|
||||||
@ -36,12 +36,12 @@ class Pet {
|
|||||||
if (json['name'] == null) {
|
if (json['name'] == null) {
|
||||||
name = null;
|
name = null;
|
||||||
} else {
|
} else {
|
||||||
name = json['name'];
|
name = json['name'];
|
||||||
}
|
}
|
||||||
if (json['photoUrls'] == null) {
|
if (json['photoUrls'] == null) {
|
||||||
photoUrls = null;
|
photoUrls = null;
|
||||||
} else {
|
} else {
|
||||||
photoUrls = ((json['photoUrls'] ?? []) as List).map((item) => item as String).toList();
|
photoUrls = (json['photoUrls'] as List).cast<String>();
|
||||||
}
|
}
|
||||||
if (json['tags'] == null) {
|
if (json['tags'] == null) {
|
||||||
tags = null;
|
tags = null;
|
||||||
@ -51,7 +51,7 @@ class Pet {
|
|||||||
if (json['status'] == null) {
|
if (json['status'] == null) {
|
||||||
status = null;
|
status = null;
|
||||||
} else {
|
} else {
|
||||||
status = json['status'];
|
status = json['status'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,12 +17,12 @@ class Tag {
|
|||||||
if (json['id'] == null) {
|
if (json['id'] == null) {
|
||||||
id = null;
|
id = null;
|
||||||
} else {
|
} else {
|
||||||
id = json['id'];
|
id = json['id'];
|
||||||
}
|
}
|
||||||
if (json['name'] == null) {
|
if (json['name'] == null) {
|
||||||
name = null;
|
name = null;
|
||||||
} else {
|
} else {
|
||||||
name = json['name'];
|
name = json['name'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,42 +29,42 @@ class User {
|
|||||||
if (json['id'] == null) {
|
if (json['id'] == null) {
|
||||||
id = null;
|
id = null;
|
||||||
} else {
|
} else {
|
||||||
id = json['id'];
|
id = json['id'];
|
||||||
}
|
}
|
||||||
if (json['username'] == null) {
|
if (json['username'] == null) {
|
||||||
username = null;
|
username = null;
|
||||||
} else {
|
} else {
|
||||||
username = json['username'];
|
username = json['username'];
|
||||||
}
|
}
|
||||||
if (json['firstName'] == null) {
|
if (json['firstName'] == null) {
|
||||||
firstName = null;
|
firstName = null;
|
||||||
} else {
|
} else {
|
||||||
firstName = json['firstName'];
|
firstName = json['firstName'];
|
||||||
}
|
}
|
||||||
if (json['lastName'] == null) {
|
if (json['lastName'] == null) {
|
||||||
lastName = null;
|
lastName = null;
|
||||||
} else {
|
} else {
|
||||||
lastName = json['lastName'];
|
lastName = json['lastName'];
|
||||||
}
|
}
|
||||||
if (json['email'] == null) {
|
if (json['email'] == null) {
|
||||||
email = null;
|
email = null;
|
||||||
} else {
|
} else {
|
||||||
email = json['email'];
|
email = json['email'];
|
||||||
}
|
}
|
||||||
if (json['password'] == null) {
|
if (json['password'] == null) {
|
||||||
password = null;
|
password = null;
|
||||||
} else {
|
} else {
|
||||||
password = json['password'];
|
password = json['password'];
|
||||||
}
|
}
|
||||||
if (json['phone'] == null) {
|
if (json['phone'] == null) {
|
||||||
phone = null;
|
phone = null;
|
||||||
} else {
|
} else {
|
||||||
phone = json['phone'];
|
phone = json['phone'];
|
||||||
}
|
}
|
||||||
if (json['userStatus'] == null) {
|
if (json['userStatus'] == null) {
|
||||||
userStatus = null;
|
userStatus = null;
|
||||||
} else {
|
} else {
|
||||||
userStatus = json['userStatus'];
|
userStatus = json['userStatus'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user