diff --git a/modules/openapi-generator/src/main/resources/dart2/README.mustache b/modules/openapi-generator/src/main/resources/dart2/README.mustache index 1766ea72105..83c7a21222c 100644 --- a/modules/openapi-generator/src/main/resources/dart2/README.mustache +++ b/modules/openapi-generator/src/main/resources/dart2/README.mustache @@ -58,18 +58,18 @@ import 'package:{{pubName}}/api.dart'; {{#authMethods}} {{#isBasic}} // TODO Configure HTTP basic authorization: {{{name}}} -//{{pubName}}.api.Configuration.username = 'YOUR_USERNAME'; -//{{pubName}}.api.Configuration.password = 'YOUR_PASSWORD'; +//defaultApiClient.getAuthentication('{{{name}}}').username = 'YOUR_USERNAME' +//defaultApiClient.getAuthentication('{{{name}}}').password = 'YOUR_PASSWORD'; {{/isBasic}} {{#isApiKey}} // TODO Configure API key authorization: {{{name}}} -//{{pubName}}.api.Configuration.apiKey{'{{{keyParamName}}}'} = 'YOUR_API_KEY'; +//defaultApiClient.getAuthentication('{{{name}}}').apiKey = 'YOUR_API_KEY'; // uncomment below to setup prefix (e.g. Bearer) for API key, if needed -//{{pubName}}.api.Configuration.apiKeyPrefix{'{{{keyParamName}}}'} = "Bearer"; +//defaultApiClient.getAuthentication('{{{name}}}').apiKeyPrefix = 'Bearer'; {{/isApiKey}} {{#isOAuth}} // TODO Configure OAuth2 access token for authorization: {{{name}}} -//{{pubName}}.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN'; +//defaultApiClient.getAuthentication('{{{name}}}').accessToken = 'YOUR_ACCESS_TOKEN'; {{/isOAuth}} {{/authMethods}} {{/hasAuthMethods}} diff --git a/modules/openapi-generator/src/main/resources/dart2/api_client.mustache b/modules/openapi-generator/src/main/resources/dart2/api_client.mustache index 2a6c411a788..a6bb6324e14 100644 --- a/modules/openapi-generator/src/main/resources/dart2/api_client.mustache +++ b/modules/openapi-generator/src/main/resources/dart2/api_client.mustache @@ -157,11 +157,9 @@ class ApiClient { }); } - void setAccessToken(String accessToken) { - _authentications.forEach((key, auth) { - if (auth is OAuth) { - auth.setAccessToken(accessToken); - } - }); + T getAuthentication(String name) { + var authentication = _authentications[name]; + + return authentication is T ? authentication : null; } } diff --git a/modules/openapi-generator/src/main/resources/dart2/api_doc.mustache b/modules/openapi-generator/src/main/resources/dart2/api_doc.mustache index c7c10a817a1..773ee0d562e 100644 --- a/modules/openapi-generator/src/main/resources/dart2/api_doc.mustache +++ b/modules/openapi-generator/src/main/resources/dart2/api_doc.mustache @@ -29,18 +29,18 @@ import 'package:{{pubName}}/api.dart'; {{#authMethods}} {{#isBasic}} // TODO Configure HTTP basic authorization: {{{name}}} -//{{pubName}}.api.Configuration.username = 'YOUR_USERNAME'; -//{{pubName}}.api.Configuration.password = 'YOUR_PASSWORD'; +//defaultApiClient.getAuthentication('{{{name}}}').username = 'YOUR_USERNAME' +//defaultApiClient.getAuthentication('{{{name}}}').password = 'YOUR_PASSWORD'; {{/isBasic}} {{#isApiKey}} // TODO Configure API key authorization: {{{name}}} -//{{pubName}}.api.Configuration.apiKey{'{{{keyParamName}}}'} = 'YOUR_API_KEY'; +//defaultApiClient.getAuthentication('{{{name}}}').apiKey = 'YOUR_API_KEY'; // uncomment below to setup prefix (e.g. Bearer) for API key, if needed -//{{pubName}}.api.Configuration.apiKeyPrefix{'{{{keyParamName}}}'} = "Bearer"; +//defaultApiClient.getAuthentication('{{{name}}}').apiKeyPrefix = 'Bearer'; {{/isApiKey}} {{#isOAuth}} // TODO Configure OAuth2 access token for authorization: {{{name}}} -//{{pubName}}.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN'; +//defaultApiClient.getAuthentication('{{{name}}}').accessToken = 'YOUR_ACCESS_TOKEN'; {{/isOAuth}} {{/authMethods}} {{/hasAuthMethods}} diff --git a/modules/openapi-generator/src/main/resources/dart2/auth/api_key_auth.mustache b/modules/openapi-generator/src/main/resources/dart2/auth/api_key_auth.mustache index 1e62a7902e4..c5e53204dc0 100644 --- a/modules/openapi-generator/src/main/resources/dart2/auth/api_key_auth.mustache +++ b/modules/openapi-generator/src/main/resources/dart2/auth/api_key_auth.mustache @@ -4,18 +4,20 @@ class ApiKeyAuth implements Authentication { final String location; final String paramName; - String apiKey; + String _apiKey; String apiKeyPrefix; + set apiKey(String key) => _apiKey = key; + ApiKeyAuth(this.location, this.paramName); @override void applyToParams(List queryParams, Map headerParams) { String value; if (apiKeyPrefix != null) { - value = '$apiKeyPrefix $apiKey'; + value = '$apiKeyPrefix $_apiKey'; } else { - value = apiKey; + value = _apiKey; } if (location == 'query' && value != null) { diff --git a/modules/openapi-generator/src/main/resources/dart2/auth/http_basic_auth.mustache b/modules/openapi-generator/src/main/resources/dart2/auth/http_basic_auth.mustache index 89b3926ed79..efbbcfb3035 100644 --- a/modules/openapi-generator/src/main/resources/dart2/auth/http_basic_auth.mustache +++ b/modules/openapi-generator/src/main/resources/dart2/auth/http_basic_auth.mustache @@ -2,13 +2,15 @@ part of {{pubName}}.api; class HttpBasicAuth implements Authentication { - String username; - String password; + String _username; + String _password; @override void applyToParams(List queryParams, Map headerParams) { - String str = (username == null ? "" : username) + ":" + (password == null ? "" : password); + String str = (_username == null ? "" : _username) + ":" + (_password == null ? "" : _password); headerParams["Authorization"] = "Basic " + base64.encode(utf8.encode(str)); } + set username(String username) => _username = username; + set password(String password) => _password = password; } diff --git a/modules/openapi-generator/src/main/resources/dart2/auth/oauth.mustache b/modules/openapi-generator/src/main/resources/dart2/auth/oauth.mustache index 07a25e5f6dc..58695a8a3ef 100644 --- a/modules/openapi-generator/src/main/resources/dart2/auth/oauth.mustache +++ b/modules/openapi-generator/src/main/resources/dart2/auth/oauth.mustache @@ -1,18 +1,16 @@ part of {{pubName}}.api; class OAuth implements Authentication { - String accessToken; + String _accessToken; - OAuth({this.accessToken}); + OAuth({String accessToken}) : _accessToken = accessToken; @override void applyToParams(List queryParams, Map headerParams) { - if (accessToken != null) { - headerParams["Authorization"] = "Bearer " + accessToken; + if (_accessToken != null) { + headerParams["Authorization"] = "Bearer $_accessToken"; } } - void setAccessToken(String accessToken) { - this.accessToken = accessToken; - } + set accessToken(String accessToken) => _accessToken = accessToken; } diff --git a/samples/client/petstore/dart/flutter_petstore/swagger/docs/PetApi.md b/samples/client/petstore/dart/flutter_petstore/swagger/docs/PetApi.md index 5780e7f3802..3ec1113828c 100644 --- a/samples/client/petstore/dart/flutter_petstore/swagger/docs/PetApi.md +++ b/samples/client/petstore/dart/flutter_petstore/swagger/docs/PetApi.md @@ -28,7 +28,7 @@ Add a new pet to the store ```dart import 'package:openapi/api.dart'; // TODO Configure OAuth2 access token for authorization: petstore_auth -//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN'; +//defaultApiClient.getAuthentication('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN'; var api_instance = new PetApi(); var body = new Pet(); // Pet | Pet object that needs to be added to the store @@ -70,7 +70,7 @@ Deletes a pet ```dart import 'package:openapi/api.dart'; // TODO Configure OAuth2 access token for authorization: petstore_auth -//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN'; +//defaultApiClient.getAuthentication('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN'; var api_instance = new PetApi(); var petId = 789; // int | Pet id to delete @@ -116,7 +116,7 @@ Multiple status values can be provided with comma separated strings ```dart import 'package:openapi/api.dart'; // TODO Configure OAuth2 access token for authorization: petstore_auth -//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN'; +//defaultApiClient.getAuthentication('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN'; var api_instance = new PetApi(); var status = []; // List | Status values that need to be considered for filter @@ -161,7 +161,7 @@ Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 ```dart import 'package:openapi/api.dart'; // TODO Configure OAuth2 access token for authorization: petstore_auth -//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN'; +//defaultApiClient.getAuthentication('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN'; var api_instance = new PetApi(); var tags = []; // List | Tags to filter by @@ -206,9 +206,9 @@ Returns a single pet ```dart import 'package:openapi/api.dart'; // TODO Configure API key authorization: api_key -//openapi.api.Configuration.apiKey{'api_key'} = 'YOUR_API_KEY'; +//defaultApiClient.getAuthentication('api_key').apiKey = 'YOUR_API_KEY'; // uncomment below to setup prefix (e.g. Bearer) for API key, if needed -//openapi.api.Configuration.apiKeyPrefix{'api_key'} = "Bearer"; +//defaultApiClient.getAuthentication('api_key').apiKeyPrefix = 'Bearer'; var api_instance = new PetApi(); var petId = 789; // int | ID of pet to return @@ -251,7 +251,7 @@ Update an existing pet ```dart import 'package:openapi/api.dart'; // TODO Configure OAuth2 access token for authorization: petstore_auth -//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN'; +//defaultApiClient.getAuthentication('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN'; var api_instance = new PetApi(); var body = new Pet(); // Pet | Pet object that needs to be added to the store @@ -293,7 +293,7 @@ Updates a pet in the store with form data ```dart import 'package:openapi/api.dart'; // TODO Configure OAuth2 access token for authorization: petstore_auth -//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN'; +//defaultApiClient.getAuthentication('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN'; var api_instance = new PetApi(); var petId = 789; // int | ID of pet that needs to be updated @@ -339,7 +339,7 @@ uploads an image ```dart import 'package:openapi/api.dart'; // TODO Configure OAuth2 access token for authorization: petstore_auth -//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN'; +//defaultApiClient.getAuthentication('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN'; var api_instance = new PetApi(); var petId = 789; // int | ID of pet to update diff --git a/samples/client/petstore/dart/flutter_petstore/swagger/docs/StoreApi.md b/samples/client/petstore/dart/flutter_petstore/swagger/docs/StoreApi.md index df76647f11a..f3a5e0aba87 100644 --- a/samples/client/petstore/dart/flutter_petstore/swagger/docs/StoreApi.md +++ b/samples/client/petstore/dart/flutter_petstore/swagger/docs/StoreApi.md @@ -68,9 +68,9 @@ Returns a map of status codes to quantities ```dart import 'package:openapi/api.dart'; // TODO Configure API key authorization: api_key -//openapi.api.Configuration.apiKey{'api_key'} = 'YOUR_API_KEY'; +//defaultApiClient.getAuthentication('api_key').apiKey = 'YOUR_API_KEY'; // uncomment below to setup prefix (e.g. Bearer) for API key, if needed -//openapi.api.Configuration.apiKeyPrefix{'api_key'} = "Bearer"; +//defaultApiClient.getAuthentication('api_key').apiKeyPrefix = 'Bearer'; var api_instance = new StoreApi(); diff --git a/samples/client/petstore/dart/flutter_petstore/swagger/lib/api/pet_api.dart b/samples/client/petstore/dart/flutter_petstore/swagger/lib/api/pet_api.dart index 2ded9e38bf9..abe86a5698a 100644 --- a/samples/client/petstore/dart/flutter_petstore/swagger/lib/api/pet_api.dart +++ b/samples/client/petstore/dart/flutter_petstore/swagger/lib/api/pet_api.dart @@ -50,7 +50,7 @@ class PetApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { } else { return; @@ -100,7 +100,7 @@ class PetApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { } else { return; @@ -150,9 +150,9 @@ class PetApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { - return (apiClient.deserialize(response.body, 'List') as List).map((item) => item as Pet).toList(); + return (apiClient.deserialize(_decodeBodyBytes(response), 'List') as List).map((item) => item as Pet).toList(); } else { return null; } @@ -201,9 +201,9 @@ class PetApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { - return (apiClient.deserialize(response.body, 'List') as List).map((item) => item as Pet).toList(); + return (apiClient.deserialize(_decodeBodyBytes(response), 'List') as List).map((item) => item as Pet).toList(); } else { return null; } @@ -251,9 +251,9 @@ class PetApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { - return apiClient.deserialize(response.body, 'Pet') as Pet; + return apiClient.deserialize(_decodeBodyBytes(response), 'Pet') as Pet; } else { return null; } @@ -301,7 +301,7 @@ class PetApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { } else { return; @@ -362,7 +362,7 @@ class PetApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { } else { return; @@ -422,9 +422,9 @@ class PetApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { - return apiClient.deserialize(response.body, 'ApiResponse') as ApiResponse; + return apiClient.deserialize(_decodeBodyBytes(response), 'ApiResponse') as ApiResponse; } else { return null; } diff --git a/samples/client/petstore/dart/flutter_petstore/swagger/lib/api/store_api.dart b/samples/client/petstore/dart/flutter_petstore/swagger/lib/api/store_api.dart index 0d05ff39bc9..75d6ef034ce 100644 --- a/samples/client/petstore/dart/flutter_petstore/swagger/lib/api/store_api.dart +++ b/samples/client/petstore/dart/flutter_petstore/swagger/lib/api/store_api.dart @@ -50,7 +50,7 @@ class StoreApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { } else { return; @@ -96,9 +96,9 @@ class StoreApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { - return new Map.from(apiClient.deserialize(response.body, 'Map')); + return new Map.from(apiClient.deserialize(_decodeBodyBytes(response), 'Map')); ; } else { return null; @@ -147,9 +147,9 @@ class StoreApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { - return apiClient.deserialize(response.body, 'Order') as Order; + return apiClient.deserialize(_decodeBodyBytes(response), 'Order') as Order; } else { return null; } @@ -197,9 +197,9 @@ class StoreApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { - return apiClient.deserialize(response.body, 'Order') as Order; + return apiClient.deserialize(_decodeBodyBytes(response), 'Order') as Order; } else { return null; } diff --git a/samples/client/petstore/dart/flutter_petstore/swagger/lib/api/user_api.dart b/samples/client/petstore/dart/flutter_petstore/swagger/lib/api/user_api.dart index 91d35801e43..a4be03b4319 100644 --- a/samples/client/petstore/dart/flutter_petstore/swagger/lib/api/user_api.dart +++ b/samples/client/petstore/dart/flutter_petstore/swagger/lib/api/user_api.dart @@ -50,7 +50,7 @@ class UserApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { } else { return; @@ -99,7 +99,7 @@ class UserApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { } else { return; @@ -148,7 +148,7 @@ class UserApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { } else { return; @@ -197,7 +197,7 @@ class UserApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { } else { return; @@ -246,9 +246,9 @@ class UserApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { - return apiClient.deserialize(response.body, 'User') as User; + return apiClient.deserialize(_decodeBodyBytes(response), 'User') as User; } else { return null; } @@ -301,9 +301,9 @@ class UserApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { - return apiClient.deserialize(response.body, 'String') as String; + return apiClient.deserialize(_decodeBodyBytes(response), 'String') as String; } else { return null; } @@ -348,7 +348,7 @@ class UserApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { } else { return; @@ -400,7 +400,7 @@ class UserApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { } else { return; diff --git a/samples/client/petstore/dart/flutter_petstore/swagger/lib/api_client.dart b/samples/client/petstore/dart/flutter_petstore/swagger/lib/api_client.dart index bfc05fe6ee8..9aed2f92dc3 100644 --- a/samples/client/petstore/dart/flutter_petstore/swagger/lib/api_client.dart +++ b/samples/client/petstore/dart/flutter_petstore/swagger/lib/api_client.dart @@ -105,7 +105,10 @@ class ApiClient { _updateParamsForAuth(authNames, queryParams, headerParams); - var ps = queryParams.where((p) => p.value != null).map((p) => '${p.name}=${p.value}'); + var ps = queryParams + .where((p) => p.value != null) + .map((p) => '${p.name}=${Uri.encodeQueryComponent(p.value)}'); + String queryString = ps.isNotEmpty ? '?' + ps.join('&') : ''; @@ -150,11 +153,9 @@ class ApiClient { }); } - void setAccessToken(String accessToken) { - _authentications.forEach((key, auth) { - if (auth is OAuth) { - auth.setAccessToken(accessToken); - } - }); + T getAuthentication(String name) { + var authentication = _authentications[name]; + + return authentication is T ? authentication : null; } } diff --git a/samples/client/petstore/dart/flutter_petstore/swagger/lib/api_helper.dart b/samples/client/petstore/dart/flutter_petstore/swagger/lib/api_helper.dart index a516a68d264..c57b111ca87 100644 --- a/samples/client/petstore/dart/flutter_petstore/swagger/lib/api_helper.dart +++ b/samples/client/petstore/dart/flutter_petstore/swagger/lib/api_helper.dart @@ -42,3 +42,15 @@ String parameterToString(dynamic value) { return value.toString(); } } + +/// Returns the decoded body by utf-8 if application/json with the given headers. +/// Else, returns the decoded body by default algorithm of dart:http. +/// Because avoid to text garbling when header only contains "application/json" without "; charset=utf-8". +String _decodeBodyBytes(Response response) { + var contentType = response.headers['content-type']; + if (contentType != null && contentType.contains("application/json")) { + return utf8.decode(response.bodyBytes); + } else { + return response.body; + } +} diff --git a/samples/client/petstore/dart/flutter_petstore/swagger/lib/auth/api_key_auth.dart b/samples/client/petstore/dart/flutter_petstore/swagger/lib/auth/api_key_auth.dart index 8caf6ab5eba..8384f0516ce 100644 --- a/samples/client/petstore/dart/flutter_petstore/swagger/lib/auth/api_key_auth.dart +++ b/samples/client/petstore/dart/flutter_petstore/swagger/lib/auth/api_key_auth.dart @@ -4,18 +4,20 @@ class ApiKeyAuth implements Authentication { final String location; final String paramName; - String apiKey; + String _apiKey; String apiKeyPrefix; + set apiKey(String key) => _apiKey = key; + ApiKeyAuth(this.location, this.paramName); @override void applyToParams(List queryParams, Map headerParams) { String value; if (apiKeyPrefix != null) { - value = '$apiKeyPrefix $apiKey'; + value = '$apiKeyPrefix $_apiKey'; } else { - value = apiKey; + value = _apiKey; } if (location == 'query' && value != null) { diff --git a/samples/client/petstore/dart/flutter_petstore/swagger/lib/auth/http_basic_auth.dart b/samples/client/petstore/dart/flutter_petstore/swagger/lib/auth/http_basic_auth.dart index 6342d886689..da931fa2634 100644 --- a/samples/client/petstore/dart/flutter_petstore/swagger/lib/auth/http_basic_auth.dart +++ b/samples/client/petstore/dart/flutter_petstore/swagger/lib/auth/http_basic_auth.dart @@ -2,13 +2,15 @@ part of openapi.api; class HttpBasicAuth implements Authentication { - String username; - String password; + String _username; + String _password; @override void applyToParams(List queryParams, Map headerParams) { - String str = (username == null ? "" : username) + ":" + (password == null ? "" : password); + String str = (_username == null ? "" : _username) + ":" + (_password == null ? "" : _password); headerParams["Authorization"] = "Basic " + base64.encode(utf8.encode(str)); } + set username(String username) => _username = username; + set password(String password) => _password = password; } diff --git a/samples/client/petstore/dart/flutter_petstore/swagger/lib/auth/oauth.dart b/samples/client/petstore/dart/flutter_petstore/swagger/lib/auth/oauth.dart index aa08e5cdb4d..230471e44fc 100644 --- a/samples/client/petstore/dart/flutter_petstore/swagger/lib/auth/oauth.dart +++ b/samples/client/petstore/dart/flutter_petstore/swagger/lib/auth/oauth.dart @@ -1,18 +1,16 @@ part of openapi.api; class OAuth implements Authentication { - String accessToken; + String _accessToken; - OAuth({this.accessToken}); + OAuth({String accessToken}) : _accessToken = accessToken; @override void applyToParams(List queryParams, Map headerParams) { - if (accessToken != null) { - headerParams["Authorization"] = "Bearer " + accessToken; + if (_accessToken != null) { + headerParams["Authorization"] = "Bearer $_accessToken"; } } - void setAccessToken(String accessToken) { - this.accessToken = accessToken; - } + set accessToken(String accessToken) => _accessToken = accessToken; } diff --git a/samples/client/petstore/dart/flutter_petstore/swagger/lib/model/api_response.dart b/samples/client/petstore/dart/flutter_petstore/swagger/lib/model/api_response.dart index 37c961b7320..99ffe708aeb 100644 --- a/samples/client/petstore/dart/flutter_petstore/swagger/lib/model/api_response.dart +++ b/samples/client/petstore/dart/flutter_petstore/swagger/lib/model/api_response.dart @@ -19,17 +19,17 @@ class ApiResponse { if (json['code'] == null) { code = null; } else { - code = json['code']; + code = json['code']; } if (json['type'] == null) { type = null; } else { - type = json['type']; + type = json['type']; } if (json['message'] == null) { message = null; } else { - message = json['message']; + message = json['message']; } } diff --git a/samples/client/petstore/dart/flutter_petstore/swagger/lib/model/category.dart b/samples/client/petstore/dart/flutter_petstore/swagger/lib/model/category.dart index 862b2c5b385..19386463ba2 100644 --- a/samples/client/petstore/dart/flutter_petstore/swagger/lib/model/category.dart +++ b/samples/client/petstore/dart/flutter_petstore/swagger/lib/model/category.dart @@ -17,12 +17,12 @@ class Category { if (json['id'] == null) { id = null; } else { - id = json['id']; + id = json['id']; } if (json['name'] == null) { name = null; } else { - name = json['name']; + name = json['name']; } } diff --git a/samples/client/petstore/dart/flutter_petstore/swagger/lib/model/order.dart b/samples/client/petstore/dart/flutter_petstore/swagger/lib/model/order.dart index 42dc28f0fa3..e9dfcfeaa93 100644 --- a/samples/client/petstore/dart/flutter_petstore/swagger/lib/model/order.dart +++ b/samples/client/petstore/dart/flutter_petstore/swagger/lib/model/order.dart @@ -26,17 +26,17 @@ class Order { if (json['id'] == null) { id = null; } else { - id = json['id']; + id = json['id']; } if (json['petId'] == null) { petId = null; } else { - petId = json['petId']; + petId = json['petId']; } if (json['quantity'] == null) { quantity = null; } else { - quantity = json['quantity']; + quantity = json['quantity']; } if (json['shipDate'] == null) { shipDate = null; @@ -46,12 +46,12 @@ class Order { if (json['status'] == null) { status = null; } else { - status = json['status']; + status = json['status']; } if (json['complete'] == null) { complete = null; } else { - complete = json['complete']; + complete = json['complete']; } } diff --git a/samples/client/petstore/dart/flutter_petstore/swagger/lib/model/pet.dart b/samples/client/petstore/dart/flutter_petstore/swagger/lib/model/pet.dart index f7747b01cf1..73407dc7dd0 100644 --- a/samples/client/petstore/dart/flutter_petstore/swagger/lib/model/pet.dart +++ b/samples/client/petstore/dart/flutter_petstore/swagger/lib/model/pet.dart @@ -26,7 +26,7 @@ class Pet { if (json['id'] == null) { id = null; } else { - id = json['id']; + id = json['id']; } if (json['category'] == null) { category = null; @@ -36,12 +36,12 @@ class Pet { if (json['name'] == null) { name = null; } else { - name = json['name']; + name = json['name']; } if (json['photoUrls'] == null) { photoUrls = null; } else { - photoUrls = ((json['photoUrls'] ?? []) as List).map((item) => item as String).toList(); + photoUrls = (json['photoUrls'] as List).cast(); } if (json['tags'] == null) { tags = null; @@ -51,7 +51,7 @@ class Pet { if (json['status'] == null) { status = null; } else { - status = json['status']; + status = json['status']; } } diff --git a/samples/client/petstore/dart/flutter_petstore/swagger/lib/model/tag.dart b/samples/client/petstore/dart/flutter_petstore/swagger/lib/model/tag.dart index 964fa48e0e2..7bd96004c23 100644 --- a/samples/client/petstore/dart/flutter_petstore/swagger/lib/model/tag.dart +++ b/samples/client/petstore/dart/flutter_petstore/swagger/lib/model/tag.dart @@ -17,12 +17,12 @@ class Tag { if (json['id'] == null) { id = null; } else { - id = json['id']; + id = json['id']; } if (json['name'] == null) { name = null; } else { - name = json['name']; + name = json['name']; } } diff --git a/samples/client/petstore/dart/flutter_petstore/swagger/lib/model/user.dart b/samples/client/petstore/dart/flutter_petstore/swagger/lib/model/user.dart index 067ce8f5c81..0178b539448 100644 --- a/samples/client/petstore/dart/flutter_petstore/swagger/lib/model/user.dart +++ b/samples/client/petstore/dart/flutter_petstore/swagger/lib/model/user.dart @@ -29,42 +29,42 @@ class User { if (json['id'] == null) { id = null; } else { - id = json['id']; + id = json['id']; } if (json['username'] == null) { username = null; } else { - username = json['username']; + username = json['username']; } if (json['firstName'] == null) { firstName = null; } else { - firstName = json['firstName']; + firstName = json['firstName']; } if (json['lastName'] == null) { lastName = null; } else { - lastName = json['lastName']; + lastName = json['lastName']; } if (json['email'] == null) { email = null; } else { - email = json['email']; + email = json['email']; } if (json['password'] == null) { password = null; } else { - password = json['password']; + password = json['password']; } if (json['phone'] == null) { phone = null; } else { - phone = json['phone']; + phone = json['phone']; } if (json['userStatus'] == null) { userStatus = null; } else { - userStatus = json['userStatus']; + userStatus = json['userStatus']; } } diff --git a/samples/client/petstore/dart2/flutter_petstore/openapi/docs/PetApi.md b/samples/client/petstore/dart2/flutter_petstore/openapi/docs/PetApi.md index 5780e7f3802..3ec1113828c 100644 --- a/samples/client/petstore/dart2/flutter_petstore/openapi/docs/PetApi.md +++ b/samples/client/petstore/dart2/flutter_petstore/openapi/docs/PetApi.md @@ -28,7 +28,7 @@ Add a new pet to the store ```dart import 'package:openapi/api.dart'; // TODO Configure OAuth2 access token for authorization: petstore_auth -//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN'; +//defaultApiClient.getAuthentication('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN'; var api_instance = new PetApi(); var body = new Pet(); // Pet | Pet object that needs to be added to the store @@ -70,7 +70,7 @@ Deletes a pet ```dart import 'package:openapi/api.dart'; // TODO Configure OAuth2 access token for authorization: petstore_auth -//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN'; +//defaultApiClient.getAuthentication('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN'; var api_instance = new PetApi(); var petId = 789; // int | Pet id to delete @@ -116,7 +116,7 @@ Multiple status values can be provided with comma separated strings ```dart import 'package:openapi/api.dart'; // TODO Configure OAuth2 access token for authorization: petstore_auth -//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN'; +//defaultApiClient.getAuthentication('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN'; var api_instance = new PetApi(); var status = []; // List | Status values that need to be considered for filter @@ -161,7 +161,7 @@ Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 ```dart import 'package:openapi/api.dart'; // TODO Configure OAuth2 access token for authorization: petstore_auth -//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN'; +//defaultApiClient.getAuthentication('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN'; var api_instance = new PetApi(); var tags = []; // List | Tags to filter by @@ -206,9 +206,9 @@ Returns a single pet ```dart import 'package:openapi/api.dart'; // TODO Configure API key authorization: api_key -//openapi.api.Configuration.apiKey{'api_key'} = 'YOUR_API_KEY'; +//defaultApiClient.getAuthentication('api_key').apiKey = 'YOUR_API_KEY'; // uncomment below to setup prefix (e.g. Bearer) for API key, if needed -//openapi.api.Configuration.apiKeyPrefix{'api_key'} = "Bearer"; +//defaultApiClient.getAuthentication('api_key').apiKeyPrefix = 'Bearer'; var api_instance = new PetApi(); var petId = 789; // int | ID of pet to return @@ -251,7 +251,7 @@ Update an existing pet ```dart import 'package:openapi/api.dart'; // TODO Configure OAuth2 access token for authorization: petstore_auth -//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN'; +//defaultApiClient.getAuthentication('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN'; var api_instance = new PetApi(); var body = new Pet(); // Pet | Pet object that needs to be added to the store @@ -293,7 +293,7 @@ Updates a pet in the store with form data ```dart import 'package:openapi/api.dart'; // TODO Configure OAuth2 access token for authorization: petstore_auth -//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN'; +//defaultApiClient.getAuthentication('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN'; var api_instance = new PetApi(); var petId = 789; // int | ID of pet that needs to be updated @@ -339,7 +339,7 @@ uploads an image ```dart import 'package:openapi/api.dart'; // TODO Configure OAuth2 access token for authorization: petstore_auth -//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN'; +//defaultApiClient.getAuthentication('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN'; var api_instance = new PetApi(); var petId = 789; // int | ID of pet to update diff --git a/samples/client/petstore/dart2/flutter_petstore/openapi/docs/StoreApi.md b/samples/client/petstore/dart2/flutter_petstore/openapi/docs/StoreApi.md index df76647f11a..f3a5e0aba87 100644 --- a/samples/client/petstore/dart2/flutter_petstore/openapi/docs/StoreApi.md +++ b/samples/client/petstore/dart2/flutter_petstore/openapi/docs/StoreApi.md @@ -68,9 +68,9 @@ Returns a map of status codes to quantities ```dart import 'package:openapi/api.dart'; // TODO Configure API key authorization: api_key -//openapi.api.Configuration.apiKey{'api_key'} = 'YOUR_API_KEY'; +//defaultApiClient.getAuthentication('api_key').apiKey = 'YOUR_API_KEY'; // uncomment below to setup prefix (e.g. Bearer) for API key, if needed -//openapi.api.Configuration.apiKeyPrefix{'api_key'} = "Bearer"; +//defaultApiClient.getAuthentication('api_key').apiKeyPrefix = 'Bearer'; var api_instance = new StoreApi(); diff --git a/samples/client/petstore/dart2/flutter_petstore/openapi/lib/api/pet_api.dart b/samples/client/petstore/dart2/flutter_petstore/openapi/lib/api/pet_api.dart index 2ded9e38bf9..abe86a5698a 100644 --- a/samples/client/petstore/dart2/flutter_petstore/openapi/lib/api/pet_api.dart +++ b/samples/client/petstore/dart2/flutter_petstore/openapi/lib/api/pet_api.dart @@ -50,7 +50,7 @@ class PetApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { } else { return; @@ -100,7 +100,7 @@ class PetApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { } else { return; @@ -150,9 +150,9 @@ class PetApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { - return (apiClient.deserialize(response.body, 'List') as List).map((item) => item as Pet).toList(); + return (apiClient.deserialize(_decodeBodyBytes(response), 'List') as List).map((item) => item as Pet).toList(); } else { return null; } @@ -201,9 +201,9 @@ class PetApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { - return (apiClient.deserialize(response.body, 'List') as List).map((item) => item as Pet).toList(); + return (apiClient.deserialize(_decodeBodyBytes(response), 'List') as List).map((item) => item as Pet).toList(); } else { return null; } @@ -251,9 +251,9 @@ class PetApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { - return apiClient.deserialize(response.body, 'Pet') as Pet; + return apiClient.deserialize(_decodeBodyBytes(response), 'Pet') as Pet; } else { return null; } @@ -301,7 +301,7 @@ class PetApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { } else { return; @@ -362,7 +362,7 @@ class PetApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { } else { return; @@ -422,9 +422,9 @@ class PetApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { - return apiClient.deserialize(response.body, 'ApiResponse') as ApiResponse; + return apiClient.deserialize(_decodeBodyBytes(response), 'ApiResponse') as ApiResponse; } else { return null; } diff --git a/samples/client/petstore/dart2/flutter_petstore/openapi/lib/api/store_api.dart b/samples/client/petstore/dart2/flutter_petstore/openapi/lib/api/store_api.dart index 0d05ff39bc9..75d6ef034ce 100644 --- a/samples/client/petstore/dart2/flutter_petstore/openapi/lib/api/store_api.dart +++ b/samples/client/petstore/dart2/flutter_petstore/openapi/lib/api/store_api.dart @@ -50,7 +50,7 @@ class StoreApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { } else { return; @@ -96,9 +96,9 @@ class StoreApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { - return new Map.from(apiClient.deserialize(response.body, 'Map')); + return new Map.from(apiClient.deserialize(_decodeBodyBytes(response), 'Map')); ; } else { return null; @@ -147,9 +147,9 @@ class StoreApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { - return apiClient.deserialize(response.body, 'Order') as Order; + return apiClient.deserialize(_decodeBodyBytes(response), 'Order') as Order; } else { return null; } @@ -197,9 +197,9 @@ class StoreApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { - return apiClient.deserialize(response.body, 'Order') as Order; + return apiClient.deserialize(_decodeBodyBytes(response), 'Order') as Order; } else { return null; } diff --git a/samples/client/petstore/dart2/flutter_petstore/openapi/lib/api/user_api.dart b/samples/client/petstore/dart2/flutter_petstore/openapi/lib/api/user_api.dart index 91d35801e43..a4be03b4319 100644 --- a/samples/client/petstore/dart2/flutter_petstore/openapi/lib/api/user_api.dart +++ b/samples/client/petstore/dart2/flutter_petstore/openapi/lib/api/user_api.dart @@ -50,7 +50,7 @@ class UserApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { } else { return; @@ -99,7 +99,7 @@ class UserApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { } else { return; @@ -148,7 +148,7 @@ class UserApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { } else { return; @@ -197,7 +197,7 @@ class UserApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { } else { return; @@ -246,9 +246,9 @@ class UserApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { - return apiClient.deserialize(response.body, 'User') as User; + return apiClient.deserialize(_decodeBodyBytes(response), 'User') as User; } else { return null; } @@ -301,9 +301,9 @@ class UserApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { - return apiClient.deserialize(response.body, 'String') as String; + return apiClient.deserialize(_decodeBodyBytes(response), 'String') as String; } else { return null; } @@ -348,7 +348,7 @@ class UserApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { } else { return; @@ -400,7 +400,7 @@ class UserApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { } else { return; diff --git a/samples/client/petstore/dart2/flutter_petstore/openapi/lib/api_client.dart b/samples/client/petstore/dart2/flutter_petstore/openapi/lib/api_client.dart index bfc05fe6ee8..9aed2f92dc3 100644 --- a/samples/client/petstore/dart2/flutter_petstore/openapi/lib/api_client.dart +++ b/samples/client/petstore/dart2/flutter_petstore/openapi/lib/api_client.dart @@ -105,7 +105,10 @@ class ApiClient { _updateParamsForAuth(authNames, queryParams, headerParams); - var ps = queryParams.where((p) => p.value != null).map((p) => '${p.name}=${p.value}'); + var ps = queryParams + .where((p) => p.value != null) + .map((p) => '${p.name}=${Uri.encodeQueryComponent(p.value)}'); + String queryString = ps.isNotEmpty ? '?' + ps.join('&') : ''; @@ -150,11 +153,9 @@ class ApiClient { }); } - void setAccessToken(String accessToken) { - _authentications.forEach((key, auth) { - if (auth is OAuth) { - auth.setAccessToken(accessToken); - } - }); + T getAuthentication(String name) { + var authentication = _authentications[name]; + + return authentication is T ? authentication : null; } } diff --git a/samples/client/petstore/dart2/flutter_petstore/openapi/lib/api_helper.dart b/samples/client/petstore/dart2/flutter_petstore/openapi/lib/api_helper.dart index a516a68d264..c57b111ca87 100644 --- a/samples/client/petstore/dart2/flutter_petstore/openapi/lib/api_helper.dart +++ b/samples/client/petstore/dart2/flutter_petstore/openapi/lib/api_helper.dart @@ -42,3 +42,15 @@ String parameterToString(dynamic value) { return value.toString(); } } + +/// Returns the decoded body by utf-8 if application/json with the given headers. +/// Else, returns the decoded body by default algorithm of dart:http. +/// Because avoid to text garbling when header only contains "application/json" without "; charset=utf-8". +String _decodeBodyBytes(Response response) { + var contentType = response.headers['content-type']; + if (contentType != null && contentType.contains("application/json")) { + return utf8.decode(response.bodyBytes); + } else { + return response.body; + } +} diff --git a/samples/client/petstore/dart2/flutter_petstore/openapi/lib/auth/api_key_auth.dart b/samples/client/petstore/dart2/flutter_petstore/openapi/lib/auth/api_key_auth.dart index 8caf6ab5eba..8384f0516ce 100644 --- a/samples/client/petstore/dart2/flutter_petstore/openapi/lib/auth/api_key_auth.dart +++ b/samples/client/petstore/dart2/flutter_petstore/openapi/lib/auth/api_key_auth.dart @@ -4,18 +4,20 @@ class ApiKeyAuth implements Authentication { final String location; final String paramName; - String apiKey; + String _apiKey; String apiKeyPrefix; + set apiKey(String key) => _apiKey = key; + ApiKeyAuth(this.location, this.paramName); @override void applyToParams(List queryParams, Map headerParams) { String value; if (apiKeyPrefix != null) { - value = '$apiKeyPrefix $apiKey'; + value = '$apiKeyPrefix $_apiKey'; } else { - value = apiKey; + value = _apiKey; } if (location == 'query' && value != null) { diff --git a/samples/client/petstore/dart2/flutter_petstore/openapi/lib/auth/http_basic_auth.dart b/samples/client/petstore/dart2/flutter_petstore/openapi/lib/auth/http_basic_auth.dart index 6342d886689..da931fa2634 100644 --- a/samples/client/petstore/dart2/flutter_petstore/openapi/lib/auth/http_basic_auth.dart +++ b/samples/client/petstore/dart2/flutter_petstore/openapi/lib/auth/http_basic_auth.dart @@ -2,13 +2,15 @@ part of openapi.api; class HttpBasicAuth implements Authentication { - String username; - String password; + String _username; + String _password; @override void applyToParams(List queryParams, Map headerParams) { - String str = (username == null ? "" : username) + ":" + (password == null ? "" : password); + String str = (_username == null ? "" : _username) + ":" + (_password == null ? "" : _password); headerParams["Authorization"] = "Basic " + base64.encode(utf8.encode(str)); } + set username(String username) => _username = username; + set password(String password) => _password = password; } diff --git a/samples/client/petstore/dart2/flutter_petstore/openapi/lib/auth/oauth.dart b/samples/client/petstore/dart2/flutter_petstore/openapi/lib/auth/oauth.dart index aa08e5cdb4d..230471e44fc 100644 --- a/samples/client/petstore/dart2/flutter_petstore/openapi/lib/auth/oauth.dart +++ b/samples/client/petstore/dart2/flutter_petstore/openapi/lib/auth/oauth.dart @@ -1,18 +1,16 @@ part of openapi.api; class OAuth implements Authentication { - String accessToken; + String _accessToken; - OAuth({this.accessToken}); + OAuth({String accessToken}) : _accessToken = accessToken; @override void applyToParams(List queryParams, Map headerParams) { - if (accessToken != null) { - headerParams["Authorization"] = "Bearer " + accessToken; + if (_accessToken != null) { + headerParams["Authorization"] = "Bearer $_accessToken"; } } - void setAccessToken(String accessToken) { - this.accessToken = accessToken; - } + set accessToken(String accessToken) => _accessToken = accessToken; } diff --git a/samples/client/petstore/dart2/flutter_petstore/openapi/lib/model/api_response.dart b/samples/client/petstore/dart2/flutter_petstore/openapi/lib/model/api_response.dart index 37c961b7320..99ffe708aeb 100644 --- a/samples/client/petstore/dart2/flutter_petstore/openapi/lib/model/api_response.dart +++ b/samples/client/petstore/dart2/flutter_petstore/openapi/lib/model/api_response.dart @@ -19,17 +19,17 @@ class ApiResponse { if (json['code'] == null) { code = null; } else { - code = json['code']; + code = json['code']; } if (json['type'] == null) { type = null; } else { - type = json['type']; + type = json['type']; } if (json['message'] == null) { message = null; } else { - message = json['message']; + message = json['message']; } } diff --git a/samples/client/petstore/dart2/flutter_petstore/openapi/lib/model/category.dart b/samples/client/petstore/dart2/flutter_petstore/openapi/lib/model/category.dart index 862b2c5b385..19386463ba2 100644 --- a/samples/client/petstore/dart2/flutter_petstore/openapi/lib/model/category.dart +++ b/samples/client/petstore/dart2/flutter_petstore/openapi/lib/model/category.dart @@ -17,12 +17,12 @@ class Category { if (json['id'] == null) { id = null; } else { - id = json['id']; + id = json['id']; } if (json['name'] == null) { name = null; } else { - name = json['name']; + name = json['name']; } } diff --git a/samples/client/petstore/dart2/flutter_petstore/openapi/lib/model/order.dart b/samples/client/petstore/dart2/flutter_petstore/openapi/lib/model/order.dart index 42dc28f0fa3..e9dfcfeaa93 100644 --- a/samples/client/petstore/dart2/flutter_petstore/openapi/lib/model/order.dart +++ b/samples/client/petstore/dart2/flutter_petstore/openapi/lib/model/order.dart @@ -26,17 +26,17 @@ class Order { if (json['id'] == null) { id = null; } else { - id = json['id']; + id = json['id']; } if (json['petId'] == null) { petId = null; } else { - petId = json['petId']; + petId = json['petId']; } if (json['quantity'] == null) { quantity = null; } else { - quantity = json['quantity']; + quantity = json['quantity']; } if (json['shipDate'] == null) { shipDate = null; @@ -46,12 +46,12 @@ class Order { if (json['status'] == null) { status = null; } else { - status = json['status']; + status = json['status']; } if (json['complete'] == null) { complete = null; } else { - complete = json['complete']; + complete = json['complete']; } } diff --git a/samples/client/petstore/dart2/flutter_petstore/openapi/lib/model/pet.dart b/samples/client/petstore/dart2/flutter_petstore/openapi/lib/model/pet.dart index f7747b01cf1..73407dc7dd0 100644 --- a/samples/client/petstore/dart2/flutter_petstore/openapi/lib/model/pet.dart +++ b/samples/client/petstore/dart2/flutter_petstore/openapi/lib/model/pet.dart @@ -26,7 +26,7 @@ class Pet { if (json['id'] == null) { id = null; } else { - id = json['id']; + id = json['id']; } if (json['category'] == null) { category = null; @@ -36,12 +36,12 @@ class Pet { if (json['name'] == null) { name = null; } else { - name = json['name']; + name = json['name']; } if (json['photoUrls'] == null) { photoUrls = null; } else { - photoUrls = ((json['photoUrls'] ?? []) as List).map((item) => item as String).toList(); + photoUrls = (json['photoUrls'] as List).cast(); } if (json['tags'] == null) { tags = null; @@ -51,7 +51,7 @@ class Pet { if (json['status'] == null) { status = null; } else { - status = json['status']; + status = json['status']; } } diff --git a/samples/client/petstore/dart2/flutter_petstore/openapi/lib/model/tag.dart b/samples/client/petstore/dart2/flutter_petstore/openapi/lib/model/tag.dart index 964fa48e0e2..7bd96004c23 100644 --- a/samples/client/petstore/dart2/flutter_petstore/openapi/lib/model/tag.dart +++ b/samples/client/petstore/dart2/flutter_petstore/openapi/lib/model/tag.dart @@ -17,12 +17,12 @@ class Tag { if (json['id'] == null) { id = null; } else { - id = json['id']; + id = json['id']; } if (json['name'] == null) { name = null; } else { - name = json['name']; + name = json['name']; } } diff --git a/samples/client/petstore/dart2/flutter_petstore/openapi/lib/model/user.dart b/samples/client/petstore/dart2/flutter_petstore/openapi/lib/model/user.dart index 067ce8f5c81..0178b539448 100644 --- a/samples/client/petstore/dart2/flutter_petstore/openapi/lib/model/user.dart +++ b/samples/client/petstore/dart2/flutter_petstore/openapi/lib/model/user.dart @@ -29,42 +29,42 @@ class User { if (json['id'] == null) { id = null; } else { - id = json['id']; + id = json['id']; } if (json['username'] == null) { username = null; } else { - username = json['username']; + username = json['username']; } if (json['firstName'] == null) { firstName = null; } else { - firstName = json['firstName']; + firstName = json['firstName']; } if (json['lastName'] == null) { lastName = null; } else { - lastName = json['lastName']; + lastName = json['lastName']; } if (json['email'] == null) { email = null; } else { - email = json['email']; + email = json['email']; } if (json['password'] == null) { password = null; } else { - password = json['password']; + password = json['password']; } if (json['phone'] == null) { phone = null; } else { - phone = json['phone']; + phone = json['phone']; } if (json['userStatus'] == null) { userStatus = null; } else { - userStatus = json['userStatus']; + userStatus = json['userStatus']; } } diff --git a/samples/client/petstore/dart2/openapi-browser-client/docs/PetApi.md b/samples/client/petstore/dart2/openapi-browser-client/docs/PetApi.md index 5780e7f3802..3ec1113828c 100644 --- a/samples/client/petstore/dart2/openapi-browser-client/docs/PetApi.md +++ b/samples/client/petstore/dart2/openapi-browser-client/docs/PetApi.md @@ -28,7 +28,7 @@ Add a new pet to the store ```dart import 'package:openapi/api.dart'; // TODO Configure OAuth2 access token for authorization: petstore_auth -//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN'; +//defaultApiClient.getAuthentication('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN'; var api_instance = new PetApi(); var body = new Pet(); // Pet | Pet object that needs to be added to the store @@ -70,7 +70,7 @@ Deletes a pet ```dart import 'package:openapi/api.dart'; // TODO Configure OAuth2 access token for authorization: petstore_auth -//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN'; +//defaultApiClient.getAuthentication('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN'; var api_instance = new PetApi(); var petId = 789; // int | Pet id to delete @@ -116,7 +116,7 @@ Multiple status values can be provided with comma separated strings ```dart import 'package:openapi/api.dart'; // TODO Configure OAuth2 access token for authorization: petstore_auth -//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN'; +//defaultApiClient.getAuthentication('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN'; var api_instance = new PetApi(); var status = []; // List | Status values that need to be considered for filter @@ -161,7 +161,7 @@ Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 ```dart import 'package:openapi/api.dart'; // TODO Configure OAuth2 access token for authorization: petstore_auth -//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN'; +//defaultApiClient.getAuthentication('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN'; var api_instance = new PetApi(); var tags = []; // List | Tags to filter by @@ -206,9 +206,9 @@ Returns a single pet ```dart import 'package:openapi/api.dart'; // TODO Configure API key authorization: api_key -//openapi.api.Configuration.apiKey{'api_key'} = 'YOUR_API_KEY'; +//defaultApiClient.getAuthentication('api_key').apiKey = 'YOUR_API_KEY'; // uncomment below to setup prefix (e.g. Bearer) for API key, if needed -//openapi.api.Configuration.apiKeyPrefix{'api_key'} = "Bearer"; +//defaultApiClient.getAuthentication('api_key').apiKeyPrefix = 'Bearer'; var api_instance = new PetApi(); var petId = 789; // int | ID of pet to return @@ -251,7 +251,7 @@ Update an existing pet ```dart import 'package:openapi/api.dart'; // TODO Configure OAuth2 access token for authorization: petstore_auth -//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN'; +//defaultApiClient.getAuthentication('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN'; var api_instance = new PetApi(); var body = new Pet(); // Pet | Pet object that needs to be added to the store @@ -293,7 +293,7 @@ Updates a pet in the store with form data ```dart import 'package:openapi/api.dart'; // TODO Configure OAuth2 access token for authorization: petstore_auth -//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN'; +//defaultApiClient.getAuthentication('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN'; var api_instance = new PetApi(); var petId = 789; // int | ID of pet that needs to be updated @@ -339,7 +339,7 @@ uploads an image ```dart import 'package:openapi/api.dart'; // TODO Configure OAuth2 access token for authorization: petstore_auth -//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN'; +//defaultApiClient.getAuthentication('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN'; var api_instance = new PetApi(); var petId = 789; // int | ID of pet to update diff --git a/samples/client/petstore/dart2/openapi-browser-client/docs/StoreApi.md b/samples/client/petstore/dart2/openapi-browser-client/docs/StoreApi.md index df76647f11a..f3a5e0aba87 100644 --- a/samples/client/petstore/dart2/openapi-browser-client/docs/StoreApi.md +++ b/samples/client/petstore/dart2/openapi-browser-client/docs/StoreApi.md @@ -68,9 +68,9 @@ Returns a map of status codes to quantities ```dart import 'package:openapi/api.dart'; // TODO Configure API key authorization: api_key -//openapi.api.Configuration.apiKey{'api_key'} = 'YOUR_API_KEY'; +//defaultApiClient.getAuthentication('api_key').apiKey = 'YOUR_API_KEY'; // uncomment below to setup prefix (e.g. Bearer) for API key, if needed -//openapi.api.Configuration.apiKeyPrefix{'api_key'} = "Bearer"; +//defaultApiClient.getAuthentication('api_key').apiKeyPrefix = 'Bearer'; var api_instance = new StoreApi(); diff --git a/samples/client/petstore/dart2/openapi-browser-client/lib/api/pet_api.dart b/samples/client/petstore/dart2/openapi-browser-client/lib/api/pet_api.dart index 2ded9e38bf9..abe86a5698a 100644 --- a/samples/client/petstore/dart2/openapi-browser-client/lib/api/pet_api.dart +++ b/samples/client/petstore/dart2/openapi-browser-client/lib/api/pet_api.dart @@ -50,7 +50,7 @@ class PetApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { } else { return; @@ -100,7 +100,7 @@ class PetApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { } else { return; @@ -150,9 +150,9 @@ class PetApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { - return (apiClient.deserialize(response.body, 'List') as List).map((item) => item as Pet).toList(); + return (apiClient.deserialize(_decodeBodyBytes(response), 'List') as List).map((item) => item as Pet).toList(); } else { return null; } @@ -201,9 +201,9 @@ class PetApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { - return (apiClient.deserialize(response.body, 'List') as List).map((item) => item as Pet).toList(); + return (apiClient.deserialize(_decodeBodyBytes(response), 'List') as List).map((item) => item as Pet).toList(); } else { return null; } @@ -251,9 +251,9 @@ class PetApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { - return apiClient.deserialize(response.body, 'Pet') as Pet; + return apiClient.deserialize(_decodeBodyBytes(response), 'Pet') as Pet; } else { return null; } @@ -301,7 +301,7 @@ class PetApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { } else { return; @@ -362,7 +362,7 @@ class PetApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { } else { return; @@ -422,9 +422,9 @@ class PetApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { - return apiClient.deserialize(response.body, 'ApiResponse') as ApiResponse; + return apiClient.deserialize(_decodeBodyBytes(response), 'ApiResponse') as ApiResponse; } else { return null; } diff --git a/samples/client/petstore/dart2/openapi-browser-client/lib/api/store_api.dart b/samples/client/petstore/dart2/openapi-browser-client/lib/api/store_api.dart index 0d05ff39bc9..75d6ef034ce 100644 --- a/samples/client/petstore/dart2/openapi-browser-client/lib/api/store_api.dart +++ b/samples/client/petstore/dart2/openapi-browser-client/lib/api/store_api.dart @@ -50,7 +50,7 @@ class StoreApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { } else { return; @@ -96,9 +96,9 @@ class StoreApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { - return new Map.from(apiClient.deserialize(response.body, 'Map')); + return new Map.from(apiClient.deserialize(_decodeBodyBytes(response), 'Map')); ; } else { return null; @@ -147,9 +147,9 @@ class StoreApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { - return apiClient.deserialize(response.body, 'Order') as Order; + return apiClient.deserialize(_decodeBodyBytes(response), 'Order') as Order; } else { return null; } @@ -197,9 +197,9 @@ class StoreApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { - return apiClient.deserialize(response.body, 'Order') as Order; + return apiClient.deserialize(_decodeBodyBytes(response), 'Order') as Order; } else { return null; } diff --git a/samples/client/petstore/dart2/openapi-browser-client/lib/api/user_api.dart b/samples/client/petstore/dart2/openapi-browser-client/lib/api/user_api.dart index 91d35801e43..a4be03b4319 100644 --- a/samples/client/petstore/dart2/openapi-browser-client/lib/api/user_api.dart +++ b/samples/client/petstore/dart2/openapi-browser-client/lib/api/user_api.dart @@ -50,7 +50,7 @@ class UserApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { } else { return; @@ -99,7 +99,7 @@ class UserApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { } else { return; @@ -148,7 +148,7 @@ class UserApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { } else { return; @@ -197,7 +197,7 @@ class UserApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { } else { return; @@ -246,9 +246,9 @@ class UserApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { - return apiClient.deserialize(response.body, 'User') as User; + return apiClient.deserialize(_decodeBodyBytes(response), 'User') as User; } else { return null; } @@ -301,9 +301,9 @@ class UserApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { - return apiClient.deserialize(response.body, 'String') as String; + return apiClient.deserialize(_decodeBodyBytes(response), 'String') as String; } else { return null; } @@ -348,7 +348,7 @@ class UserApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { } else { return; @@ -400,7 +400,7 @@ class UserApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { } else { return; diff --git a/samples/client/petstore/dart2/openapi-browser-client/lib/api_client.dart b/samples/client/petstore/dart2/openapi-browser-client/lib/api_client.dart index dcdbd3769d8..d5b111bf7fc 100644 --- a/samples/client/petstore/dart2/openapi-browser-client/lib/api_client.dart +++ b/samples/client/petstore/dart2/openapi-browser-client/lib/api_client.dart @@ -105,7 +105,10 @@ class ApiClient { _updateParamsForAuth(authNames, queryParams, headerParams); - var ps = queryParams.where((p) => p.value != null).map((p) => '${p.name}=${p.value}'); + var ps = queryParams + .where((p) => p.value != null) + .map((p) => '${p.name}=${Uri.encodeQueryComponent(p.value)}'); + String queryString = ps.isNotEmpty ? '?' + ps.join('&') : ''; @@ -150,11 +153,9 @@ class ApiClient { }); } - void setAccessToken(String accessToken) { - _authentications.forEach((key, auth) { - if (auth is OAuth) { - auth.setAccessToken(accessToken); - } - }); + T getAuthentication(String name) { + var authentication = _authentications[name]; + + return authentication is T ? authentication : null; } } diff --git a/samples/client/petstore/dart2/openapi-browser-client/lib/api_helper.dart b/samples/client/petstore/dart2/openapi-browser-client/lib/api_helper.dart index a516a68d264..c57b111ca87 100644 --- a/samples/client/petstore/dart2/openapi-browser-client/lib/api_helper.dart +++ b/samples/client/petstore/dart2/openapi-browser-client/lib/api_helper.dart @@ -42,3 +42,15 @@ String parameterToString(dynamic value) { return value.toString(); } } + +/// Returns the decoded body by utf-8 if application/json with the given headers. +/// Else, returns the decoded body by default algorithm of dart:http. +/// Because avoid to text garbling when header only contains "application/json" without "; charset=utf-8". +String _decodeBodyBytes(Response response) { + var contentType = response.headers['content-type']; + if (contentType != null && contentType.contains("application/json")) { + return utf8.decode(response.bodyBytes); + } else { + return response.body; + } +} diff --git a/samples/client/petstore/dart2/openapi-browser-client/lib/auth/api_key_auth.dart b/samples/client/petstore/dart2/openapi-browser-client/lib/auth/api_key_auth.dart index 8caf6ab5eba..8384f0516ce 100644 --- a/samples/client/petstore/dart2/openapi-browser-client/lib/auth/api_key_auth.dart +++ b/samples/client/petstore/dart2/openapi-browser-client/lib/auth/api_key_auth.dart @@ -4,18 +4,20 @@ class ApiKeyAuth implements Authentication { final String location; final String paramName; - String apiKey; + String _apiKey; String apiKeyPrefix; + set apiKey(String key) => _apiKey = key; + ApiKeyAuth(this.location, this.paramName); @override void applyToParams(List queryParams, Map headerParams) { String value; if (apiKeyPrefix != null) { - value = '$apiKeyPrefix $apiKey'; + value = '$apiKeyPrefix $_apiKey'; } else { - value = apiKey; + value = _apiKey; } if (location == 'query' && value != null) { diff --git a/samples/client/petstore/dart2/openapi-browser-client/lib/auth/http_basic_auth.dart b/samples/client/petstore/dart2/openapi-browser-client/lib/auth/http_basic_auth.dart index 6342d886689..da931fa2634 100644 --- a/samples/client/petstore/dart2/openapi-browser-client/lib/auth/http_basic_auth.dart +++ b/samples/client/petstore/dart2/openapi-browser-client/lib/auth/http_basic_auth.dart @@ -2,13 +2,15 @@ part of openapi.api; class HttpBasicAuth implements Authentication { - String username; - String password; + String _username; + String _password; @override void applyToParams(List queryParams, Map headerParams) { - String str = (username == null ? "" : username) + ":" + (password == null ? "" : password); + String str = (_username == null ? "" : _username) + ":" + (_password == null ? "" : _password); headerParams["Authorization"] = "Basic " + base64.encode(utf8.encode(str)); } + set username(String username) => _username = username; + set password(String password) => _password = password; } diff --git a/samples/client/petstore/dart2/openapi-browser-client/lib/auth/oauth.dart b/samples/client/petstore/dart2/openapi-browser-client/lib/auth/oauth.dart index aa08e5cdb4d..230471e44fc 100644 --- a/samples/client/petstore/dart2/openapi-browser-client/lib/auth/oauth.dart +++ b/samples/client/petstore/dart2/openapi-browser-client/lib/auth/oauth.dart @@ -1,18 +1,16 @@ part of openapi.api; class OAuth implements Authentication { - String accessToken; + String _accessToken; - OAuth({this.accessToken}); + OAuth({String accessToken}) : _accessToken = accessToken; @override void applyToParams(List queryParams, Map headerParams) { - if (accessToken != null) { - headerParams["Authorization"] = "Bearer " + accessToken; + if (_accessToken != null) { + headerParams["Authorization"] = "Bearer $_accessToken"; } } - void setAccessToken(String accessToken) { - this.accessToken = accessToken; - } + set accessToken(String accessToken) => _accessToken = accessToken; } diff --git a/samples/client/petstore/dart2/openapi-browser-client/lib/model/api_response.dart b/samples/client/petstore/dart2/openapi-browser-client/lib/model/api_response.dart index 37c961b7320..99ffe708aeb 100644 --- a/samples/client/petstore/dart2/openapi-browser-client/lib/model/api_response.dart +++ b/samples/client/petstore/dart2/openapi-browser-client/lib/model/api_response.dart @@ -19,17 +19,17 @@ class ApiResponse { if (json['code'] == null) { code = null; } else { - code = json['code']; + code = json['code']; } if (json['type'] == null) { type = null; } else { - type = json['type']; + type = json['type']; } if (json['message'] == null) { message = null; } else { - message = json['message']; + message = json['message']; } } diff --git a/samples/client/petstore/dart2/openapi-browser-client/lib/model/category.dart b/samples/client/petstore/dart2/openapi-browser-client/lib/model/category.dart index 862b2c5b385..19386463ba2 100644 --- a/samples/client/petstore/dart2/openapi-browser-client/lib/model/category.dart +++ b/samples/client/petstore/dart2/openapi-browser-client/lib/model/category.dart @@ -17,12 +17,12 @@ class Category { if (json['id'] == null) { id = null; } else { - id = json['id']; + id = json['id']; } if (json['name'] == null) { name = null; } else { - name = json['name']; + name = json['name']; } } diff --git a/samples/client/petstore/dart2/openapi-browser-client/lib/model/order.dart b/samples/client/petstore/dart2/openapi-browser-client/lib/model/order.dart index 42dc28f0fa3..e9dfcfeaa93 100644 --- a/samples/client/petstore/dart2/openapi-browser-client/lib/model/order.dart +++ b/samples/client/petstore/dart2/openapi-browser-client/lib/model/order.dart @@ -26,17 +26,17 @@ class Order { if (json['id'] == null) { id = null; } else { - id = json['id']; + id = json['id']; } if (json['petId'] == null) { petId = null; } else { - petId = json['petId']; + petId = json['petId']; } if (json['quantity'] == null) { quantity = null; } else { - quantity = json['quantity']; + quantity = json['quantity']; } if (json['shipDate'] == null) { shipDate = null; @@ -46,12 +46,12 @@ class Order { if (json['status'] == null) { status = null; } else { - status = json['status']; + status = json['status']; } if (json['complete'] == null) { complete = null; } else { - complete = json['complete']; + complete = json['complete']; } } diff --git a/samples/client/petstore/dart2/openapi-browser-client/lib/model/pet.dart b/samples/client/petstore/dart2/openapi-browser-client/lib/model/pet.dart index f7747b01cf1..73407dc7dd0 100644 --- a/samples/client/petstore/dart2/openapi-browser-client/lib/model/pet.dart +++ b/samples/client/petstore/dart2/openapi-browser-client/lib/model/pet.dart @@ -26,7 +26,7 @@ class Pet { if (json['id'] == null) { id = null; } else { - id = json['id']; + id = json['id']; } if (json['category'] == null) { category = null; @@ -36,12 +36,12 @@ class Pet { if (json['name'] == null) { name = null; } else { - name = json['name']; + name = json['name']; } if (json['photoUrls'] == null) { photoUrls = null; } else { - photoUrls = ((json['photoUrls'] ?? []) as List).map((item) => item as String).toList(); + photoUrls = (json['photoUrls'] as List).cast(); } if (json['tags'] == null) { tags = null; @@ -51,7 +51,7 @@ class Pet { if (json['status'] == null) { status = null; } else { - status = json['status']; + status = json['status']; } } diff --git a/samples/client/petstore/dart2/openapi-browser-client/lib/model/tag.dart b/samples/client/petstore/dart2/openapi-browser-client/lib/model/tag.dart index 964fa48e0e2..7bd96004c23 100644 --- a/samples/client/petstore/dart2/openapi-browser-client/lib/model/tag.dart +++ b/samples/client/petstore/dart2/openapi-browser-client/lib/model/tag.dart @@ -17,12 +17,12 @@ class Tag { if (json['id'] == null) { id = null; } else { - id = json['id']; + id = json['id']; } if (json['name'] == null) { name = null; } else { - name = json['name']; + name = json['name']; } } diff --git a/samples/client/petstore/dart2/openapi-browser-client/lib/model/user.dart b/samples/client/petstore/dart2/openapi-browser-client/lib/model/user.dart index 067ce8f5c81..0178b539448 100644 --- a/samples/client/petstore/dart2/openapi-browser-client/lib/model/user.dart +++ b/samples/client/petstore/dart2/openapi-browser-client/lib/model/user.dart @@ -29,42 +29,42 @@ class User { if (json['id'] == null) { id = null; } else { - id = json['id']; + id = json['id']; } if (json['username'] == null) { username = null; } else { - username = json['username']; + username = json['username']; } if (json['firstName'] == null) { firstName = null; } else { - firstName = json['firstName']; + firstName = json['firstName']; } if (json['lastName'] == null) { lastName = null; } else { - lastName = json['lastName']; + lastName = json['lastName']; } if (json['email'] == null) { email = null; } else { - email = json['email']; + email = json['email']; } if (json['password'] == null) { password = null; } else { - password = json['password']; + password = json['password']; } if (json['phone'] == null) { phone = null; } else { - phone = json['phone']; + phone = json['phone']; } if (json['userStatus'] == null) { userStatus = null; } else { - userStatus = json['userStatus']; + userStatus = json['userStatus']; } } diff --git a/samples/client/petstore/dart2/openapi/docs/PetApi.md b/samples/client/petstore/dart2/openapi/docs/PetApi.md index 5780e7f3802..3ec1113828c 100644 --- a/samples/client/petstore/dart2/openapi/docs/PetApi.md +++ b/samples/client/petstore/dart2/openapi/docs/PetApi.md @@ -28,7 +28,7 @@ Add a new pet to the store ```dart import 'package:openapi/api.dart'; // TODO Configure OAuth2 access token for authorization: petstore_auth -//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN'; +//defaultApiClient.getAuthentication('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN'; var api_instance = new PetApi(); var body = new Pet(); // Pet | Pet object that needs to be added to the store @@ -70,7 +70,7 @@ Deletes a pet ```dart import 'package:openapi/api.dart'; // TODO Configure OAuth2 access token for authorization: petstore_auth -//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN'; +//defaultApiClient.getAuthentication('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN'; var api_instance = new PetApi(); var petId = 789; // int | Pet id to delete @@ -116,7 +116,7 @@ Multiple status values can be provided with comma separated strings ```dart import 'package:openapi/api.dart'; // TODO Configure OAuth2 access token for authorization: petstore_auth -//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN'; +//defaultApiClient.getAuthentication('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN'; var api_instance = new PetApi(); var status = []; // List | Status values that need to be considered for filter @@ -161,7 +161,7 @@ Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 ```dart import 'package:openapi/api.dart'; // TODO Configure OAuth2 access token for authorization: petstore_auth -//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN'; +//defaultApiClient.getAuthentication('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN'; var api_instance = new PetApi(); var tags = []; // List | Tags to filter by @@ -206,9 +206,9 @@ Returns a single pet ```dart import 'package:openapi/api.dart'; // TODO Configure API key authorization: api_key -//openapi.api.Configuration.apiKey{'api_key'} = 'YOUR_API_KEY'; +//defaultApiClient.getAuthentication('api_key').apiKey = 'YOUR_API_KEY'; // uncomment below to setup prefix (e.g. Bearer) for API key, if needed -//openapi.api.Configuration.apiKeyPrefix{'api_key'} = "Bearer"; +//defaultApiClient.getAuthentication('api_key').apiKeyPrefix = 'Bearer'; var api_instance = new PetApi(); var petId = 789; // int | ID of pet to return @@ -251,7 +251,7 @@ Update an existing pet ```dart import 'package:openapi/api.dart'; // TODO Configure OAuth2 access token for authorization: petstore_auth -//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN'; +//defaultApiClient.getAuthentication('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN'; var api_instance = new PetApi(); var body = new Pet(); // Pet | Pet object that needs to be added to the store @@ -293,7 +293,7 @@ Updates a pet in the store with form data ```dart import 'package:openapi/api.dart'; // TODO Configure OAuth2 access token for authorization: petstore_auth -//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN'; +//defaultApiClient.getAuthentication('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN'; var api_instance = new PetApi(); var petId = 789; // int | ID of pet that needs to be updated @@ -339,7 +339,7 @@ uploads an image ```dart import 'package:openapi/api.dart'; // TODO Configure OAuth2 access token for authorization: petstore_auth -//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN'; +//defaultApiClient.getAuthentication('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN'; var api_instance = new PetApi(); var petId = 789; // int | ID of pet to update diff --git a/samples/client/petstore/dart2/openapi/docs/StoreApi.md b/samples/client/petstore/dart2/openapi/docs/StoreApi.md index df76647f11a..f3a5e0aba87 100644 --- a/samples/client/petstore/dart2/openapi/docs/StoreApi.md +++ b/samples/client/petstore/dart2/openapi/docs/StoreApi.md @@ -68,9 +68,9 @@ Returns a map of status codes to quantities ```dart import 'package:openapi/api.dart'; // TODO Configure API key authorization: api_key -//openapi.api.Configuration.apiKey{'api_key'} = 'YOUR_API_KEY'; +//defaultApiClient.getAuthentication('api_key').apiKey = 'YOUR_API_KEY'; // uncomment below to setup prefix (e.g. Bearer) for API key, if needed -//openapi.api.Configuration.apiKeyPrefix{'api_key'} = "Bearer"; +//defaultApiClient.getAuthentication('api_key').apiKeyPrefix = 'Bearer'; var api_instance = new StoreApi(); diff --git a/samples/client/petstore/dart2/openapi/lib/api/pet_api.dart b/samples/client/petstore/dart2/openapi/lib/api/pet_api.dart index 2ded9e38bf9..abe86a5698a 100644 --- a/samples/client/petstore/dart2/openapi/lib/api/pet_api.dart +++ b/samples/client/petstore/dart2/openapi/lib/api/pet_api.dart @@ -50,7 +50,7 @@ class PetApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { } else { return; @@ -100,7 +100,7 @@ class PetApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { } else { return; @@ -150,9 +150,9 @@ class PetApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { - return (apiClient.deserialize(response.body, 'List') as List).map((item) => item as Pet).toList(); + return (apiClient.deserialize(_decodeBodyBytes(response), 'List') as List).map((item) => item as Pet).toList(); } else { return null; } @@ -201,9 +201,9 @@ class PetApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { - return (apiClient.deserialize(response.body, 'List') as List).map((item) => item as Pet).toList(); + return (apiClient.deserialize(_decodeBodyBytes(response), 'List') as List).map((item) => item as Pet).toList(); } else { return null; } @@ -251,9 +251,9 @@ class PetApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { - return apiClient.deserialize(response.body, 'Pet') as Pet; + return apiClient.deserialize(_decodeBodyBytes(response), 'Pet') as Pet; } else { return null; } @@ -301,7 +301,7 @@ class PetApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { } else { return; @@ -362,7 +362,7 @@ class PetApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { } else { return; @@ -422,9 +422,9 @@ class PetApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { - return apiClient.deserialize(response.body, 'ApiResponse') as ApiResponse; + return apiClient.deserialize(_decodeBodyBytes(response), 'ApiResponse') as ApiResponse; } else { return null; } diff --git a/samples/client/petstore/dart2/openapi/lib/api/store_api.dart b/samples/client/petstore/dart2/openapi/lib/api/store_api.dart index 0d05ff39bc9..75d6ef034ce 100644 --- a/samples/client/petstore/dart2/openapi/lib/api/store_api.dart +++ b/samples/client/petstore/dart2/openapi/lib/api/store_api.dart @@ -50,7 +50,7 @@ class StoreApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { } else { return; @@ -96,9 +96,9 @@ class StoreApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { - return new Map.from(apiClient.deserialize(response.body, 'Map')); + return new Map.from(apiClient.deserialize(_decodeBodyBytes(response), 'Map')); ; } else { return null; @@ -147,9 +147,9 @@ class StoreApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { - return apiClient.deserialize(response.body, 'Order') as Order; + return apiClient.deserialize(_decodeBodyBytes(response), 'Order') as Order; } else { return null; } @@ -197,9 +197,9 @@ class StoreApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { - return apiClient.deserialize(response.body, 'Order') as Order; + return apiClient.deserialize(_decodeBodyBytes(response), 'Order') as Order; } else { return null; } diff --git a/samples/client/petstore/dart2/openapi/lib/api/user_api.dart b/samples/client/petstore/dart2/openapi/lib/api/user_api.dart index 91d35801e43..a4be03b4319 100644 --- a/samples/client/petstore/dart2/openapi/lib/api/user_api.dart +++ b/samples/client/petstore/dart2/openapi/lib/api/user_api.dart @@ -50,7 +50,7 @@ class UserApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { } else { return; @@ -99,7 +99,7 @@ class UserApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { } else { return; @@ -148,7 +148,7 @@ class UserApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { } else { return; @@ -197,7 +197,7 @@ class UserApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { } else { return; @@ -246,9 +246,9 @@ class UserApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { - return apiClient.deserialize(response.body, 'User') as User; + return apiClient.deserialize(_decodeBodyBytes(response), 'User') as User; } else { return null; } @@ -301,9 +301,9 @@ class UserApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { - return apiClient.deserialize(response.body, 'String') as String; + return apiClient.deserialize(_decodeBodyBytes(response), 'String') as String; } else { return null; } @@ -348,7 +348,7 @@ class UserApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { } else { return; @@ -400,7 +400,7 @@ class UserApi { authNames); if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); + throw new ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { } else { return; diff --git a/samples/client/petstore/dart2/openapi/lib/api_client.dart b/samples/client/petstore/dart2/openapi/lib/api_client.dart index bfc05fe6ee8..9aed2f92dc3 100644 --- a/samples/client/petstore/dart2/openapi/lib/api_client.dart +++ b/samples/client/petstore/dart2/openapi/lib/api_client.dart @@ -105,7 +105,10 @@ class ApiClient { _updateParamsForAuth(authNames, queryParams, headerParams); - var ps = queryParams.where((p) => p.value != null).map((p) => '${p.name}=${p.value}'); + var ps = queryParams + .where((p) => p.value != null) + .map((p) => '${p.name}=${Uri.encodeQueryComponent(p.value)}'); + String queryString = ps.isNotEmpty ? '?' + ps.join('&') : ''; @@ -150,11 +153,9 @@ class ApiClient { }); } - void setAccessToken(String accessToken) { - _authentications.forEach((key, auth) { - if (auth is OAuth) { - auth.setAccessToken(accessToken); - } - }); + T getAuthentication(String name) { + var authentication = _authentications[name]; + + return authentication is T ? authentication : null; } } diff --git a/samples/client/petstore/dart2/openapi/lib/api_helper.dart b/samples/client/petstore/dart2/openapi/lib/api_helper.dart index a516a68d264..c57b111ca87 100644 --- a/samples/client/petstore/dart2/openapi/lib/api_helper.dart +++ b/samples/client/petstore/dart2/openapi/lib/api_helper.dart @@ -42,3 +42,15 @@ String parameterToString(dynamic value) { return value.toString(); } } + +/// Returns the decoded body by utf-8 if application/json with the given headers. +/// Else, returns the decoded body by default algorithm of dart:http. +/// Because avoid to text garbling when header only contains "application/json" without "; charset=utf-8". +String _decodeBodyBytes(Response response) { + var contentType = response.headers['content-type']; + if (contentType != null && contentType.contains("application/json")) { + return utf8.decode(response.bodyBytes); + } else { + return response.body; + } +} diff --git a/samples/client/petstore/dart2/openapi/lib/auth/api_key_auth.dart b/samples/client/petstore/dart2/openapi/lib/auth/api_key_auth.dart index 8caf6ab5eba..8384f0516ce 100644 --- a/samples/client/petstore/dart2/openapi/lib/auth/api_key_auth.dart +++ b/samples/client/petstore/dart2/openapi/lib/auth/api_key_auth.dart @@ -4,18 +4,20 @@ class ApiKeyAuth implements Authentication { final String location; final String paramName; - String apiKey; + String _apiKey; String apiKeyPrefix; + set apiKey(String key) => _apiKey = key; + ApiKeyAuth(this.location, this.paramName); @override void applyToParams(List queryParams, Map headerParams) { String value; if (apiKeyPrefix != null) { - value = '$apiKeyPrefix $apiKey'; + value = '$apiKeyPrefix $_apiKey'; } else { - value = apiKey; + value = _apiKey; } if (location == 'query' && value != null) { diff --git a/samples/client/petstore/dart2/openapi/lib/auth/http_basic_auth.dart b/samples/client/petstore/dart2/openapi/lib/auth/http_basic_auth.dart index 6342d886689..da931fa2634 100644 --- a/samples/client/petstore/dart2/openapi/lib/auth/http_basic_auth.dart +++ b/samples/client/petstore/dart2/openapi/lib/auth/http_basic_auth.dart @@ -2,13 +2,15 @@ part of openapi.api; class HttpBasicAuth implements Authentication { - String username; - String password; + String _username; + String _password; @override void applyToParams(List queryParams, Map headerParams) { - String str = (username == null ? "" : username) + ":" + (password == null ? "" : password); + String str = (_username == null ? "" : _username) + ":" + (_password == null ? "" : _password); headerParams["Authorization"] = "Basic " + base64.encode(utf8.encode(str)); } + set username(String username) => _username = username; + set password(String password) => _password = password; } diff --git a/samples/client/petstore/dart2/openapi/lib/auth/oauth.dart b/samples/client/petstore/dart2/openapi/lib/auth/oauth.dart index aa08e5cdb4d..230471e44fc 100644 --- a/samples/client/petstore/dart2/openapi/lib/auth/oauth.dart +++ b/samples/client/petstore/dart2/openapi/lib/auth/oauth.dart @@ -1,18 +1,16 @@ part of openapi.api; class OAuth implements Authentication { - String accessToken; + String _accessToken; - OAuth({this.accessToken}); + OAuth({String accessToken}) : _accessToken = accessToken; @override void applyToParams(List queryParams, Map headerParams) { - if (accessToken != null) { - headerParams["Authorization"] = "Bearer " + accessToken; + if (_accessToken != null) { + headerParams["Authorization"] = "Bearer $_accessToken"; } } - void setAccessToken(String accessToken) { - this.accessToken = accessToken; - } + set accessToken(String accessToken) => _accessToken = accessToken; } diff --git a/samples/client/petstore/dart2/openapi/lib/model/api_response.dart b/samples/client/petstore/dart2/openapi/lib/model/api_response.dart index 37c961b7320..99ffe708aeb 100644 --- a/samples/client/petstore/dart2/openapi/lib/model/api_response.dart +++ b/samples/client/petstore/dart2/openapi/lib/model/api_response.dart @@ -19,17 +19,17 @@ class ApiResponse { if (json['code'] == null) { code = null; } else { - code = json['code']; + code = json['code']; } if (json['type'] == null) { type = null; } else { - type = json['type']; + type = json['type']; } if (json['message'] == null) { message = null; } else { - message = json['message']; + message = json['message']; } } diff --git a/samples/client/petstore/dart2/openapi/lib/model/category.dart b/samples/client/petstore/dart2/openapi/lib/model/category.dart index 862b2c5b385..19386463ba2 100644 --- a/samples/client/petstore/dart2/openapi/lib/model/category.dart +++ b/samples/client/petstore/dart2/openapi/lib/model/category.dart @@ -17,12 +17,12 @@ class Category { if (json['id'] == null) { id = null; } else { - id = json['id']; + id = json['id']; } if (json['name'] == null) { name = null; } else { - name = json['name']; + name = json['name']; } } diff --git a/samples/client/petstore/dart2/openapi/lib/model/order.dart b/samples/client/petstore/dart2/openapi/lib/model/order.dart index 42dc28f0fa3..e9dfcfeaa93 100644 --- a/samples/client/petstore/dart2/openapi/lib/model/order.dart +++ b/samples/client/petstore/dart2/openapi/lib/model/order.dart @@ -26,17 +26,17 @@ class Order { if (json['id'] == null) { id = null; } else { - id = json['id']; + id = json['id']; } if (json['petId'] == null) { petId = null; } else { - petId = json['petId']; + petId = json['petId']; } if (json['quantity'] == null) { quantity = null; } else { - quantity = json['quantity']; + quantity = json['quantity']; } if (json['shipDate'] == null) { shipDate = null; @@ -46,12 +46,12 @@ class Order { if (json['status'] == null) { status = null; } else { - status = json['status']; + status = json['status']; } if (json['complete'] == null) { complete = null; } else { - complete = json['complete']; + complete = json['complete']; } } diff --git a/samples/client/petstore/dart2/openapi/lib/model/pet.dart b/samples/client/petstore/dart2/openapi/lib/model/pet.dart index f7747b01cf1..73407dc7dd0 100644 --- a/samples/client/petstore/dart2/openapi/lib/model/pet.dart +++ b/samples/client/petstore/dart2/openapi/lib/model/pet.dart @@ -26,7 +26,7 @@ class Pet { if (json['id'] == null) { id = null; } else { - id = json['id']; + id = json['id']; } if (json['category'] == null) { category = null; @@ -36,12 +36,12 @@ class Pet { if (json['name'] == null) { name = null; } else { - name = json['name']; + name = json['name']; } if (json['photoUrls'] == null) { photoUrls = null; } else { - photoUrls = ((json['photoUrls'] ?? []) as List).map((item) => item as String).toList(); + photoUrls = (json['photoUrls'] as List).cast(); } if (json['tags'] == null) { tags = null; @@ -51,7 +51,7 @@ class Pet { if (json['status'] == null) { status = null; } else { - status = json['status']; + status = json['status']; } } diff --git a/samples/client/petstore/dart2/openapi/lib/model/tag.dart b/samples/client/petstore/dart2/openapi/lib/model/tag.dart index 964fa48e0e2..7bd96004c23 100644 --- a/samples/client/petstore/dart2/openapi/lib/model/tag.dart +++ b/samples/client/petstore/dart2/openapi/lib/model/tag.dart @@ -17,12 +17,12 @@ class Tag { if (json['id'] == null) { id = null; } else { - id = json['id']; + id = json['id']; } if (json['name'] == null) { name = null; } else { - name = json['name']; + name = json['name']; } } diff --git a/samples/client/petstore/dart2/openapi/lib/model/user.dart b/samples/client/petstore/dart2/openapi/lib/model/user.dart index 067ce8f5c81..0178b539448 100644 --- a/samples/client/petstore/dart2/openapi/lib/model/user.dart +++ b/samples/client/petstore/dart2/openapi/lib/model/user.dart @@ -29,42 +29,42 @@ class User { if (json['id'] == null) { id = null; } else { - id = json['id']; + id = json['id']; } if (json['username'] == null) { username = null; } else { - username = json['username']; + username = json['username']; } if (json['firstName'] == null) { firstName = null; } else { - firstName = json['firstName']; + firstName = json['firstName']; } if (json['lastName'] == null) { lastName = null; } else { - lastName = json['lastName']; + lastName = json['lastName']; } if (json['email'] == null) { email = null; } else { - email = json['email']; + email = json['email']; } if (json['password'] == null) { password = null; } else { - password = json['password']; + password = json['password']; } if (json['phone'] == null) { phone = null; } else { - phone = json['phone']; + phone = json['phone']; } if (json['userStatus'] == null) { userStatus = null; } else { - userStatus = json['userStatus']; + userStatus = json['userStatus']; } }