diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartClientCodegen.java index c62bbaefd917..ae1a2e8fbb06 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartClientCodegen.java @@ -280,6 +280,7 @@ public void processOpts() { final String authFolder = sourceFolder + File.separator + "lib" + File.separator + "auth"; supportingFiles.add(new SupportingFile("auth/authentication.mustache", authFolder, "authentication.dart")); supportingFiles.add(new SupportingFile("auth/http_basic_auth.mustache", authFolder, "http_basic_auth.dart")); + supportingFiles.add(new SupportingFile("auth/http_bearer_auth.mustache", authFolder, "http_bearer_auth.dart")); supportingFiles.add(new SupportingFile("auth/api_key_auth.mustache", authFolder, "api_key_auth.dart")); supportingFiles.add(new SupportingFile("auth/oauth.mustache", authFolder, "oauth.dart")); supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh")); diff --git a/modules/openapi-generator/src/main/resources/dart2/README.mustache b/modules/openapi-generator/src/main/resources/dart2/README.mustache index 54e7a4efd5f4..a16cba3d5fa2 100644 --- a/modules/openapi-generator/src/main/resources/dart2/README.mustache +++ b/modules/openapi-generator/src/main/resources/dart2/README.mustache @@ -53,9 +53,19 @@ import 'package:{{pubName}}/api.dart'; {{#hasAuthMethods}} {{#authMethods}} {{#isBasic}} +{{#isBasicBasic}} // TODO Configure HTTP basic authorization: {{{name}}} //defaultApiClient.getAuthentication('{{{name}}}').username = 'YOUR_USERNAME' //defaultApiClient.getAuthentication('{{{name}}}').password = 'YOUR_PASSWORD'; +{{/isBasicBasic}} +{{#isBasicBearer}} +// TODO Configure HTTP Bearer authorization: {{{name}}} +// Case 1. Use String Token +//defaultApiClient.getAuthentication('{{{name}}}').setAccessToken('YOUR_ACCESS_TOKEN'); +// Case 2. Use Function which generate token. +// String yourTokenGeneratorFunction() { ... } +//defaultApiClient.getAuthentication('{{{name}}}').setAccessToken(yourTokenGeneratorFunction); +{{/isBasicBearer}} {{/isBasic}} {{#isApiKey}} // TODO Configure API key authorization: {{{name}}} @@ -110,7 +120,13 @@ Class | Method | HTTP request | Description - **API key parameter name**: {{{keyParamName}}} - **Location**: {{#isKeyInQuery}}URL query string{{/isKeyInQuery}}{{#isKeyInHeader}}HTTP header{{/isKeyInHeader}} {{/isApiKey}} -{{#isBasic}}- **Type**: HTTP basic authentication +{{#isBasic}} +{{#isBasicBasic}} +- **Type**: HTTP basicc authentication +{{/isBasicBasic}} +{{#isBasicBearer}} +- **Type**: HTTP Bearer authentication +{{/isBasicBearer}} {{/isBasic}} {{#isOAuth}}- **Type**: OAuth - **Flow**: {{{flow}}} 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 eaa3a3ed6063..91fc58fd8a8f 100644 --- a/modules/openapi-generator/src/main/resources/dart2/api_client.mustache +++ b/modules/openapi-generator/src/main/resources/dart2/api_client.mustache @@ -19,10 +19,25 @@ class ApiClient { final _regMap = RegExp(r'^Map$'); ApiClient({this.basePath = "{{{basePath}}}"}) { - // Setup authentications (key: authentication name, value: authentication).{{#authMethods}}{{#isBasic}} - _authentications['{{name}}'] = HttpBasicAuth();{{/isBasic}}{{#isApiKey}} - _authentications['{{name}}'] = ApiKeyAuth({{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{^isKeyInHeader}}"query"{{/isKeyInHeader}}, "{{keyParamName}}");{{/isApiKey}}{{#isOAuth}} - _authentications['{{name}}'] = OAuth();{{/isOAuth}}{{/authMethods}} + {{#hasAuthMethods}} + // Setup authentications (key: authentication name, value: authentication). + {{#authMethods}} + {{#isBasic}} + {{#isBasicBasic}} + _authentications['{{name}}'] = HttpBasicAuth(); + {{/isBasicBasic}} + {{#isBasicBearer}} + _authentications['{{name}}'] = HttpBearerAuth(); + {{/isBasicBearer}} + {{/isBasic}} + {{#isApiKey}} + _authentications['{{name}}'] = ApiKeyAuth({{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{^isKeyInHeader}}"query"{{/isKeyInHeader}}, "{{keyParamName}}"); + {{/isApiKey}} + {{#isOAuth}} + _authentications['{{name}}'] = OAuth(); + {{/isOAuth}} + {{/authMethods}} + {{/hasAuthMethods}} } void addDefaultHeader(String key, String value) { 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 7ef24590d167..5e0192005d0b 100644 --- a/modules/openapi-generator/src/main/resources/dart2/api_doc.mustache +++ b/modules/openapi-generator/src/main/resources/dart2/api_doc.mustache @@ -28,9 +28,19 @@ import 'package:{{pubName}}/api.dart'; {{#hasAuthMethods}} {{#authMethods}} {{#isBasic}} +{{#isBasicBasic}} // TODO Configure HTTP basic authorization: {{{name}}} //defaultApiClient.getAuthentication('{{{name}}}').username = 'YOUR_USERNAME' //defaultApiClient.getAuthentication('{{{name}}}').password = 'YOUR_PASSWORD'; +{{/isBasicBasic}} +{{#isBasicBearer}} +// TODO Configure HTTP Bearer authorization: {{{name}}} +// Case 1. Use String Token +//defaultApiClient.getAuthentication('{{{name}}}').setAccessToken('YOUR_ACCESS_TOKEN'); +// Case 2. Use Function which generate token. +// String yourTokenGeneratorFunction() { ... } +//defaultApiClient.getAuthentication('{{{name}}}').setAccessToken(yourTokenGeneratorFunction); +{{/isBasicBearer}} {{/isBasic}} {{#isApiKey}} // TODO Configure API key authorization: {{{name}}} diff --git a/modules/openapi-generator/src/main/resources/dart2/apilib.mustache b/modules/openapi-generator/src/main/resources/dart2/apilib.mustache index 720ac0b0dbf5..365ae92eb1d3 100644 --- a/modules/openapi-generator/src/main/resources/dart2/apilib.mustache +++ b/modules/openapi-generator/src/main/resources/dart2/apilib.mustache @@ -11,6 +11,7 @@ part 'auth/authentication.dart'; part 'auth/api_key_auth.dart'; part 'auth/oauth.dart'; part 'auth/http_basic_auth.dart'; +part 'auth/http_bearer_auth.dart'; {{#apiInfo}}{{#apis}}part 'api/{{classFilename}}.dart'; {{/apis}}{{/apiInfo}} diff --git a/modules/openapi-generator/src/main/resources/dart2/auth/http_bearer_auth.mustache b/modules/openapi-generator/src/main/resources/dart2/auth/http_bearer_auth.mustache new file mode 100644 index 000000000000..7390098fc48a --- /dev/null +++ b/modules/openapi-generator/src/main/resources/dart2/auth/http_bearer_auth.mustache @@ -0,0 +1,25 @@ +part of {{pubName}}.api; + +class HttpBearerAuth implements Authentication { + dynamic _accessToken; + + HttpBearerAuth() { } + + @override + void applyToParams(List queryParams, Map headerParams) { + if (_accessToken is String) { + headerParams["Authorization"] = "Bearer " + _accessToken; + } else if (_accessToken is String Function()){ + headerParams["Authorization"] = "Bearer " + _accessToken(); + } else { + throw ArgumentError('Type of Bearer accessToken should be String or String Function().'); + } + } + + void setAccessToken(dynamic accessToken) { + if (!((accessToken is String) | (accessToken is String Function()))){ + throw ArgumentError('Type of Bearer accessToken should be String or String Function().'); + } + this._accessToken = accessToken; + } +} diff --git a/samples/client/petstore/dart-dio/.openapi-generator/VERSION b/samples/client/petstore/dart-dio/.openapi-generator/VERSION index bfbf77eb7fad..b5d898602c2c 100644 --- a/samples/client/petstore/dart-dio/.openapi-generator/VERSION +++ b/samples/client/petstore/dart-dio/.openapi-generator/VERSION @@ -1 +1 @@ -4.3.0-SNAPSHOT \ No newline at end of file +4.3.1-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/dart/flutter_petstore/openapi/doc/InlineObject.md b/samples/client/petstore/dart/flutter_petstore/openapi/doc/InlineObject.md new file mode 100644 index 000000000000..1789b30bb816 --- /dev/null +++ b/samples/client/petstore/dart/flutter_petstore/openapi/doc/InlineObject.md @@ -0,0 +1,16 @@ +# openapi.model.InlineObject + +## Load the model package +```dart +import 'package:openapi/api.dart'; +``` + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**name** | **String** | Updated name of the pet | [optional] [default to null] +**status** | **String** | Updated status of the pet | [optional] [default to null] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/client/petstore/dart/flutter_petstore/openapi/doc/InlineObject1.md b/samples/client/petstore/dart/flutter_petstore/openapi/doc/InlineObject1.md new file mode 100644 index 000000000000..a5c2c120129c --- /dev/null +++ b/samples/client/petstore/dart/flutter_petstore/openapi/doc/InlineObject1.md @@ -0,0 +1,16 @@ +# openapi.model.InlineObject1 + +## Load the model package +```dart +import 'package:openapi/api.dart'; +``` + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**additionalMetadata** | **String** | Additional data to pass to server | [optional] [default to null] +**file** | [**MultipartFile**](File.md) | file to upload | [optional] [default to null] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/client/petstore/dart/flutter_petstore/openapi/lib/auth/http_bearer_auth.dart b/samples/client/petstore/dart/flutter_petstore/openapi/lib/auth/http_bearer_auth.dart new file mode 100644 index 000000000000..19a348c965ed --- /dev/null +++ b/samples/client/petstore/dart/flutter_petstore/openapi/lib/auth/http_bearer_auth.dart @@ -0,0 +1,25 @@ +part of openapi.api; + +class HttpBearerAuth implements Authentication { + dynamic _accessToken; + + HttpBearerAuth() { } + + @override + void applyToParams(List queryParams, Map headerParams) { + if (_accessToken is String) { + headerParams["Authorization"] = "Bearer " + _accessToken; + } else if (_accessToken is String Function()){ + headerParams["Authorization"] = "Bearer " + _accessToken(); + } else { + throw ArgumentError('Type of Bearer accessToken should be String or String Function().'); + } + } + + void setAccessToken(dynamic accessToken) { + if (!((accessToken is String) | (accessToken is String Function()))){ + throw ArgumentError('Type of Bearer accessToken should be String or String Function().'); + } + this._accessToken = accessToken; + } +} diff --git a/samples/client/petstore/dart/flutter_petstore/openapi/lib/model/inline_object.dart b/samples/client/petstore/dart/flutter_petstore/openapi/lib/model/inline_object.dart index 91e9c7d11756..01da636b114a 100644 --- a/samples/client/petstore/dart/flutter_petstore/openapi/lib/model/inline_object.dart +++ b/samples/client/petstore/dart/flutter_petstore/openapi/lib/model/inline_object.dart @@ -2,9 +2,9 @@ part of openapi.api; class InlineObject { /* Updated name of the pet */ - String name = null; + String name = null; /* Updated status of the pet */ - String status = null; + String status = null; InlineObject(); @override @@ -14,27 +14,33 @@ class InlineObject { InlineObject.fromJson(Map json) { if (json == null) return; - name = json['name']; - status = json['status']; + if (json['name'] == null) { + name = null; + } else { + name = json['name']; + } + if (json['status'] == null) { + status = null; + } else { + status = json['status']; + } } Map toJson() { - Map json = {}; - if (name != null) - json['name'] = name; - if (status != null) - json['status'] = status; - return json; + return { + 'name': name, + 'status': status + }; } static List listFromJson(List json) { - return json == null ? List() : json.map((value) => InlineObject.fromJson(value)).toList(); + return json == null ? new List() : json.map((value) => new InlineObject.fromJson(value)).toList(); } - static Map mapFromJson(Map json) { - var map = Map(); - if (json != null && json.isNotEmpty) { - json.forEach((String key, dynamic value) => map[key] = InlineObject.fromJson(value)); + static Map mapFromJson(Map> json) { + var map = new Map(); + if (json != null && json.length > 0) { + json.forEach((String key, Map value) => map[key] = new InlineObject.fromJson(value)); } return map; } diff --git a/samples/client/petstore/dart/flutter_petstore/openapi/lib/model/inline_object1.dart b/samples/client/petstore/dart/flutter_petstore/openapi/lib/model/inline_object1.dart index 6f5f3a426c31..9a50a7b88be3 100644 --- a/samples/client/petstore/dart/flutter_petstore/openapi/lib/model/inline_object1.dart +++ b/samples/client/petstore/dart/flutter_petstore/openapi/lib/model/inline_object1.dart @@ -2,9 +2,9 @@ part of openapi.api; class InlineObject1 { /* Additional data to pass to server */ - String additionalMetadata = null; + String additionalMetadata = null; /* file to upload */ - MultipartFile file = null; + MultipartFile file = null; InlineObject1(); @override @@ -14,29 +14,33 @@ class InlineObject1 { InlineObject1.fromJson(Map json) { if (json == null) return; - additionalMetadata = json['additionalMetadata']; - file = (json['file'] == null) ? - null : - File.fromJson(json['file']); + if (json['additionalMetadata'] == null) { + additionalMetadata = null; + } else { + additionalMetadata = json['additionalMetadata']; + } + if (json['file'] == null) { + file = null; + } else { + file = new File.fromJson(json['file']); + } } Map toJson() { - Map json = {}; - if (additionalMetadata != null) - json['additionalMetadata'] = additionalMetadata; - if (file != null) - json['file'] = file; - return json; + return { + 'additionalMetadata': additionalMetadata, + 'file': file + }; } static List listFromJson(List json) { - return json == null ? List() : json.map((value) => InlineObject1.fromJson(value)).toList(); + return json == null ? new List() : json.map((value) => new InlineObject1.fromJson(value)).toList(); } - static Map mapFromJson(Map json) { - var map = Map(); - if (json != null && json.isNotEmpty) { - json.forEach((String key, dynamic value) => map[key] = InlineObject1.fromJson(value)); + static Map mapFromJson(Map> json) { + var map = new Map(); + if (json != null && json.length > 0) { + json.forEach((String key, Map value) => map[key] = new InlineObject1.fromJson(value)); } return map; } diff --git a/samples/client/petstore/dart/openapi-browser-client/lib/auth/http_bearer_auth.dart b/samples/client/petstore/dart/openapi-browser-client/lib/auth/http_bearer_auth.dart new file mode 100644 index 000000000000..19a348c965ed --- /dev/null +++ b/samples/client/petstore/dart/openapi-browser-client/lib/auth/http_bearer_auth.dart @@ -0,0 +1,25 @@ +part of openapi.api; + +class HttpBearerAuth implements Authentication { + dynamic _accessToken; + + HttpBearerAuth() { } + + @override + void applyToParams(List queryParams, Map headerParams) { + if (_accessToken is String) { + headerParams["Authorization"] = "Bearer " + _accessToken; + } else if (_accessToken is String Function()){ + headerParams["Authorization"] = "Bearer " + _accessToken(); + } else { + throw ArgumentError('Type of Bearer accessToken should be String or String Function().'); + } + } + + void setAccessToken(dynamic accessToken) { + if (!((accessToken is String) | (accessToken is String Function()))){ + throw ArgumentError('Type of Bearer accessToken should be String or String Function().'); + } + this._accessToken = accessToken; + } +} diff --git a/samples/client/petstore/dart/openapi/lib/auth/http_bearer_auth.dart b/samples/client/petstore/dart/openapi/lib/auth/http_bearer_auth.dart new file mode 100644 index 000000000000..19a348c965ed --- /dev/null +++ b/samples/client/petstore/dart/openapi/lib/auth/http_bearer_auth.dart @@ -0,0 +1,25 @@ +part of openapi.api; + +class HttpBearerAuth implements Authentication { + dynamic _accessToken; + + HttpBearerAuth() { } + + @override + void applyToParams(List queryParams, Map headerParams) { + if (_accessToken is String) { + headerParams["Authorization"] = "Bearer " + _accessToken; + } else if (_accessToken is String Function()){ + headerParams["Authorization"] = "Bearer " + _accessToken(); + } else { + throw ArgumentError('Type of Bearer accessToken should be String or String Function().'); + } + } + + void setAccessToken(dynamic accessToken) { + if (!((accessToken is String) | (accessToken is String Function()))){ + throw ArgumentError('Type of Bearer accessToken should be String or String Function().'); + } + this._accessToken = accessToken; + } +} diff --git a/samples/client/petstore/dart2/petstore_client_lib/lib/api.dart b/samples/client/petstore/dart2/petstore_client_lib/lib/api.dart index 69c3ecd2e15d..e73e87223819 100644 --- a/samples/client/petstore/dart2/petstore_client_lib/lib/api.dart +++ b/samples/client/petstore/dart2/petstore_client_lib/lib/api.dart @@ -11,6 +11,7 @@ part 'auth/authentication.dart'; part 'auth/api_key_auth.dart'; part 'auth/oauth.dart'; part 'auth/http_basic_auth.dart'; +part 'auth/http_bearer_auth.dart'; part 'api/pet_api.dart'; part 'api/store_api.dart'; diff --git a/samples/client/petstore/dart2/petstore_client_lib/lib/auth/http_bearer_auth.dart b/samples/client/petstore/dart2/petstore_client_lib/lib/auth/http_bearer_auth.dart new file mode 100644 index 000000000000..19a348c965ed --- /dev/null +++ b/samples/client/petstore/dart2/petstore_client_lib/lib/auth/http_bearer_auth.dart @@ -0,0 +1,25 @@ +part of openapi.api; + +class HttpBearerAuth implements Authentication { + dynamic _accessToken; + + HttpBearerAuth() { } + + @override + void applyToParams(List queryParams, Map headerParams) { + if (_accessToken is String) { + headerParams["Authorization"] = "Bearer " + _accessToken; + } else if (_accessToken is String Function()){ + headerParams["Authorization"] = "Bearer " + _accessToken(); + } else { + throw ArgumentError('Type of Bearer accessToken should be String or String Function().'); + } + } + + void setAccessToken(dynamic accessToken) { + if (!((accessToken is String) | (accessToken is String Function()))){ + throw ArgumentError('Type of Bearer accessToken should be String or String Function().'); + } + this._accessToken = accessToken; + } +}