Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
8efe999
Add optValue to CliOption
A-Joshi Mar 18, 2019
b5f4b6b
Use CliOption for classModifier, operationModifier, buildTarget, add …
A-Joshi Mar 18, 2019
c85b5bf
Make abstract method look cleaner
A-Joshi Mar 18, 2019
dd1d826
Add ASP.Net core 2.2
A-Joshi Mar 18, 2019
b70372b
update docs
A-Joshi Mar 18, 2019
0b15fac
fix java doc issue (#2435)
wing328 Mar 18, 2019
1f45ea7
[#2425] - implemented yaml parsing for config file. (#2434)
dragosnutu Mar 18, 2019
d93fd31
[dart] Fix authentication for dart (#2419)
dalewking Mar 19, 2019
93baa5d
Initial attempt at deploying to gradle plugin portal (#2440)
jimschubert Mar 19, 2019
43fcd19
add semi colon to gradle tasks
wing328 Mar 19, 2019
7ad479e
[C] Update README and adding object.c/h files (#2377)
zhemant Mar 19, 2019
3320d3c
Handle collection params in path (assume csv for now). (#2259)
jacobweber Mar 19, 2019
79d9388
Reformat code to meet PR feedback
A-Joshi Mar 19, 2019
1dd25ef
Fix compilation with ASP.Net Core 2.1
A-Joshi Mar 19, 2019
54041f2
Update docs
A-Joshi Mar 19, 2019
01c480d
Add optValue to CliOption
A-Joshi Mar 18, 2019
d1a089e
Use CliOption for classModifier, operationModifier, buildTarget, add …
A-Joshi Mar 18, 2019
58a3d2c
Make abstract method look cleaner
A-Joshi Mar 18, 2019
fb4f8b9
Add ASP.Net core 2.2
A-Joshi Mar 18, 2019
144d18c
update docs
A-Joshi Mar 18, 2019
b9513e9
Reformat code to meet PR feedback
A-Joshi Mar 19, 2019
4332298
Fix compilation with ASP.Net Core 2.1
A-Joshi Mar 19, 2019
d8b2bac
Update docs
A-Joshi Mar 19, 2019
53f217b
Merge branch 'feature/cleanup' of https://github.com/ihsmarkitoss/ope…
A-Joshi Mar 20, 2019
80a34b3
Fix build target error
A-Joshi Mar 20, 2019
04b66d0
Remove duplicated code
A-Joshi Mar 20, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[dart] Fix authentication for dart (#2419)
* [dart] Fix authentication so all forms of Swagger 2.0 authentication work

* Run changes on petstore examples

* Amend dart2 generated README to cover basic authentication

* Amend dart2 generated README to cover authentication methods

* [dart] Fix authentication so all forms of Swagger 2.0 authentication work

* Run changes on petstore examples
  • Loading branch information
dalewking authored and wing328 committed Mar 19, 2019
commit d93fd31bb1d6d4d6c89092a6c1a75afc4429bc94
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,18 @@ import 'package:{{pubName}}/api.dart';
{{#authMethods}}
{{#isBasic}}
// TODO Configure HTTP basic authorization: {{{name}}}
//{{pubName}}.api.Configuration.username = 'YOUR_USERNAME';
//{{pubName}}.api.Configuration.password = 'YOUR_PASSWORD';
//defaultApiClient.getAuthentication<HttpBasicAuth>('{{{name}}}').username = 'YOUR_USERNAME'
//defaultApiClient.getAuthentication<HttpBasicAuth>('{{{name}}}').password = 'YOUR_PASSWORD';
{{/isBasic}}
{{#isApiKey}}
// TODO Configure API key authorization: {{{name}}}
//{{pubName}}.api.Configuration.apiKey{'{{{keyParamName}}}'} = 'YOUR_API_KEY';
//defaultApiClient.getAuthentication<ApiKeyAuth>('{{{name}}}').apiKey = 'YOUR_API_KEY';
// uncomment below to setup prefix (e.g. Bearer) for API key, if needed
//{{pubName}}.api.Configuration.apiKeyPrefix{'{{{keyParamName}}}'} = "Bearer";
//defaultApiClient.getAuthentication<ApiKeyAuth>('{{{name}}}').apiKeyPrefix = 'Bearer';
{{/isApiKey}}
{{#isOAuth}}
// TODO Configure OAuth2 access token for authorization: {{{name}}}
//{{pubName}}.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN';
//defaultApiClient.getAuthentication<OAuth>('{{{name}}}').accessToken = 'YOUR_ACCESS_TOKEN';
{{/isOAuth}}
{{/authMethods}}
{{/hasAuthMethods}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,9 @@ class ApiClient {
});
}

void setAccessToken(String accessToken) {
_authentications.forEach((key, auth) {
if (auth is OAuth) {
auth.setAccessToken(accessToken);
}
});
T getAuthentication<T extends Authentication>(String name) {
var authentication = _authentications[name];

return authentication is T ? authentication : null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ import 'package:{{pubName}}/api.dart';
{{#authMethods}}
{{#isBasic}}
// TODO Configure HTTP basic authorization: {{{name}}}
//{{pubName}}.api.Configuration.username = 'YOUR_USERNAME';
//{{pubName}}.api.Configuration.password = 'YOUR_PASSWORD';
//defaultApiClient.getAuthentication<HttpBasicAuth>('{{{name}}}').username = 'YOUR_USERNAME'
//defaultApiClient.getAuthentication<HttpBasicAuth>('{{{name}}}').password = 'YOUR_PASSWORD';
{{/isBasic}}
{{#isApiKey}}
// TODO Configure API key authorization: {{{name}}}
//{{pubName}}.api.Configuration.apiKey{'{{{keyParamName}}}'} = 'YOUR_API_KEY';
//defaultApiClient.getAuthentication<ApiKeyAuth>('{{{name}}}').apiKey = 'YOUR_API_KEY';
// uncomment below to setup prefix (e.g. Bearer) for API key, if needed
//{{pubName}}.api.Configuration.apiKeyPrefix{'{{{keyParamName}}}'} = "Bearer";
//defaultApiClient.getAuthentication<ApiKeyAuth>('{{{name}}}').apiKeyPrefix = 'Bearer';
{{/isApiKey}}
{{#isOAuth}}
// TODO Configure OAuth2 access token for authorization: {{{name}}}
//{{pubName}}.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN';
//defaultApiClient.getAuthentication<OAuth>('{{{name}}}').accessToken = 'YOUR_ACCESS_TOKEN';
{{/isOAuth}}
{{/authMethods}}
{{/hasAuthMethods}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@ class ApiKeyAuth implements Authentication {

final String location;
final String paramName;
String apiKey;
String _apiKey;
String apiKeyPrefix;

set apiKey(String key) => _apiKey = key;

ApiKeyAuth(this.location, this.paramName);

@override
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
String value;
if (apiKeyPrefix != null) {
value = '$apiKeyPrefix $apiKey';
value = '$apiKeyPrefix $_apiKey';
} else {
value = apiKey;
value = _apiKey;
}

if (location == 'query' && value != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ part of {{pubName}}.api;

class HttpBasicAuth implements Authentication {

String username;
String password;
String _username;
String _password;

@override
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
String str = (username == null ? "" : username) + ":" + (password == null ? "" : password);
String str = (_username == null ? "" : _username) + ":" + (_password == null ? "" : _password);
headerParams["Authorization"] = "Basic " + base64.encode(utf8.encode(str));
}

set username(String username) => _username = username;
set password(String password) => _password = password;
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
part of {{pubName}}.api;

class OAuth implements Authentication {
String accessToken;
String _accessToken;

OAuth({this.accessToken});
OAuth({String accessToken}) : _accessToken = accessToken;

@override
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
if (accessToken != null) {
headerParams["Authorization"] = "Bearer " + accessToken;
if (_accessToken != null) {
headerParams["Authorization"] = "Bearer $_accessToken";
}
}

void setAccessToken(String accessToken) {
this.accessToken = accessToken;
}
set accessToken(String accessToken) => _accessToken = accessToken;
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Add a new pet to the store
```dart
import 'package:openapi/api.dart';
// TODO Configure OAuth2 access token for authorization: petstore_auth
//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN';
//defaultApiClient.getAuthentication<OAuth>('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN';

var api_instance = new PetApi();
var body = new Pet(); // Pet | Pet object that needs to be added to the store
Expand Down Expand Up @@ -70,7 +70,7 @@ Deletes a pet
```dart
import 'package:openapi/api.dart';
// TODO Configure OAuth2 access token for authorization: petstore_auth
//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN';
//defaultApiClient.getAuthentication<OAuth>('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN';

var api_instance = new PetApi();
var petId = 789; // int | Pet id to delete
Expand Down Expand Up @@ -116,7 +116,7 @@ Multiple status values can be provided with comma separated strings
```dart
import 'package:openapi/api.dart';
// TODO Configure OAuth2 access token for authorization: petstore_auth
//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN';
//defaultApiClient.getAuthentication<OAuth>('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN';

var api_instance = new PetApi();
var status = []; // List<String> | Status values that need to be considered for filter
Expand Down Expand Up @@ -161,7 +161,7 @@ Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3
```dart
import 'package:openapi/api.dart';
// TODO Configure OAuth2 access token for authorization: petstore_auth
//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN';
//defaultApiClient.getAuthentication<OAuth>('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN';

var api_instance = new PetApi();
var tags = []; // List<String> | Tags to filter by
Expand Down Expand Up @@ -206,9 +206,9 @@ Returns a single pet
```dart
import 'package:openapi/api.dart';
// TODO Configure API key authorization: api_key
//openapi.api.Configuration.apiKey{'api_key'} = 'YOUR_API_KEY';
//defaultApiClient.getAuthentication<ApiKeyAuth>('api_key').apiKey = 'YOUR_API_KEY';
// uncomment below to setup prefix (e.g. Bearer) for API key, if needed
//openapi.api.Configuration.apiKeyPrefix{'api_key'} = "Bearer";
//defaultApiClient.getAuthentication<ApiKeyAuth>('api_key').apiKeyPrefix = 'Bearer';

var api_instance = new PetApi();
var petId = 789; // int | ID of pet to return
Expand Down Expand Up @@ -251,7 +251,7 @@ Update an existing pet
```dart
import 'package:openapi/api.dart';
// TODO Configure OAuth2 access token for authorization: petstore_auth
//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN';
//defaultApiClient.getAuthentication<OAuth>('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN';

var api_instance = new PetApi();
var body = new Pet(); // Pet | Pet object that needs to be added to the store
Expand Down Expand Up @@ -293,7 +293,7 @@ Updates a pet in the store with form data
```dart
import 'package:openapi/api.dart';
// TODO Configure OAuth2 access token for authorization: petstore_auth
//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN';
//defaultApiClient.getAuthentication<OAuth>('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN';

var api_instance = new PetApi();
var petId = 789; // int | ID of pet that needs to be updated
Expand Down Expand Up @@ -339,7 +339,7 @@ uploads an image
```dart
import 'package:openapi/api.dart';
// TODO Configure OAuth2 access token for authorization: petstore_auth
//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN';
//defaultApiClient.getAuthentication<OAuth>('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN';

var api_instance = new PetApi();
var petId = 789; // int | ID of pet to update
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ Returns a map of status codes to quantities
```dart
import 'package:openapi/api.dart';
// TODO Configure API key authorization: api_key
//openapi.api.Configuration.apiKey{'api_key'} = 'YOUR_API_KEY';
//defaultApiClient.getAuthentication<ApiKeyAuth>('api_key').apiKey = 'YOUR_API_KEY';
// uncomment below to setup prefix (e.g. Bearer) for API key, if needed
//openapi.api.Configuration.apiKeyPrefix{'api_key'} = "Bearer";
//defaultApiClient.getAuthentication<ApiKeyAuth>('api_key').apiKeyPrefix = 'Bearer';

var api_instance = new StoreApi();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -150,9 +150,9 @@ class PetApi {
authNames);

if(response.statusCode >= 400) {
throw new ApiException(response.statusCode, response.body);
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
} else if(response.body != null) {
return (apiClient.deserialize(response.body, 'List<Pet>') as List).map((item) => item as Pet).toList();
return (apiClient.deserialize(_decodeBodyBytes(response), 'List<Pet>') as List).map((item) => item as Pet).toList();
} else {
return null;
}
Expand Down Expand Up @@ -201,9 +201,9 @@ class PetApi {
authNames);

if(response.statusCode >= 400) {
throw new ApiException(response.statusCode, response.body);
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
} else if(response.body != null) {
return (apiClient.deserialize(response.body, 'List<Pet>') as List).map((item) => item as Pet).toList();
return (apiClient.deserialize(_decodeBodyBytes(response), 'List<Pet>') as List).map((item) => item as Pet).toList();
} else {
return null;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -96,9 +96,9 @@ class StoreApi {
authNames);

if(response.statusCode >= 400) {
throw new ApiException(response.statusCode, response.body);
throw new ApiException(response.statusCode, _decodeBodyBytes(response));
} else if(response.body != null) {
return new Map<String, int>.from(apiClient.deserialize(response.body, 'Map<String, int>'));
return new Map<String, int>.from(apiClient.deserialize(_decodeBodyBytes(response), 'Map<String, int>'));
;
} else {
return null;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
Loading