[Dart 2] Add support for Dart 2 (#754)

* Add an option for Dart2

* add dart2 samples, update travis

* fix dart installation

* Upper constraints on the SDK version

* Update dependencies

* supportDart2 option can now be passed through --additional-properties

* Update petstore tests

* Update dart2-petstore.sh

* Running tests on Dart VM

* Fixed JSON deserialization bugs

* Fixed missing initialization of postBody

* Run bin/dart2-petstore.sh to regenerate libraries

* Update pom.xml

* Added SDK version constraints in pubspec.mustache

* Run bin/dart2-petstore.sh to regenerate libraries

* move dart2 test to the end
This commit is contained in:
Yimin Lin
2018-09-01 01:49:18 +08:00
committed by William Cheng
parent 31149a5a69
commit d327c5be46
131 changed files with 10604 additions and 2 deletions

View File

@@ -0,0 +1,27 @@
part of openapi.api;
class ApiKeyAuth implements Authentication {
final String location;
final String paramName;
String apiKey;
String apiKeyPrefix;
ApiKeyAuth(this.location, this.paramName);
@override
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
String value;
if (apiKeyPrefix != null) {
value = '$apiKeyPrefix $apiKey';
} else {
value = apiKey;
}
if (location == 'query' && value != null) {
queryParams.add(QueryParam(paramName, value));
} else if (location == 'header' && value != null) {
headerParams[paramName] = value;
}
}
}

View File

@@ -0,0 +1,7 @@
part of openapi.api;
abstract class Authentication {
/// Apply authentication settings to header and query params.
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams);
}

View File

@@ -0,0 +1,14 @@
part of openapi.api;
class HttpBasicAuth implements Authentication {
String username;
String password;
@override
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
String str = (username == null ? "" : username) + ":" + (password == null ? "" : password);
headerParams["Authorization"] = "Basic " + base64.encode(utf8.encode(str));
}
}

View File

@@ -0,0 +1,18 @@
part of openapi.api;
class OAuth implements Authentication {
String accessToken;
OAuth({this.accessToken});
@override
void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {
if (accessToken != null) {
headerParams["Authorization"] = "Bearer " + accessToken;
}
}
void setAccessToken(String accessToken) {
this.accessToken = accessToken;
}
}