forked from OpenAPITools/openapi-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Dart] Fix "basic" auth method and Add Bearer token support (OpenAPIT…
…ools#5743) * added auth check and lint * fixed basic auth condition * Added bearer auth * updated samples * update dart petstore samples Co-authored-by: William Cheng <wing328hk@gmail.com>
- Loading branch information
Showing
16 changed files
with
249 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
modules/openapi-generator/src/main/resources/dart2/auth/http_bearer_auth.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
part of {{pubName}}.api; | ||
|
||
class HttpBearerAuth implements Authentication { | ||
dynamic _accessToken; | ||
HttpBearerAuth() { } | ||
|
||
@override | ||
void applyToParams(List<QueryParam> queryParams, Map<String, String> 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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
4.3.0-SNAPSHOT | ||
4.3.1-SNAPSHOT |
16 changes: 16 additions & 0 deletions
16
samples/client/petstore/dart/flutter_petstore/openapi/doc/InlineObject.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
|
||
|
16 changes: 16 additions & 0 deletions
16
samples/client/petstore/dart/flutter_petstore/openapi/doc/InlineObject1.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
|
||
|
25 changes: 25 additions & 0 deletions
25
samples/client/petstore/dart/flutter_petstore/openapi/lib/auth/http_bearer_auth.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
part of openapi.api; | ||
|
||
class HttpBearerAuth implements Authentication { | ||
dynamic _accessToken; | ||
|
||
HttpBearerAuth() { } | ||
|
||
@override | ||
void applyToParams(List<QueryParam> queryParams, Map<String, String> 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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
samples/client/petstore/dart/openapi-browser-client/lib/auth/http_bearer_auth.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
part of openapi.api; | ||
|
||
class HttpBearerAuth implements Authentication { | ||
dynamic _accessToken; | ||
|
||
HttpBearerAuth() { } | ||
|
||
@override | ||
void applyToParams(List<QueryParam> queryParams, Map<String, String> 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; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
samples/client/petstore/dart/openapi/lib/auth/http_bearer_auth.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
part of openapi.api; | ||
|
||
class HttpBearerAuth implements Authentication { | ||
dynamic _accessToken; | ||
|
||
HttpBearerAuth() { } | ||
|
||
@override | ||
void applyToParams(List<QueryParam> queryParams, Map<String, String> 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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
samples/client/petstore/dart2/petstore_client_lib/lib/auth/http_bearer_auth.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
part of openapi.api; | ||
|
||
class HttpBearerAuth implements Authentication { | ||
dynamic _accessToken; | ||
|
||
HttpBearerAuth() { } | ||
|
||
@override | ||
void applyToParams(List<QueryParam> queryParams, Map<String, String> 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; | ||
} | ||
} |