From c7bd75d13c14ea3ea0db8385054eb8a129d7f10b Mon Sep 17 00:00:00 2001 From: Christian Loitsch Date: Wed, 13 Jul 2016 15:44:48 +0200 Subject: [PATCH 01/10] fix: query params may be ints as well don't assume query params are Strings or Lists --- .../src/main/resources/dart/api_helper.mustache | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/dart/api_helper.mustache b/modules/swagger-codegen/src/main/resources/dart/api_helper.mustache index 9e2c30228a8..b9889382860 100644 --- a/modules/swagger-codegen/src/main/resources/dart/api_helper.mustache +++ b/modules/swagger-codegen/src/main/resources/dart/api_helper.mustache @@ -11,11 +11,11 @@ List _convertParametersForCollectionFormat( if (name == null || name.isEmpty || value == null) return params; if (value is! List) { - params.add(new QueryParam(name, value as String)); + params.add(new QueryParam(name, '$value')); return params; } - List values = value as List; + List values = value as List; // get the collection format collectionFormat = (collectionFormat == null || collectionFormat.isEmpty) @@ -23,7 +23,7 @@ List _convertParametersForCollectionFormat( : collectionFormat; // default: csv if (collectionFormat == "multi") { - return values.map((v) => new QueryParam(name, v)); + return values.map((v) => new QueryParam(name, '$v')); } String delimiter = _delimiters[collectionFormat] ?? ","; From ee3f42d6408ebebd90a16e7790a2180e6abc140f Mon Sep 17 00:00:00 2001 From: Christian Loitsch Date: Wed, 13 Jul 2016 16:33:44 +0200 Subject: [PATCH 02/10] fix dart: use correct type for QueryParams type is Iterable, not List only check params for != null if they haven't been checked already add some casts to make strong mode happy update petstore --- .../resources/dart/analysis_options.mustache | 0 .../src/main/resources/dart/api.mustache | 8 +++- .../main/resources/dart/api_client.mustache | 2 +- .../main/resources/dart/api_helper.mustache | 6 +-- samples/client/petstore/dart/lib/api.dart | 2 +- .../client/petstore/dart/lib/api/pet_api.dart | 39 +++++++------------ .../petstore/dart/lib/api/store_api.dart | 21 ++++------ .../petstore/dart/lib/api/user_api.dart | 35 ++++++----------- .../client/petstore/dart/lib/api_client.dart | 12 +++--- .../petstore/dart/lib/api_exception.dart | 2 +- .../client/petstore/dart/lib/api_helper.dart | 12 +++--- .../petstore/dart/lib/auth/api_key_auth.dart | 2 +- .../dart/lib/auth/authentication.dart | 2 +- .../dart/lib/auth/http_basic_auth.dart | 2 +- .../client/petstore/dart/lib/auth/oauth.dart | 2 +- .../petstore/dart/lib/model/api_response.dart | 2 +- .../petstore/dart/lib/model/category.dart | 2 +- .../client/petstore/dart/lib/model/order.dart | 2 +- .../client/petstore/dart/lib/model/pet.dart | 2 +- .../client/petstore/dart/lib/model/tag.dart | 2 +- .../client/petstore/dart/lib/model/user.dart | 2 +- 21 files changed, 66 insertions(+), 93 deletions(-) create mode 100644 modules/swagger-codegen/src/main/resources/dart/analysis_options.mustache diff --git a/modules/swagger-codegen/src/main/resources/dart/analysis_options.mustache b/modules/swagger-codegen/src/main/resources/dart/analysis_options.mustache new file mode 100644 index 00000000000..e69de29bb2d diff --git a/modules/swagger-codegen/src/main/resources/dart/api.mustache b/modules/swagger-codegen/src/main/resources/dart/api.mustache index 9fcd1391406..cff22ffecf9 100644 --- a/modules/swagger-codegen/src/main/resources/dart/api.mustache +++ b/modules/swagger-codegen/src/main/resources/dart/api.mustache @@ -36,9 +36,13 @@ class {{classname}} { Map headerParams = {}; Map formParams = {}; {{#queryParams}} - if("null" != {{paramName}}) { + {{^required}} + if({{paramName}} != null) { + {{/required}} queryParams.addAll(_convertParametersForCollectionFormat("{{collectionFormat}}", "{{baseName}}", {{paramName}})); + {{^required}} } + {{/required}} {{/queryParams}} {{#headerParams}}headerParams["{{baseName}}"] = {{paramName}}; {{/headerParams}} @@ -84,7 +88,7 @@ class {{classname}} { if(response.statusCode >= 400) { throw new ApiException(response.statusCode, response.body); } else if(response.body != null) { - return {{#returnType}} apiClient.deserialize(response.body, '{{{returnType}}}') {{/returnType}}; + return {{#returnType}}apiClient.deserialize(response.body, '{{{returnType}}}') as {{{returnType}}} {{/returnType}}; } else { return {{#returnType}}null{{/returnType}}; } diff --git a/modules/swagger-codegen/src/main/resources/dart/api_client.mustache b/modules/swagger-codegen/src/main/resources/dart/api_client.mustache index 075dbab135d..26c9e051a43 100644 --- a/modules/swagger-codegen/src/main/resources/dart/api_client.mustache +++ b/modules/swagger-codegen/src/main/resources/dart/api_client.mustache @@ -116,7 +116,7 @@ class ApiClient { // If collectionFormat is 'multi' a key might appear multiple times. Future invokeAPI(String path, String method, - List queryParams, + Iterable queryParams, Object body, Map headerParams, Map formParams, diff --git a/modules/swagger-codegen/src/main/resources/dart/api_helper.mustache b/modules/swagger-codegen/src/main/resources/dart/api_helper.mustache index b9889382860..0d2381ef592 100644 --- a/modules/swagger-codegen/src/main/resources/dart/api_helper.mustache +++ b/modules/swagger-codegen/src/main/resources/dart/api_helper.mustache @@ -3,9 +3,9 @@ part of {{pubName}}.api; const _delimiters = const {'csv': ',', 'ssv': ' ', 'tsv': '\t', 'pipes': '|'}; // port from Java version -List _convertParametersForCollectionFormat( +Iterable _convertParametersForCollectionFormat( String collectionFormat, String name, dynamic value) { - var params = []; + var params = []; // preconditions if (name == null || name.isEmpty || value == null) return params; @@ -23,7 +23,7 @@ List _convertParametersForCollectionFormat( : collectionFormat; // default: csv if (collectionFormat == "multi") { - return values.map((v) => new QueryParam(name, '$v')); + return values.map((v) => new QueryParam(name, '$v')) as Iterable; } String delimiter = _delimiters[collectionFormat] ?? ","; diff --git a/samples/client/petstore/dart/lib/api.dart b/samples/client/petstore/dart/lib/api.dart index 1a0b0c84cc6..667f617176e 100644 --- a/samples/client/petstore/dart/lib/api.dart +++ b/samples/client/petstore/dart/lib/api.dart @@ -1,4 +1,4 @@ -library api; +library swagger.api; import 'dart:async'; import 'dart:convert'; diff --git a/samples/client/petstore/dart/lib/api/pet_api.dart b/samples/client/petstore/dart/lib/api/pet_api.dart index 694ec340d46..45c203c51ef 100644 --- a/samples/client/petstore/dart/lib/api/pet_api.dart +++ b/samples/client/petstore/dart/lib/api/pet_api.dart @@ -1,9 +1,8 @@ -part of api; +part of swagger.api; class PetApi { - String basePath = "http://petstore.swagger.io/v2"; final ApiClient apiClient; PetApi([ApiClient apiClient]) : apiClient = apiClient ?? defaultApiClient; @@ -46,8 +45,7 @@ class PetApi { else { } - var response = await apiClient.invokeAPI(basePath, - path, + var response = await apiClient.invokeAPI(path, 'POST', queryParams, postBody, @@ -103,8 +101,7 @@ class PetApi { else { } - var response = await apiClient.invokeAPI(basePath, - path, + var response = await apiClient.invokeAPI(path, 'DELETE', queryParams, postBody, @@ -143,9 +140,7 @@ class PetApi { List queryParams = []; Map headerParams = {}; Map formParams = {}; - if("null" != status) { queryParams.addAll(_convertParametersForCollectionFormat("csv", "status", status)); - } List contentTypes = []; @@ -162,8 +157,7 @@ class PetApi { else { } - var response = await apiClient.invokeAPI(basePath, - path, + var response = await apiClient.invokeAPI(path, 'GET', queryParams, postBody, @@ -175,7 +169,7 @@ class PetApi { if(response.statusCode >= 400) { throw new ApiException(response.statusCode, response.body); } else if(response.body != null) { - return apiClient.deserialize(response.body, 'List') ; + return apiClient.deserialize(response.body, 'List') as List ; } else { return null; } @@ -202,9 +196,7 @@ class PetApi { List queryParams = []; Map headerParams = {}; Map formParams = {}; - if("null" != tags) { queryParams.addAll(_convertParametersForCollectionFormat("csv", "tags", tags)); - } List contentTypes = []; @@ -221,8 +213,7 @@ class PetApi { else { } - var response = await apiClient.invokeAPI(basePath, - path, + var response = await apiClient.invokeAPI(path, 'GET', queryParams, postBody, @@ -234,7 +225,7 @@ class PetApi { if(response.statusCode >= 400) { throw new ApiException(response.statusCode, response.body); } else if(response.body != null) { - return apiClient.deserialize(response.body, 'List') ; + return apiClient.deserialize(response.body, 'List') as List ; } else { return null; } @@ -277,8 +268,7 @@ class PetApi { else { } - var response = await apiClient.invokeAPI(basePath, - path, + var response = await apiClient.invokeAPI(path, 'GET', queryParams, postBody, @@ -290,7 +280,7 @@ class PetApi { if(response.statusCode >= 400) { throw new ApiException(response.statusCode, response.body); } else if(response.body != null) { - return apiClient.deserialize(response.body, 'Pet') ; + return apiClient.deserialize(response.body, 'Pet') as Pet ; } else { return null; } @@ -333,8 +323,7 @@ class PetApi { else { } - var response = await apiClient.invokeAPI(basePath, - path, + var response = await apiClient.invokeAPI(path, 'PUT', queryParams, postBody, @@ -403,8 +392,7 @@ if (status != null) formParams['status'] = apiClient.parameterToString(status); } - var response = await apiClient.invokeAPI(basePath, - path, + var response = await apiClient.invokeAPI(path, 'POST', queryParams, postBody, @@ -473,8 +461,7 @@ if (status != null) } - var response = await apiClient.invokeAPI(basePath, - path, + var response = await apiClient.invokeAPI(path, 'POST', queryParams, postBody, @@ -486,7 +473,7 @@ if (status != null) if(response.statusCode >= 400) { throw new ApiException(response.statusCode, response.body); } else if(response.body != null) { - return apiClient.deserialize(response.body, 'ApiResponse') ; + return apiClient.deserialize(response.body, 'ApiResponse') as ApiResponse ; } else { return null; } diff --git a/samples/client/petstore/dart/lib/api/store_api.dart b/samples/client/petstore/dart/lib/api/store_api.dart index 0e42d534603..a2bf1bb68b9 100644 --- a/samples/client/petstore/dart/lib/api/store_api.dart +++ b/samples/client/petstore/dart/lib/api/store_api.dart @@ -1,9 +1,8 @@ -part of api; +part of swagger.api; class StoreApi { - String basePath = "http://petstore.swagger.io/v2"; final ApiClient apiClient; StoreApi([ApiClient apiClient]) : apiClient = apiClient ?? defaultApiClient; @@ -46,8 +45,7 @@ class StoreApi { else { } - var response = await apiClient.invokeAPI(basePath, - path, + var response = await apiClient.invokeAPI(path, 'DELETE', queryParams, postBody, @@ -99,8 +97,7 @@ class StoreApi { else { } - var response = await apiClient.invokeAPI(basePath, - path, + var response = await apiClient.invokeAPI(path, 'GET', queryParams, postBody, @@ -112,7 +109,7 @@ class StoreApi { if(response.statusCode >= 400) { throw new ApiException(response.statusCode, response.body); } else if(response.body != null) { - return apiClient.deserialize(response.body, 'Map') ; + return apiClient.deserialize(response.body, 'Map') as Map ; } else { return null; } @@ -155,8 +152,7 @@ class StoreApi { else { } - var response = await apiClient.invokeAPI(basePath, - path, + var response = await apiClient.invokeAPI(path, 'GET', queryParams, postBody, @@ -168,7 +164,7 @@ class StoreApi { if(response.statusCode >= 400) { throw new ApiException(response.statusCode, response.body); } else if(response.body != null) { - return apiClient.deserialize(response.body, 'Order') ; + return apiClient.deserialize(response.body, 'Order') as Order ; } else { return null; } @@ -211,8 +207,7 @@ class StoreApi { else { } - var response = await apiClient.invokeAPI(basePath, - path, + var response = await apiClient.invokeAPI(path, 'POST', queryParams, postBody, @@ -224,7 +219,7 @@ class StoreApi { if(response.statusCode >= 400) { throw new ApiException(response.statusCode, response.body); } else if(response.body != null) { - return apiClient.deserialize(response.body, 'Order') ; + return apiClient.deserialize(response.body, 'Order') as Order ; } else { return null; } diff --git a/samples/client/petstore/dart/lib/api/user_api.dart b/samples/client/petstore/dart/lib/api/user_api.dart index 34481806b95..10fecbf80f0 100644 --- a/samples/client/petstore/dart/lib/api/user_api.dart +++ b/samples/client/petstore/dart/lib/api/user_api.dart @@ -1,9 +1,8 @@ -part of api; +part of swagger.api; class UserApi { - String basePath = "http://petstore.swagger.io/v2"; final ApiClient apiClient; UserApi([ApiClient apiClient]) : apiClient = apiClient ?? defaultApiClient; @@ -46,8 +45,7 @@ class UserApi { else { } - var response = await apiClient.invokeAPI(basePath, - path, + var response = await apiClient.invokeAPI(path, 'POST', queryParams, postBody, @@ -102,8 +100,7 @@ class UserApi { else { } - var response = await apiClient.invokeAPI(basePath, - path, + var response = await apiClient.invokeAPI(path, 'POST', queryParams, postBody, @@ -158,8 +155,7 @@ class UserApi { else { } - var response = await apiClient.invokeAPI(basePath, - path, + var response = await apiClient.invokeAPI(path, 'POST', queryParams, postBody, @@ -214,8 +210,7 @@ class UserApi { else { } - var response = await apiClient.invokeAPI(basePath, - path, + var response = await apiClient.invokeAPI(path, 'DELETE', queryParams, postBody, @@ -270,8 +265,7 @@ class UserApi { else { } - var response = await apiClient.invokeAPI(basePath, - path, + var response = await apiClient.invokeAPI(path, 'GET', queryParams, postBody, @@ -283,7 +277,7 @@ class UserApi { if(response.statusCode >= 400) { throw new ApiException(response.statusCode, response.body); } else if(response.body != null) { - return apiClient.deserialize(response.body, 'User') ; + return apiClient.deserialize(response.body, 'User') as User ; } else { return null; } @@ -313,12 +307,8 @@ class UserApi { List queryParams = []; Map headerParams = {}; Map formParams = {}; - if("null" != username) { queryParams.addAll(_convertParametersForCollectionFormat("", "username", username)); - } - if("null" != password) { queryParams.addAll(_convertParametersForCollectionFormat("", "password", password)); - } List contentTypes = []; @@ -335,8 +325,7 @@ class UserApi { else { } - var response = await apiClient.invokeAPI(basePath, - path, + var response = await apiClient.invokeAPI(path, 'GET', queryParams, postBody, @@ -348,7 +337,7 @@ class UserApi { if(response.statusCode >= 400) { throw new ApiException(response.statusCode, response.body); } else if(response.body != null) { - return apiClient.deserialize(response.body, 'String') ; + return apiClient.deserialize(response.body, 'String') as String ; } else { return null; } @@ -388,8 +377,7 @@ class UserApi { else { } - var response = await apiClient.invokeAPI(basePath, - path, + var response = await apiClient.invokeAPI(path, 'GET', queryParams, postBody, @@ -447,8 +435,7 @@ class UserApi { else { } - var response = await apiClient.invokeAPI(basePath, - path, + var response = await apiClient.invokeAPI(path, 'PUT', queryParams, postBody, diff --git a/samples/client/petstore/dart/lib/api_client.dart b/samples/client/petstore/dart/lib/api_client.dart index 3014e7deade..b3ee4065d2c 100644 --- a/samples/client/petstore/dart/lib/api_client.dart +++ b/samples/client/petstore/dart/lib/api_client.dart @@ -1,4 +1,4 @@ -part of api; +part of swagger.api; class QueryParam { String name; @@ -9,6 +9,7 @@ class QueryParam { class ApiClient { + String basePath; var client = new BrowserClient(); Map _defaultHeaderMap = {}; @@ -20,7 +21,7 @@ class ApiClient { final _RegList = new RegExp(r'^List<(.*)>$'); final _RegMap = new RegExp(r'^Map$'); - ApiClient() { + ApiClient({this.basePath: "http://petstore.swagger.io/v2"}) { // Setup authentications (key: authentication name, value: authentication). _authentications['petstore_auth'] = new OAuth(); _authentications['api_key'] = new ApiKeyAuth("header", "api_key"); @@ -118,10 +119,9 @@ class ApiClient { // We don't use a Map for queryParams. // If collectionFormat is 'multi' a key might appear multiple times. - Future invokeAPI(String host, - String path, + Future invokeAPI(String path, String method, - List queryParams, + Iterable queryParams, Object body, Map headerParams, Map formParams, @@ -135,7 +135,7 @@ class ApiClient { '?' + ps.join('&') : ''; - String url = host + path + queryString; + String url = basePath + path + queryString; headerParams.addAll(_defaultHeaderMap); headerParams['Content-Type'] = contentType; diff --git a/samples/client/petstore/dart/lib/api_exception.dart b/samples/client/petstore/dart/lib/api_exception.dart index c168fb512da..6a043acb7a7 100644 --- a/samples/client/petstore/dart/lib/api_exception.dart +++ b/samples/client/petstore/dart/lib/api_exception.dart @@ -1,4 +1,4 @@ -part of api; +part of swagger.api; class ApiException implements Exception { int code = 0; diff --git a/samples/client/petstore/dart/lib/api_helper.dart b/samples/client/petstore/dart/lib/api_helper.dart index fb25306d260..00d7836915a 100644 --- a/samples/client/petstore/dart/lib/api_helper.dart +++ b/samples/client/petstore/dart/lib/api_helper.dart @@ -1,21 +1,21 @@ -part of api; +part of swagger.api; const _delimiters = const {'csv': ',', 'ssv': ' ', 'tsv': '\t', 'pipes': '|'}; // port from Java version -List _convertParametersForCollectionFormat( +Iterable _convertParametersForCollectionFormat( String collectionFormat, String name, dynamic value) { - var params = []; + var params = []; // preconditions if (name == null || name.isEmpty || value == null) return params; if (value is! List) { - params.add(new QueryParam(name, value as String)); + params.add(new QueryParam(name, '$value')); return params; } - List values = value as List; + List values = value as List; // get the collection format collectionFormat = (collectionFormat == null || collectionFormat.isEmpty) @@ -23,7 +23,7 @@ List _convertParametersForCollectionFormat( : collectionFormat; // default: csv if (collectionFormat == "multi") { - return values.map((v) => new QueryParam(name, v)); + return values.map((v) => new QueryParam(name, '$v')) as Iterable; } String delimiter = _delimiters[collectionFormat] ?? ","; diff --git a/samples/client/petstore/dart/lib/auth/api_key_auth.dart b/samples/client/petstore/dart/lib/auth/api_key_auth.dart index d80d6a6a213..d46fa15e9b8 100644 --- a/samples/client/petstore/dart/lib/auth/api_key_auth.dart +++ b/samples/client/petstore/dart/lib/auth/api_key_auth.dart @@ -1,4 +1,4 @@ -part of api; +part of swagger.api; class ApiKeyAuth implements Authentication { diff --git a/samples/client/petstore/dart/lib/auth/authentication.dart b/samples/client/petstore/dart/lib/auth/authentication.dart index c0b1f92a42d..3d6b6aadcda 100644 --- a/samples/client/petstore/dart/lib/auth/authentication.dart +++ b/samples/client/petstore/dart/lib/auth/authentication.dart @@ -1,4 +1,4 @@ -part of api; +part of swagger.api; abstract class Authentication { diff --git a/samples/client/petstore/dart/lib/auth/http_basic_auth.dart b/samples/client/petstore/dart/lib/auth/http_basic_auth.dart index 0645d4358f5..7a118d6cdad 100644 --- a/samples/client/petstore/dart/lib/auth/http_basic_auth.dart +++ b/samples/client/petstore/dart/lib/auth/http_basic_auth.dart @@ -1,4 +1,4 @@ -part of api; +part of swagger.api; class HttpBasicAuth implements Authentication { diff --git a/samples/client/petstore/dart/lib/auth/oauth.dart b/samples/client/petstore/dart/lib/auth/oauth.dart index e514dd85738..405c5119a45 100644 --- a/samples/client/petstore/dart/lib/auth/oauth.dart +++ b/samples/client/petstore/dart/lib/auth/oauth.dart @@ -1,4 +1,4 @@ -part of api; +part of swagger.api; class OAuth implements Authentication { diff --git a/samples/client/petstore/dart/lib/model/api_response.dart b/samples/client/petstore/dart/lib/model/api_response.dart index e8ffe737861..b2ac2c2577e 100644 --- a/samples/client/petstore/dart/lib/model/api_response.dart +++ b/samples/client/petstore/dart/lib/model/api_response.dart @@ -1,4 +1,4 @@ -part of api; +part of swagger.api; @Entity() diff --git a/samples/client/petstore/dart/lib/model/category.dart b/samples/client/petstore/dart/lib/model/category.dart index e39966555fb..9ab2a96fc37 100644 --- a/samples/client/petstore/dart/lib/model/category.dart +++ b/samples/client/petstore/dart/lib/model/category.dart @@ -1,4 +1,4 @@ -part of api; +part of swagger.api; @Entity() diff --git a/samples/client/petstore/dart/lib/model/order.dart b/samples/client/petstore/dart/lib/model/order.dart index 1d908629b06..d7ea97b3bad 100644 --- a/samples/client/petstore/dart/lib/model/order.dart +++ b/samples/client/petstore/dart/lib/model/order.dart @@ -1,4 +1,4 @@ -part of api; +part of swagger.api; @Entity() diff --git a/samples/client/petstore/dart/lib/model/pet.dart b/samples/client/petstore/dart/lib/model/pet.dart index 8ad328b78be..03e13743763 100644 --- a/samples/client/petstore/dart/lib/model/pet.dart +++ b/samples/client/petstore/dart/lib/model/pet.dart @@ -1,4 +1,4 @@ -part of api; +part of swagger.api; @Entity() diff --git a/samples/client/petstore/dart/lib/model/tag.dart b/samples/client/petstore/dart/lib/model/tag.dart index 0541e12fb6f..485de92a615 100644 --- a/samples/client/petstore/dart/lib/model/tag.dart +++ b/samples/client/petstore/dart/lib/model/tag.dart @@ -1,4 +1,4 @@ -part of api; +part of swagger.api; @Entity() diff --git a/samples/client/petstore/dart/lib/model/user.dart b/samples/client/petstore/dart/lib/model/user.dart index fd99a51ee58..f529d9432c1 100644 --- a/samples/client/petstore/dart/lib/model/user.dart +++ b/samples/client/petstore/dart/lib/model/user.dart @@ -1,4 +1,4 @@ -part of api; +part of swagger.api; @Entity() From 7b4153cda1d1ceb9caed5104ec8e3970854d1c4f Mon Sep 17 00:00:00 2001 From: Christian Loitsch Date: Wed, 13 Jul 2016 16:36:31 +0200 Subject: [PATCH 03/10] feat dart: enable strong mode --- .../java/io/swagger/codegen/languages/DartClientCodegen.java | 1 + .../src/main/resources/dart/analysis_options.mustache | 2 ++ samples/client/petstore/dart/.analysis_options | 2 ++ 3 files changed, 5 insertions(+) create mode 100644 samples/client/petstore/dart/.analysis_options diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/DartClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/DartClientCodegen.java index a70c5c4c692..4ad6e85d772 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/DartClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/DartClientCodegen.java @@ -140,6 +140,7 @@ public void processOpts() { final String libFolder = sourceFolder + File.separator + "lib"; supportingFiles.add(new SupportingFile("pubspec.mustache", "", "pubspec.yaml")); + supportingFiles.add(new SupportingFile("analysis_options.mustache", "", ".analysis_options")); supportingFiles.add(new SupportingFile("api_client.mustache", libFolder, "api_client.dart")); supportingFiles.add(new SupportingFile("api_exception.mustache", libFolder, "api_exception.dart")); supportingFiles.add(new SupportingFile("api_helper.mustache", libFolder, "api_helper.dart")); diff --git a/modules/swagger-codegen/src/main/resources/dart/analysis_options.mustache b/modules/swagger-codegen/src/main/resources/dart/analysis_options.mustache index e69de29bb2d..518eb901a6f 100644 --- a/modules/swagger-codegen/src/main/resources/dart/analysis_options.mustache +++ b/modules/swagger-codegen/src/main/resources/dart/analysis_options.mustache @@ -0,0 +1,2 @@ +analyzer: + strong-mode: true \ No newline at end of file diff --git a/samples/client/petstore/dart/.analysis_options b/samples/client/petstore/dart/.analysis_options new file mode 100644 index 00000000000..518eb901a6f --- /dev/null +++ b/samples/client/petstore/dart/.analysis_options @@ -0,0 +1,2 @@ +analyzer: + strong-mode: true \ No newline at end of file From 2c462b0ca2c8dce85296a4f337b8970d5090de37 Mon Sep 17 00:00:00 2001 From: Christian Loitsch Date: Wed, 13 Jul 2016 18:25:35 +0200 Subject: [PATCH 04/10] feat dart: generate both browser and vm library move petstore client into subdirectory and reference generated libraries using path in pubspec.yaml --- bin/dart-petstore.sh | 10 +- .../petstore/dart/.swagger-codegen-ignore | 23 + samples/client/petstore/dart/lib/api.dart | 31 -- .../client/petstore/dart/lib/api/pet_api.dart | 494 ------------------ .../petstore/dart/lib/api/store_api.dart | 232 -------- .../petstore/dart/lib/api/user_api.dart | 468 ----------------- .../client/petstore/dart/lib/api_client.dart | 175 ------- .../petstore/dart/lib/api_exception.dart | 9 - .../client/petstore/dart/lib/api_helper.dart | 33 -- .../petstore/dart/lib/auth/api_key_auth.dart | 27 - .../dart/lib/auth/authentication.dart | 7 - .../dart/lib/auth/http_basic_auth.dart | 14 - .../client/petstore/dart/lib/auth/oauth.dart | 9 - .../petstore/dart/lib/model/api_response.dart | 26 - .../petstore/dart/lib/model/category.dart | 22 - .../client/petstore/dart/lib/model/order.dart | 38 -- .../client/petstore/dart/lib/model/pet.dart | 38 -- .../client/petstore/dart/lib/model/tag.dart | 22 - .../client/petstore/dart/lib/model/user.dart | 46 -- .../petstore/dart/{ => petstore}/LICENSE | 0 .../petstore/dart/{ => petstore}/README.md | 0 .../petstore/dart/{ => petstore}/git_push.sh | 0 .../petstore/dart/petstore/pubspec.yaml | 10 + .../dart/{ => petstore}/test/packages | 0 .../dart/{ => petstore}/test/pet_test.dart | 0 .../dart/{ => petstore}/test/store_test.dart | 0 .../dart/{ => petstore}/test/tests.dart | 0 .../dart/{ => petstore}/test/tests.html | 0 .../dart/{ => petstore}/test/user_test.dart | 0 samples/client/petstore/dart/pubspec.lock | 178 ------- samples/client/petstore/dart/pubspec.yaml | 14 - 31 files changed, 40 insertions(+), 1886 deletions(-) create mode 100644 samples/client/petstore/dart/.swagger-codegen-ignore delete mode 100644 samples/client/petstore/dart/lib/api.dart delete mode 100644 samples/client/petstore/dart/lib/api/pet_api.dart delete mode 100644 samples/client/petstore/dart/lib/api/store_api.dart delete mode 100644 samples/client/petstore/dart/lib/api/user_api.dart delete mode 100644 samples/client/petstore/dart/lib/api_client.dart delete mode 100644 samples/client/petstore/dart/lib/api_exception.dart delete mode 100644 samples/client/petstore/dart/lib/api_helper.dart delete mode 100644 samples/client/petstore/dart/lib/auth/api_key_auth.dart delete mode 100644 samples/client/petstore/dart/lib/auth/authentication.dart delete mode 100644 samples/client/petstore/dart/lib/auth/http_basic_auth.dart delete mode 100644 samples/client/petstore/dart/lib/auth/oauth.dart delete mode 100644 samples/client/petstore/dart/lib/model/api_response.dart delete mode 100644 samples/client/petstore/dart/lib/model/category.dart delete mode 100644 samples/client/petstore/dart/lib/model/order.dart delete mode 100644 samples/client/petstore/dart/lib/model/pet.dart delete mode 100644 samples/client/petstore/dart/lib/model/tag.dart delete mode 100644 samples/client/petstore/dart/lib/model/user.dart rename samples/client/petstore/dart/{ => petstore}/LICENSE (100%) rename samples/client/petstore/dart/{ => petstore}/README.md (100%) rename samples/client/petstore/dart/{ => petstore}/git_push.sh (100%) create mode 100644 samples/client/petstore/dart/petstore/pubspec.yaml rename samples/client/petstore/dart/{ => petstore}/test/packages (100%) rename samples/client/petstore/dart/{ => petstore}/test/pet_test.dart (100%) rename samples/client/petstore/dart/{ => petstore}/test/store_test.dart (100%) rename samples/client/petstore/dart/{ => petstore}/test/tests.dart (100%) rename samples/client/petstore/dart/{ => petstore}/test/tests.html (100%) rename samples/client/petstore/dart/{ => petstore}/test/user_test.dart (100%) delete mode 100644 samples/client/petstore/dart/pubspec.lock delete mode 100644 samples/client/petstore/dart/pubspec.yaml diff --git a/bin/dart-petstore.sh b/bin/dart-petstore.sh index 9f59540a5a7..2481fca0368 100755 --- a/bin/dart-petstore.sh +++ b/bin/dart-petstore.sh @@ -26,9 +26,13 @@ fi # if you've executed sbt assembly previously it will use that instead. export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties" -ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l dart -o samples/client/petstore/dart" +# first generate swagger library for browser rest client +#ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l dart -o samples/client/petstore/dart/swagger" +java $JAVA_OPTS -jar $executable $ags + +# then generate swagger library for vm # for dart vm lib generation: -#ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l dart -o samples/client/petstore/dart --additional-properties browserClient=false" +agsvm="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l dart -o samples/client/petstore/dart/swagger_vm -DbrowserClient=false -DpubName=swagger_vm" +java $JAVA_OPTS -jar $executable $agsvm -java $JAVA_OPTS -jar $executable $ags diff --git a/samples/client/petstore/dart/.swagger-codegen-ignore b/samples/client/petstore/dart/.swagger-codegen-ignore new file mode 100644 index 00000000000..c5fa491b4c5 --- /dev/null +++ b/samples/client/petstore/dart/.swagger-codegen-ignore @@ -0,0 +1,23 @@ +# Swagger Codegen Ignore +# Generated by swagger-codegen https://github.com/swagger-api/swagger-codegen + +# Use this file to prevent files from being overwritten by the generator. +# The patterns follow closely to .gitignore or .dockerignore. + +# As an example, the C# client generator defines ApiClient.cs. +# You can make changes and tell Swagger Codgen to ignore just this file by uncommenting the following line: +#ApiClient.cs + +# You can match any string of characters against a directory, file or extension with a single asterisk (*): +#foo/*/qux +# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux + +# You can recursively match patterns against a directory, file or extension with a double asterisk (**): +#foo/**/qux +# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux + +# You can also negate patterns with an exclamation (!). +# For example, you can ignore all files in a docs folder with the file extension .md: +#docs/*.md +# Then explicitly reverse the ignore rule for a single file: +#!docs/README.md diff --git a/samples/client/petstore/dart/lib/api.dart b/samples/client/petstore/dart/lib/api.dart deleted file mode 100644 index 1a0b0c84cc6..00000000000 --- a/samples/client/petstore/dart/lib/api.dart +++ /dev/null @@ -1,31 +0,0 @@ -library api; - -import 'dart:async'; -import 'dart:convert'; -import 'package:http/browser_client.dart'; -import 'package:http/http.dart'; -import 'package:dartson/dartson.dart'; -import 'package:intl/intl.dart'; - -part 'api_client.dart'; -part 'api_helper.dart'; -part 'api_exception.dart'; -part 'auth/authentication.dart'; -part 'auth/api_key_auth.dart'; -part 'auth/oauth.dart'; -part 'auth/http_basic_auth.dart'; - -part 'api/pet_api.dart'; -part 'api/store_api.dart'; -part 'api/user_api.dart'; - -part 'model/api_response.dart'; -part 'model/category.dart'; -part 'model/order.dart'; -part 'model/pet.dart'; -part 'model/tag.dart'; -part 'model/user.dart'; - - -ApiClient defaultApiClient = new ApiClient(); - diff --git a/samples/client/petstore/dart/lib/api/pet_api.dart b/samples/client/petstore/dart/lib/api/pet_api.dart deleted file mode 100644 index 694ec340d46..00000000000 --- a/samples/client/petstore/dart/lib/api/pet_api.dart +++ /dev/null @@ -1,494 +0,0 @@ -part of api; - - - -class PetApi { - String basePath = "http://petstore.swagger.io/v2"; - final ApiClient apiClient; - - PetApi([ApiClient apiClient]) : apiClient = apiClient ?? defaultApiClient; - - /// Add a new pet to the store - /// - /// - Future addPet(Pet body, { bool justIgnoreThisFlag: true}) async { - if (!justIgnoreThisFlag) { - print('Why??? Just trust me, I only need this variable inside the mustache codegen template.'); - // This code may be removed as soon as dart accepts trailing spaces (has already been implemented). - } - Object postBody = body; - - // verify required params are set - if(body == null) { - throw new ApiException(400, "Missing required param: body"); - } - - // create path and map variables - String path = "/pet".replaceAll("{format}","json"); - - // query params - List queryParams = []; - Map headerParams = {}; - Map formParams = {}; - - List contentTypes = ["application/json","application/xml"]; - - String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; - List authNames = ["petstore_auth"]; - - if(contentType.startsWith("multipart/form-data")) { - bool hasFields = false; - MultipartRequest mp = new MultipartRequest(null, null); - - if(hasFields) - postBody = mp; - } - else { - } - - var response = await apiClient.invokeAPI(basePath, - path, - 'POST', - queryParams, - postBody, - headerParams, - formParams, - contentType, - authNames); - - if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); - } else if(response.body != null) { - return ; - } else { - return ; - } - } - /// Deletes a pet - /// - /// - Future deletePet(int petId, { String apiKey, bool justIgnoreThisFlag: true}) async { - if (!justIgnoreThisFlag) { - print('Why??? Just trust me, I only need this variable inside the mustache codegen template.'); - // This code may be removed as soon as dart accepts trailing spaces (has already been implemented). - } - Object postBody = null; - - // verify required params are set - if(petId == null) { - throw new ApiException(400, "Missing required param: petId"); - } - - // create path and map variables - String path = "/pet/{petId}".replaceAll("{format}","json").replaceAll("{" + "petId" + "}", petId.toString()); - - // query params - List queryParams = []; - Map headerParams = {}; - Map formParams = {}; - headerParams["api_key"] = apiKey; - - List contentTypes = []; - - String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; - List authNames = ["petstore_auth"]; - - if(contentType.startsWith("multipart/form-data")) { - bool hasFields = false; - MultipartRequest mp = new MultipartRequest(null, null); - - if(hasFields) - postBody = mp; - } - else { - } - - var response = await apiClient.invokeAPI(basePath, - path, - 'DELETE', - queryParams, - postBody, - headerParams, - formParams, - contentType, - authNames); - - if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); - } else if(response.body != null) { - return ; - } else { - return ; - } - } - /// Finds Pets by status - /// - /// Multiple status values can be provided with comma separated strings - Future> findPetsByStatus(List status, { bool justIgnoreThisFlag: true}) async { - if (!justIgnoreThisFlag) { - print('Why??? Just trust me, I only need this variable inside the mustache codegen template.'); - // This code may be removed as soon as dart accepts trailing spaces (has already been implemented). - } - Object postBody = null; - - // verify required params are set - if(status == null) { - throw new ApiException(400, "Missing required param: status"); - } - - // create path and map variables - String path = "/pet/findByStatus".replaceAll("{format}","json"); - - // query params - List queryParams = []; - Map headerParams = {}; - Map formParams = {}; - if("null" != status) { - queryParams.addAll(_convertParametersForCollectionFormat("csv", "status", status)); - } - - List contentTypes = []; - - String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; - List authNames = ["petstore_auth"]; - - if(contentType.startsWith("multipart/form-data")) { - bool hasFields = false; - MultipartRequest mp = new MultipartRequest(null, null); - - if(hasFields) - postBody = mp; - } - else { - } - - var response = await apiClient.invokeAPI(basePath, - path, - 'GET', - queryParams, - postBody, - headerParams, - formParams, - contentType, - authNames); - - if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); - } else if(response.body != null) { - return apiClient.deserialize(response.body, 'List') ; - } else { - return null; - } - } - /// Finds Pets by tags - /// - /// Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. - Future> findPetsByTags(List tags, { bool justIgnoreThisFlag: true}) async { - if (!justIgnoreThisFlag) { - print('Why??? Just trust me, I only need this variable inside the mustache codegen template.'); - // This code may be removed as soon as dart accepts trailing spaces (has already been implemented). - } - Object postBody = null; - - // verify required params are set - if(tags == null) { - throw new ApiException(400, "Missing required param: tags"); - } - - // create path and map variables - String path = "/pet/findByTags".replaceAll("{format}","json"); - - // query params - List queryParams = []; - Map headerParams = {}; - Map formParams = {}; - if("null" != tags) { - queryParams.addAll(_convertParametersForCollectionFormat("csv", "tags", tags)); - } - - List contentTypes = []; - - String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; - List authNames = ["petstore_auth"]; - - if(contentType.startsWith("multipart/form-data")) { - bool hasFields = false; - MultipartRequest mp = new MultipartRequest(null, null); - - if(hasFields) - postBody = mp; - } - else { - } - - var response = await apiClient.invokeAPI(basePath, - path, - 'GET', - queryParams, - postBody, - headerParams, - formParams, - contentType, - authNames); - - if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); - } else if(response.body != null) { - return apiClient.deserialize(response.body, 'List') ; - } else { - return null; - } - } - /// Find pet by ID - /// - /// Returns a single pet - Future getPetById(int petId, { bool justIgnoreThisFlag: true}) async { - if (!justIgnoreThisFlag) { - print('Why??? Just trust me, I only need this variable inside the mustache codegen template.'); - // This code may be removed as soon as dart accepts trailing spaces (has already been implemented). - } - Object postBody = null; - - // verify required params are set - if(petId == null) { - throw new ApiException(400, "Missing required param: petId"); - } - - // create path and map variables - String path = "/pet/{petId}".replaceAll("{format}","json").replaceAll("{" + "petId" + "}", petId.toString()); - - // query params - List queryParams = []; - Map headerParams = {}; - Map formParams = {}; - - List contentTypes = []; - - String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; - List authNames = ["api_key"]; - - if(contentType.startsWith("multipart/form-data")) { - bool hasFields = false; - MultipartRequest mp = new MultipartRequest(null, null); - - if(hasFields) - postBody = mp; - } - else { - } - - var response = await apiClient.invokeAPI(basePath, - path, - 'GET', - queryParams, - postBody, - headerParams, - formParams, - contentType, - authNames); - - if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); - } else if(response.body != null) { - return apiClient.deserialize(response.body, 'Pet') ; - } else { - return null; - } - } - /// Update an existing pet - /// - /// - Future updatePet(Pet body, { bool justIgnoreThisFlag: true}) async { - if (!justIgnoreThisFlag) { - print('Why??? Just trust me, I only need this variable inside the mustache codegen template.'); - // This code may be removed as soon as dart accepts trailing spaces (has already been implemented). - } - Object postBody = body; - - // verify required params are set - if(body == null) { - throw new ApiException(400, "Missing required param: body"); - } - - // create path and map variables - String path = "/pet".replaceAll("{format}","json"); - - // query params - List queryParams = []; - Map headerParams = {}; - Map formParams = {}; - - List contentTypes = ["application/json","application/xml"]; - - String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; - List authNames = ["petstore_auth"]; - - if(contentType.startsWith("multipart/form-data")) { - bool hasFields = false; - MultipartRequest mp = new MultipartRequest(null, null); - - if(hasFields) - postBody = mp; - } - else { - } - - var response = await apiClient.invokeAPI(basePath, - path, - 'PUT', - queryParams, - postBody, - headerParams, - formParams, - contentType, - authNames); - - if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); - } else if(response.body != null) { - return ; - } else { - return ; - } - } - /// Updates a pet in the store with form data - /// - /// - Future updatePetWithForm(int petId, { String name, String status, bool justIgnoreThisFlag: true}) async { - if (!justIgnoreThisFlag) { - print('Why??? Just trust me, I only need this variable inside the mustache codegen template.'); - // This code may be removed as soon as dart accepts trailing spaces (has already been implemented). - } - Object postBody = null; - - // verify required params are set - if(petId == null) { - throw new ApiException(400, "Missing required param: petId"); - } - - // create path and map variables - String path = "/pet/{petId}".replaceAll("{format}","json").replaceAll("{" + "petId" + "}", petId.toString()); - - // query params - List queryParams = []; - Map headerParams = {}; - Map formParams = {}; - - List contentTypes = ["application/x-www-form-urlencoded"]; - - String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; - List authNames = ["petstore_auth"]; - - if(contentType.startsWith("multipart/form-data")) { - bool hasFields = false; - MultipartRequest mp = new MultipartRequest(null, null); - - if (name != null) { - hasFields = true; - mp.fields['name'] = apiClient.parameterToString(name); - } - - if (status != null) { - hasFields = true; - mp.fields['status'] = apiClient.parameterToString(status); - } - - if(hasFields) - postBody = mp; - } - else { - if (name != null) - formParams['name'] = apiClient.parameterToString(name); -if (status != null) - formParams['status'] = apiClient.parameterToString(status); - } - - var response = await apiClient.invokeAPI(basePath, - path, - 'POST', - queryParams, - postBody, - headerParams, - formParams, - contentType, - authNames); - - if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); - } else if(response.body != null) { - return ; - } else { - return ; - } - } - /// uploads an image - /// - /// - Future uploadFile(int petId, { String additionalMetadata, MultipartFile file, bool justIgnoreThisFlag: true}) async { - if (!justIgnoreThisFlag) { - print('Why??? Just trust me, I only need this variable inside the mustache codegen template.'); - // This code may be removed as soon as dart accepts trailing spaces (has already been implemented). - } - Object postBody = null; - - // verify required params are set - if(petId == null) { - throw new ApiException(400, "Missing required param: petId"); - } - - // create path and map variables - String path = "/pet/{petId}/uploadImage".replaceAll("{format}","json").replaceAll("{" + "petId" + "}", petId.toString()); - - // query params - List queryParams = []; - Map headerParams = {}; - Map formParams = {}; - - List contentTypes = ["multipart/form-data"]; - - String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; - List authNames = ["petstore_auth"]; - - if(contentType.startsWith("multipart/form-data")) { - bool hasFields = false; - MultipartRequest mp = new MultipartRequest(null, null); - - if (additionalMetadata != null) { - hasFields = true; - mp.fields['additionalMetadata'] = apiClient.parameterToString(additionalMetadata); - } - - if (file != null) { - hasFields = true; - mp.fields['file'] = file.field; - mp.files.add(file); - } - - if(hasFields) - postBody = mp; - } - else { - if (additionalMetadata != null) - formParams['additionalMetadata'] = apiClient.parameterToString(additionalMetadata); - - } - - var response = await apiClient.invokeAPI(basePath, - path, - 'POST', - queryParams, - postBody, - headerParams, - formParams, - contentType, - authNames); - - if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); - } else if(response.body != null) { - return apiClient.deserialize(response.body, 'ApiResponse') ; - } else { - return null; - } - } -} diff --git a/samples/client/petstore/dart/lib/api/store_api.dart b/samples/client/petstore/dart/lib/api/store_api.dart deleted file mode 100644 index 0e42d534603..00000000000 --- a/samples/client/petstore/dart/lib/api/store_api.dart +++ /dev/null @@ -1,232 +0,0 @@ -part of api; - - - -class StoreApi { - String basePath = "http://petstore.swagger.io/v2"; - final ApiClient apiClient; - - StoreApi([ApiClient apiClient]) : apiClient = apiClient ?? defaultApiClient; - - /// Delete purchase order by ID - /// - /// For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors - Future deleteOrder(String orderId, { bool justIgnoreThisFlag: true}) async { - if (!justIgnoreThisFlag) { - print('Why??? Just trust me, I only need this variable inside the mustache codegen template.'); - // This code may be removed as soon as dart accepts trailing spaces (has already been implemented). - } - Object postBody = null; - - // verify required params are set - if(orderId == null) { - throw new ApiException(400, "Missing required param: orderId"); - } - - // create path and map variables - String path = "/store/order/{orderId}".replaceAll("{format}","json").replaceAll("{" + "orderId" + "}", orderId.toString()); - - // query params - List queryParams = []; - Map headerParams = {}; - Map formParams = {}; - - List contentTypes = []; - - String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; - List authNames = []; - - if(contentType.startsWith("multipart/form-data")) { - bool hasFields = false; - MultipartRequest mp = new MultipartRequest(null, null); - - if(hasFields) - postBody = mp; - } - else { - } - - var response = await apiClient.invokeAPI(basePath, - path, - 'DELETE', - queryParams, - postBody, - headerParams, - formParams, - contentType, - authNames); - - if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); - } else if(response.body != null) { - return ; - } else { - return ; - } - } - /// Returns pet inventories by status - /// - /// Returns a map of status codes to quantities - Future> getInventory( { bool justIgnoreThisFlag: true}) async { - if (!justIgnoreThisFlag) { - print('Why??? Just trust me, I only need this variable inside the mustache codegen template.'); - // This code may be removed as soon as dart accepts trailing spaces (has already been implemented). - } - Object postBody = null; - - // verify required params are set - - // create path and map variables - String path = "/store/inventory".replaceAll("{format}","json"); - - // query params - List queryParams = []; - Map headerParams = {}; - Map formParams = {}; - - List contentTypes = []; - - String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; - List authNames = ["api_key"]; - - if(contentType.startsWith("multipart/form-data")) { - bool hasFields = false; - MultipartRequest mp = new MultipartRequest(null, null); - - if(hasFields) - postBody = mp; - } - else { - } - - var response = await apiClient.invokeAPI(basePath, - path, - 'GET', - queryParams, - postBody, - headerParams, - formParams, - contentType, - authNames); - - if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); - } else if(response.body != null) { - return apiClient.deserialize(response.body, 'Map') ; - } else { - return null; - } - } - /// Find purchase order by ID - /// - /// For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions - Future getOrderById(int orderId, { bool justIgnoreThisFlag: true}) async { - if (!justIgnoreThisFlag) { - print('Why??? Just trust me, I only need this variable inside the mustache codegen template.'); - // This code may be removed as soon as dart accepts trailing spaces (has already been implemented). - } - Object postBody = null; - - // verify required params are set - if(orderId == null) { - throw new ApiException(400, "Missing required param: orderId"); - } - - // create path and map variables - String path = "/store/order/{orderId}".replaceAll("{format}","json").replaceAll("{" + "orderId" + "}", orderId.toString()); - - // query params - List queryParams = []; - Map headerParams = {}; - Map formParams = {}; - - List contentTypes = []; - - String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; - List authNames = []; - - if(contentType.startsWith("multipart/form-data")) { - bool hasFields = false; - MultipartRequest mp = new MultipartRequest(null, null); - - if(hasFields) - postBody = mp; - } - else { - } - - var response = await apiClient.invokeAPI(basePath, - path, - 'GET', - queryParams, - postBody, - headerParams, - formParams, - contentType, - authNames); - - if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); - } else if(response.body != null) { - return apiClient.deserialize(response.body, 'Order') ; - } else { - return null; - } - } - /// Place an order for a pet - /// - /// - Future placeOrder(Order body, { bool justIgnoreThisFlag: true}) async { - if (!justIgnoreThisFlag) { - print('Why??? Just trust me, I only need this variable inside the mustache codegen template.'); - // This code may be removed as soon as dart accepts trailing spaces (has already been implemented). - } - Object postBody = body; - - // verify required params are set - if(body == null) { - throw new ApiException(400, "Missing required param: body"); - } - - // create path and map variables - String path = "/store/order".replaceAll("{format}","json"); - - // query params - List queryParams = []; - Map headerParams = {}; - Map formParams = {}; - - List contentTypes = []; - - String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; - List authNames = []; - - if(contentType.startsWith("multipart/form-data")) { - bool hasFields = false; - MultipartRequest mp = new MultipartRequest(null, null); - - if(hasFields) - postBody = mp; - } - else { - } - - var response = await apiClient.invokeAPI(basePath, - path, - 'POST', - queryParams, - postBody, - headerParams, - formParams, - contentType, - authNames); - - if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); - } else if(response.body != null) { - return apiClient.deserialize(response.body, 'Order') ; - } else { - return null; - } - } -} diff --git a/samples/client/petstore/dart/lib/api/user_api.dart b/samples/client/petstore/dart/lib/api/user_api.dart deleted file mode 100644 index 34481806b95..00000000000 --- a/samples/client/petstore/dart/lib/api/user_api.dart +++ /dev/null @@ -1,468 +0,0 @@ -part of api; - - - -class UserApi { - String basePath = "http://petstore.swagger.io/v2"; - final ApiClient apiClient; - - UserApi([ApiClient apiClient]) : apiClient = apiClient ?? defaultApiClient; - - /// Create user - /// - /// This can only be done by the logged in user. - Future createUser(User body, { bool justIgnoreThisFlag: true}) async { - if (!justIgnoreThisFlag) { - print('Why??? Just trust me, I only need this variable inside the mustache codegen template.'); - // This code may be removed as soon as dart accepts trailing spaces (has already been implemented). - } - Object postBody = body; - - // verify required params are set - if(body == null) { - throw new ApiException(400, "Missing required param: body"); - } - - // create path and map variables - String path = "/user".replaceAll("{format}","json"); - - // query params - List queryParams = []; - Map headerParams = {}; - Map formParams = {}; - - List contentTypes = []; - - String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; - List authNames = []; - - if(contentType.startsWith("multipart/form-data")) { - bool hasFields = false; - MultipartRequest mp = new MultipartRequest(null, null); - - if(hasFields) - postBody = mp; - } - else { - } - - var response = await apiClient.invokeAPI(basePath, - path, - 'POST', - queryParams, - postBody, - headerParams, - formParams, - contentType, - authNames); - - if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); - } else if(response.body != null) { - return ; - } else { - return ; - } - } - /// Creates list of users with given input array - /// - /// - Future createUsersWithArrayInput(List body, { bool justIgnoreThisFlag: true}) async { - if (!justIgnoreThisFlag) { - print('Why??? Just trust me, I only need this variable inside the mustache codegen template.'); - // This code may be removed as soon as dart accepts trailing spaces (has already been implemented). - } - Object postBody = body; - - // verify required params are set - if(body == null) { - throw new ApiException(400, "Missing required param: body"); - } - - // create path and map variables - String path = "/user/createWithArray".replaceAll("{format}","json"); - - // query params - List queryParams = []; - Map headerParams = {}; - Map formParams = {}; - - List contentTypes = []; - - String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; - List authNames = []; - - if(contentType.startsWith("multipart/form-data")) { - bool hasFields = false; - MultipartRequest mp = new MultipartRequest(null, null); - - if(hasFields) - postBody = mp; - } - else { - } - - var response = await apiClient.invokeAPI(basePath, - path, - 'POST', - queryParams, - postBody, - headerParams, - formParams, - contentType, - authNames); - - if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); - } else if(response.body != null) { - return ; - } else { - return ; - } - } - /// Creates list of users with given input array - /// - /// - Future createUsersWithListInput(List body, { bool justIgnoreThisFlag: true}) async { - if (!justIgnoreThisFlag) { - print('Why??? Just trust me, I only need this variable inside the mustache codegen template.'); - // This code may be removed as soon as dart accepts trailing spaces (has already been implemented). - } - Object postBody = body; - - // verify required params are set - if(body == null) { - throw new ApiException(400, "Missing required param: body"); - } - - // create path and map variables - String path = "/user/createWithList".replaceAll("{format}","json"); - - // query params - List queryParams = []; - Map headerParams = {}; - Map formParams = {}; - - List contentTypes = []; - - String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; - List authNames = []; - - if(contentType.startsWith("multipart/form-data")) { - bool hasFields = false; - MultipartRequest mp = new MultipartRequest(null, null); - - if(hasFields) - postBody = mp; - } - else { - } - - var response = await apiClient.invokeAPI(basePath, - path, - 'POST', - queryParams, - postBody, - headerParams, - formParams, - contentType, - authNames); - - if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); - } else if(response.body != null) { - return ; - } else { - return ; - } - } - /// Delete user - /// - /// This can only be done by the logged in user. - Future deleteUser(String username, { bool justIgnoreThisFlag: true}) async { - if (!justIgnoreThisFlag) { - print('Why??? Just trust me, I only need this variable inside the mustache codegen template.'); - // This code may be removed as soon as dart accepts trailing spaces (has already been implemented). - } - Object postBody = null; - - // verify required params are set - if(username == null) { - throw new ApiException(400, "Missing required param: username"); - } - - // create path and map variables - String path = "/user/{username}".replaceAll("{format}","json").replaceAll("{" + "username" + "}", username.toString()); - - // query params - List queryParams = []; - Map headerParams = {}; - Map formParams = {}; - - List contentTypes = []; - - String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; - List authNames = []; - - if(contentType.startsWith("multipart/form-data")) { - bool hasFields = false; - MultipartRequest mp = new MultipartRequest(null, null); - - if(hasFields) - postBody = mp; - } - else { - } - - var response = await apiClient.invokeAPI(basePath, - path, - 'DELETE', - queryParams, - postBody, - headerParams, - formParams, - contentType, - authNames); - - if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); - } else if(response.body != null) { - return ; - } else { - return ; - } - } - /// Get user by user name - /// - /// - Future getUserByName(String username, { bool justIgnoreThisFlag: true}) async { - if (!justIgnoreThisFlag) { - print('Why??? Just trust me, I only need this variable inside the mustache codegen template.'); - // This code may be removed as soon as dart accepts trailing spaces (has already been implemented). - } - Object postBody = null; - - // verify required params are set - if(username == null) { - throw new ApiException(400, "Missing required param: username"); - } - - // create path and map variables - String path = "/user/{username}".replaceAll("{format}","json").replaceAll("{" + "username" + "}", username.toString()); - - // query params - List queryParams = []; - Map headerParams = {}; - Map formParams = {}; - - List contentTypes = []; - - String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; - List authNames = []; - - if(contentType.startsWith("multipart/form-data")) { - bool hasFields = false; - MultipartRequest mp = new MultipartRequest(null, null); - - if(hasFields) - postBody = mp; - } - else { - } - - var response = await apiClient.invokeAPI(basePath, - path, - 'GET', - queryParams, - postBody, - headerParams, - formParams, - contentType, - authNames); - - if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); - } else if(response.body != null) { - return apiClient.deserialize(response.body, 'User') ; - } else { - return null; - } - } - /// Logs user into the system - /// - /// - Future loginUser(String username, String password, { bool justIgnoreThisFlag: true}) async { - if (!justIgnoreThisFlag) { - print('Why??? Just trust me, I only need this variable inside the mustache codegen template.'); - // This code may be removed as soon as dart accepts trailing spaces (has already been implemented). - } - Object postBody = null; - - // verify required params are set - if(username == null) { - throw new ApiException(400, "Missing required param: username"); - } - if(password == null) { - throw new ApiException(400, "Missing required param: password"); - } - - // create path and map variables - String path = "/user/login".replaceAll("{format}","json"); - - // query params - List queryParams = []; - Map headerParams = {}; - Map formParams = {}; - if("null" != username) { - queryParams.addAll(_convertParametersForCollectionFormat("", "username", username)); - } - if("null" != password) { - queryParams.addAll(_convertParametersForCollectionFormat("", "password", password)); - } - - List contentTypes = []; - - String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; - List authNames = []; - - if(contentType.startsWith("multipart/form-data")) { - bool hasFields = false; - MultipartRequest mp = new MultipartRequest(null, null); - - if(hasFields) - postBody = mp; - } - else { - } - - var response = await apiClient.invokeAPI(basePath, - path, - 'GET', - queryParams, - postBody, - headerParams, - formParams, - contentType, - authNames); - - if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); - } else if(response.body != null) { - return apiClient.deserialize(response.body, 'String') ; - } else { - return null; - } - } - /// Logs out current logged in user session - /// - /// - Future logoutUser( { bool justIgnoreThisFlag: true}) async { - if (!justIgnoreThisFlag) { - print('Why??? Just trust me, I only need this variable inside the mustache codegen template.'); - // This code may be removed as soon as dart accepts trailing spaces (has already been implemented). - } - Object postBody = null; - - // verify required params are set - - // create path and map variables - String path = "/user/logout".replaceAll("{format}","json"); - - // query params - List queryParams = []; - Map headerParams = {}; - Map formParams = {}; - - List contentTypes = []; - - String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; - List authNames = []; - - if(contentType.startsWith("multipart/form-data")) { - bool hasFields = false; - MultipartRequest mp = new MultipartRequest(null, null); - - if(hasFields) - postBody = mp; - } - else { - } - - var response = await apiClient.invokeAPI(basePath, - path, - 'GET', - queryParams, - postBody, - headerParams, - formParams, - contentType, - authNames); - - if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); - } else if(response.body != null) { - return ; - } else { - return ; - } - } - /// Updated user - /// - /// This can only be done by the logged in user. - Future updateUser(String username, User body, { bool justIgnoreThisFlag: true}) async { - if (!justIgnoreThisFlag) { - print('Why??? Just trust me, I only need this variable inside the mustache codegen template.'); - // This code may be removed as soon as dart accepts trailing spaces (has already been implemented). - } - Object postBody = body; - - // verify required params are set - if(username == null) { - throw new ApiException(400, "Missing required param: username"); - } - if(body == null) { - throw new ApiException(400, "Missing required param: body"); - } - - // create path and map variables - String path = "/user/{username}".replaceAll("{format}","json").replaceAll("{" + "username" + "}", username.toString()); - - // query params - List queryParams = []; - Map headerParams = {}; - Map formParams = {}; - - List contentTypes = []; - - String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; - List authNames = []; - - if(contentType.startsWith("multipart/form-data")) { - bool hasFields = false; - MultipartRequest mp = new MultipartRequest(null, null); - - if(hasFields) - postBody = mp; - } - else { - } - - var response = await apiClient.invokeAPI(basePath, - path, - 'PUT', - queryParams, - postBody, - headerParams, - formParams, - contentType, - authNames); - - if(response.statusCode >= 400) { - throw new ApiException(response.statusCode, response.body); - } else if(response.body != null) { - return ; - } else { - return ; - } - } -} diff --git a/samples/client/petstore/dart/lib/api_client.dart b/samples/client/petstore/dart/lib/api_client.dart deleted file mode 100644 index 3014e7deade..00000000000 --- a/samples/client/petstore/dart/lib/api_client.dart +++ /dev/null @@ -1,175 +0,0 @@ -part of api; - -class QueryParam { - String name; - String value; - - QueryParam(this.name, this.value); -} - -class ApiClient { - - var client = new BrowserClient(); - - Map _defaultHeaderMap = {}; - Map _authentications = {}; - - final dson = new Dartson.JSON(); - final DateFormat _dateFormatter = new DateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); - - final _RegList = new RegExp(r'^List<(.*)>$'); - final _RegMap = new RegExp(r'^Map$'); - - ApiClient() { - // Setup authentications (key: authentication name, value: authentication). - _authentications['petstore_auth'] = new OAuth(); - _authentications['api_key'] = new ApiKeyAuth("header", "api_key"); - } - - void addDefaultHeader(String key, String value) { - _defaultHeaderMap[key] = value; - } - - /// Format the given Date object into string. - String formatDate(DateTime date) { - return _dateFormatter.format(date); - } - - /// Format the given parameter object into string. - String parameterToString(Object param) { - if (param == null) { - return ''; - } else if (param is DateTime) { - return formatDate(param); - } else if (param is List) { - return (param).join(','); - } else { - return param.toString(); - } - } - - dynamic _deserialize(dynamic value, String targetType) { - try { - switch (targetType) { - case 'String': - return '$value'; - case 'int': - return value is int ? value : int.parse('$value'); - case 'bool': - return value is bool ? value : '$value'.toLowerCase() == 'true'; - case 'double': - return value is double ? value : double.parse('$value'); - case 'ApiResponse': - return dson.map(value, new ApiResponse()); - case 'Category': - return dson.map(value, new Category()); - case 'Order': - return dson.map(value, new Order()); - case 'Pet': - return dson.map(value, new Pet()); - case 'Tag': - return dson.map(value, new Tag()); - case 'User': - return dson.map(value, new User()); - default: - { - Match match; - if (value is List && - (match = _RegList.firstMatch(targetType)) != null) { - var valueL = value as List; - var newTargetType = match[1]; - return valueL.map((v) => _deserialize(v, newTargetType)).toList(); - } else if (value is Map && - (match = _RegMap.firstMatch(targetType)) != null) { - var valueM = value as Map; - var newTargetType = match[1]; - return new Map.fromIterables(valueM.keys, - valueM.values.map((v) => _deserialize(v, newTargetType))); - } - } - } - } catch(e) { - // Just throw the ApiException below - } - throw new ApiException(500, 'Could not find a suitable class for deserialization'); - } - - dynamic deserialize(String json, String targetType) { - // Remove all spaces. Necessary for reg expressions as well. - targetType = targetType.replaceAll(' ', ''); - - if (targetType == 'String') return json; - - var decodedJson = JSON.decode(json); - return _deserialize(decodedJson, targetType); - } - - String serialize(Object obj) { - String serialized = ''; - if (obj == null) { - serialized = ''; - } else if (obj is String) { - serialized = obj; - } else { - serialized = dson.encode(obj); - } - return serialized; - } - - // We don't use a Map for queryParams. - // If collectionFormat is 'multi' a key might appear multiple times. - Future invokeAPI(String host, - String path, - String method, - List queryParams, - Object body, - Map headerParams, - Map formParams, - String contentType, - List authNames) async { - - _updateParamsForAuth(authNames, queryParams, headerParams); - - var ps = queryParams.where((p) => p.value != null).map((p) => '${p.name}=${p.value}'); - String queryString = ps.isNotEmpty ? - '?' + ps.join('&') : - ''; - - String url = host + path + queryString; - - headerParams.addAll(_defaultHeaderMap); - headerParams['Content-Type'] = contentType; - - if(body is MultipartRequest) { - var request = new MultipartRequest(method, Uri.parse(url)); - request.fields.addAll(body.fields); - request.files.addAll(body.files); - request.headers.addAll(body.headers); - request.headers.addAll(headerParams); - var response = await client.send(request); - return Response.fromStream(response); - } else { - var msgBody = contentType == "application/x-www-form-urlencoded" ? formParams : serialize(body); - switch(method) { - case "POST": - return client.post(url, headers: headerParams, body: msgBody); - case "PUT": - return client.put(url, headers: headerParams, body: msgBody); - case "DELETE": - return client.delete(url, headers: headerParams); - default: - return client.get(url, headers: headerParams); - } - } - } - - /// Update query and header parameters based on authentication settings. - /// @param authNames The authentications to apply - void _updateParamsForAuth(List authNames, List queryParams, Map headerParams) { - authNames.forEach((authName) { - Authentication auth = _authentications[authName]; - if (auth == null) throw new ArgumentError("Authentication undefined: " + authName); - auth.applyToParams(queryParams, headerParams); - }); - } -} diff --git a/samples/client/petstore/dart/lib/api_exception.dart b/samples/client/petstore/dart/lib/api_exception.dart deleted file mode 100644 index c168fb512da..00000000000 --- a/samples/client/petstore/dart/lib/api_exception.dart +++ /dev/null @@ -1,9 +0,0 @@ -part of api; - -class ApiException implements Exception { - int code = 0; - String message = null; - - ApiException(this.code, this.message); - -} \ No newline at end of file diff --git a/samples/client/petstore/dart/lib/api_helper.dart b/samples/client/petstore/dart/lib/api_helper.dart deleted file mode 100644 index fb25306d260..00000000000 --- a/samples/client/petstore/dart/lib/api_helper.dart +++ /dev/null @@ -1,33 +0,0 @@ -part of api; - -const _delimiters = const {'csv': ',', 'ssv': ' ', 'tsv': '\t', 'pipes': '|'}; - -// port from Java version -List _convertParametersForCollectionFormat( - String collectionFormat, String name, dynamic value) { - var params = []; - - // preconditions - if (name == null || name.isEmpty || value == null) return params; - - if (value is! List) { - params.add(new QueryParam(name, value as String)); - return params; - } - - List values = value as List; - - // get the collection format - collectionFormat = (collectionFormat == null || collectionFormat.isEmpty) - ? "csv" - : collectionFormat; // default: csv - - if (collectionFormat == "multi") { - return values.map((v) => new QueryParam(name, v)); - } - - String delimiter = _delimiters[collectionFormat] ?? ","; - - params.add(new QueryParam(name, values.join(delimiter))); - return params; -} diff --git a/samples/client/petstore/dart/lib/auth/api_key_auth.dart b/samples/client/petstore/dart/lib/auth/api_key_auth.dart deleted file mode 100644 index d80d6a6a213..00000000000 --- a/samples/client/petstore/dart/lib/auth/api_key_auth.dart +++ /dev/null @@ -1,27 +0,0 @@ -part of api; - -class ApiKeyAuth implements Authentication { - - final String location; - final String paramName; - String apiKey; - String apiKeyPrefix; - - ApiKeyAuth(this.location, this.paramName); - - @override - void applyToParams(List queryParams, Map headerParams) { - String value; - if (apiKeyPrefix != null) { - value = '$apiKeyPrefix $apiKey'; - } else { - value = apiKey; - } - - if (location == 'query' && value != null) { - queryParams.add(new QueryParam(paramName, value)); - } else if (location == 'header' && value != null) { - headerParams[paramName] = value; - } - } -} \ No newline at end of file diff --git a/samples/client/petstore/dart/lib/auth/authentication.dart b/samples/client/petstore/dart/lib/auth/authentication.dart deleted file mode 100644 index c0b1f92a42d..00000000000 --- a/samples/client/petstore/dart/lib/auth/authentication.dart +++ /dev/null @@ -1,7 +0,0 @@ -part of api; - -abstract class Authentication { - - /// Apply authentication settings to header and query params. - void applyToParams(List queryParams, Map headerParams); -} \ No newline at end of file diff --git a/samples/client/petstore/dart/lib/auth/http_basic_auth.dart b/samples/client/petstore/dart/lib/auth/http_basic_auth.dart deleted file mode 100644 index 0645d4358f5..00000000000 --- a/samples/client/petstore/dart/lib/auth/http_basic_auth.dart +++ /dev/null @@ -1,14 +0,0 @@ -part of api; - -class HttpBasicAuth implements Authentication { - - String username; - String password; - - @override - void applyToParams(List queryParams, Map headerParams) { - String str = (username == null ? "" : username) + ":" + (password == null ? "" : password); - headerParams["Authorization"] = "Basic " + BASE64.encode(UTF8.encode(str)); - } - -} \ No newline at end of file diff --git a/samples/client/petstore/dart/lib/auth/oauth.dart b/samples/client/petstore/dart/lib/auth/oauth.dart deleted file mode 100644 index e514dd85738..00000000000 --- a/samples/client/petstore/dart/lib/auth/oauth.dart +++ /dev/null @@ -1,9 +0,0 @@ -part of api; - -class OAuth implements Authentication { - - @override - void applyToParams(List queryParams, Map headerParams) { - // TODO: support oauth - } -} \ No newline at end of file diff --git a/samples/client/petstore/dart/lib/model/api_response.dart b/samples/client/petstore/dart/lib/model/api_response.dart deleted file mode 100644 index e8ffe737861..00000000000 --- a/samples/client/petstore/dart/lib/model/api_response.dart +++ /dev/null @@ -1,26 +0,0 @@ -part of api; - - -@Entity() -class ApiResponse { - - @Property(name: 'code') - int code = null; - - - @Property(name: 'type') - String type = null; - - - @Property(name: 'message') - String message = null; - - ApiResponse(); - - @override - String toString() { - return 'ApiResponse[code=$code, type=$type, message=$message, ]'; - } - -} - diff --git a/samples/client/petstore/dart/lib/model/category.dart b/samples/client/petstore/dart/lib/model/category.dart deleted file mode 100644 index e39966555fb..00000000000 --- a/samples/client/petstore/dart/lib/model/category.dart +++ /dev/null @@ -1,22 +0,0 @@ -part of api; - - -@Entity() -class Category { - - @Property(name: 'id') - int id = null; - - - @Property(name: 'name') - String name = null; - - Category(); - - @override - String toString() { - return 'Category[id=$id, name=$name, ]'; - } - -} - diff --git a/samples/client/petstore/dart/lib/model/order.dart b/samples/client/petstore/dart/lib/model/order.dart deleted file mode 100644 index 1d908629b06..00000000000 --- a/samples/client/petstore/dart/lib/model/order.dart +++ /dev/null @@ -1,38 +0,0 @@ -part of api; - - -@Entity() -class Order { - - @Property(name: 'id') - int id = null; - - - @Property(name: 'petId') - int petId = null; - - - @Property(name: 'quantity') - int quantity = null; - - - @Property(name: 'shipDate') - DateTime shipDate = null; - -/* Order Status */ - @Property(name: 'status') - String status = null; - //enum statusEnum { placed, approved, delivered, }; - - @Property(name: 'complete') - bool complete = null; - - Order(); - - @override - String toString() { - return 'Order[id=$id, petId=$petId, quantity=$quantity, shipDate=$shipDate, status=$status, complete=$complete, ]'; - } - -} - diff --git a/samples/client/petstore/dart/lib/model/pet.dart b/samples/client/petstore/dart/lib/model/pet.dart deleted file mode 100644 index 8ad328b78be..00000000000 --- a/samples/client/petstore/dart/lib/model/pet.dart +++ /dev/null @@ -1,38 +0,0 @@ -part of api; - - -@Entity() -class Pet { - - @Property(name: 'id') - int id = null; - - - @Property(name: 'category') - Category category = null; - - - @Property(name: 'name') - String name = null; - - - @Property(name: 'photoUrls') - List photoUrls = []; - - - @Property(name: 'tags') - List tags = []; - -/* pet status in the store */ - @Property(name: 'status') - String status = null; - //enum statusEnum { available, pending, sold, }; - Pet(); - - @override - String toString() { - return 'Pet[id=$id, category=$category, name=$name, photoUrls=$photoUrls, tags=$tags, status=$status, ]'; - } - -} - diff --git a/samples/client/petstore/dart/lib/model/tag.dart b/samples/client/petstore/dart/lib/model/tag.dart deleted file mode 100644 index 0541e12fb6f..00000000000 --- a/samples/client/petstore/dart/lib/model/tag.dart +++ /dev/null @@ -1,22 +0,0 @@ -part of api; - - -@Entity() -class Tag { - - @Property(name: 'id') - int id = null; - - - @Property(name: 'name') - String name = null; - - Tag(); - - @override - String toString() { - return 'Tag[id=$id, name=$name, ]'; - } - -} - diff --git a/samples/client/petstore/dart/lib/model/user.dart b/samples/client/petstore/dart/lib/model/user.dart deleted file mode 100644 index fd99a51ee58..00000000000 --- a/samples/client/petstore/dart/lib/model/user.dart +++ /dev/null @@ -1,46 +0,0 @@ -part of api; - - -@Entity() -class User { - - @Property(name: 'id') - int id = null; - - - @Property(name: 'username') - String username = null; - - - @Property(name: 'firstName') - String firstName = null; - - - @Property(name: 'lastName') - String lastName = null; - - - @Property(name: 'email') - String email = null; - - - @Property(name: 'password') - String password = null; - - - @Property(name: 'phone') - String phone = null; - -/* User Status */ - @Property(name: 'userStatus') - int userStatus = null; - - User(); - - @override - String toString() { - return 'User[id=$id, username=$username, firstName=$firstName, lastName=$lastName, email=$email, password=$password, phone=$phone, userStatus=$userStatus, ]'; - } - -} - diff --git a/samples/client/petstore/dart/LICENSE b/samples/client/petstore/dart/petstore/LICENSE similarity index 100% rename from samples/client/petstore/dart/LICENSE rename to samples/client/petstore/dart/petstore/LICENSE diff --git a/samples/client/petstore/dart/README.md b/samples/client/petstore/dart/petstore/README.md similarity index 100% rename from samples/client/petstore/dart/README.md rename to samples/client/petstore/dart/petstore/README.md diff --git a/samples/client/petstore/dart/git_push.sh b/samples/client/petstore/dart/petstore/git_push.sh similarity index 100% rename from samples/client/petstore/dart/git_push.sh rename to samples/client/petstore/dart/petstore/git_push.sh diff --git a/samples/client/petstore/dart/petstore/pubspec.yaml b/samples/client/petstore/dart/petstore/pubspec.yaml new file mode 100644 index 00000000000..3a0d2cc4693 --- /dev/null +++ b/samples/client/petstore/dart/petstore/pubspec.yaml @@ -0,0 +1,10 @@ +name: petstore_client +version: 1.0.0 +description: Petstore client using swagger API library +dependencies: + swagger: + path:../swagger + swagger_vm: + path:../swagger_vm + + diff --git a/samples/client/petstore/dart/test/packages b/samples/client/petstore/dart/petstore/test/packages similarity index 100% rename from samples/client/petstore/dart/test/packages rename to samples/client/petstore/dart/petstore/test/packages diff --git a/samples/client/petstore/dart/test/pet_test.dart b/samples/client/petstore/dart/petstore/test/pet_test.dart similarity index 100% rename from samples/client/petstore/dart/test/pet_test.dart rename to samples/client/petstore/dart/petstore/test/pet_test.dart diff --git a/samples/client/petstore/dart/test/store_test.dart b/samples/client/petstore/dart/petstore/test/store_test.dart similarity index 100% rename from samples/client/petstore/dart/test/store_test.dart rename to samples/client/petstore/dart/petstore/test/store_test.dart diff --git a/samples/client/petstore/dart/test/tests.dart b/samples/client/petstore/dart/petstore/test/tests.dart similarity index 100% rename from samples/client/petstore/dart/test/tests.dart rename to samples/client/petstore/dart/petstore/test/tests.dart diff --git a/samples/client/petstore/dart/test/tests.html b/samples/client/petstore/dart/petstore/test/tests.html similarity index 100% rename from samples/client/petstore/dart/test/tests.html rename to samples/client/petstore/dart/petstore/test/tests.html diff --git a/samples/client/petstore/dart/test/user_test.dart b/samples/client/petstore/dart/petstore/test/user_test.dart similarity index 100% rename from samples/client/petstore/dart/test/user_test.dart rename to samples/client/petstore/dart/petstore/test/user_test.dart diff --git a/samples/client/petstore/dart/pubspec.lock b/samples/client/petstore/dart/pubspec.lock deleted file mode 100644 index b816620fa90..00000000000 --- a/samples/client/petstore/dart/pubspec.lock +++ /dev/null @@ -1,178 +0,0 @@ -# Generated by pub -# See http://pub.dartlang.org/doc/glossary.html#lockfile -packages: - analyzer: - description: - name: analyzer - url: "https://pub.dartlang.org" - source: hosted - version: "0.26.4" - args: - description: - name: args - url: "https://pub.dartlang.org" - source: hosted - version: "0.13.4+2" - async: - description: - name: async - url: "https://pub.dartlang.org" - source: hosted - version: "1.11.0" - barback: - description: - name: barback - url: "https://pub.dartlang.org" - source: hosted - version: "0.15.2+8" - browser: - description: - name: browser - url: "https://pub.dartlang.org" - source: hosted - version: "0.10.0+2" - charcode: - description: - name: charcode - url: "https://pub.dartlang.org" - source: hosted - version: "1.1.0" - collection: - description: - name: collection - url: "https://pub.dartlang.org" - source: hosted - version: "1.9.0" - csslib: - description: - name: csslib - url: "https://pub.dartlang.org" - source: hosted - version: "0.13.2" - dartson: - description: - name: dartson - url: "https://pub.dartlang.org" - source: hosted - version: "0.2.5" - glob: - description: - name: glob - url: "https://pub.dartlang.org" - source: hosted - version: "1.1.3" - guinness: - description: - name: guinness - url: "https://pub.dartlang.org" - source: hosted - version: "0.1.18" - html: - description: - name: html - url: "https://pub.dartlang.org" - source: hosted - version: "0.12.2+2" - http: - description: - name: http - url: "https://pub.dartlang.org" - source: hosted - version: "0.11.3+8" - http_parser: - description: - name: http_parser - url: "https://pub.dartlang.org" - source: hosted - version: "3.0.2" - intl: - description: - name: intl - url: "https://pub.dartlang.org" - source: hosted - version: "0.12.7+1" - logging: - description: - name: logging - url: "https://pub.dartlang.org" - source: hosted - version: "0.11.3" - package_config: - description: - name: package_config - url: "https://pub.dartlang.org" - source: hosted - version: "0.1.5" - path: - description: - name: path - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.9" - petitparser: - description: - name: petitparser - url: "https://pub.dartlang.org" - source: hosted - version: "1.5.3" - plugin: - description: - name: plugin - url: "https://pub.dartlang.org" - source: hosted - version: "0.1.0" - pool: - description: - name: pool - url: "https://pub.dartlang.org" - source: hosted - version: "1.2.4" - source_maps: - description: - name: source_maps - url: "https://pub.dartlang.org" - source: hosted - version: "0.10.1+1" - source_span: - description: - name: source_span - url: "https://pub.dartlang.org" - source: hosted - version: "1.2.3" - stack_trace: - description: - name: stack_trace - url: "https://pub.dartlang.org" - source: hosted - version: "1.6.6" - string_scanner: - description: - name: string_scanner - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.0" - unittest: - description: - name: unittest - url: "https://pub.dartlang.org" - source: hosted - version: "0.11.6+4" - utf: - description: - name: utf - url: "https://pub.dartlang.org" - source: hosted - version: "0.9.0+3" - watcher: - description: - name: watcher - url: "https://pub.dartlang.org" - source: hosted - version: "0.9.7+2" - yaml: - description: - name: yaml - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.10" -sdk: ">=1.14.0 <2.0.0" diff --git a/samples/client/petstore/dart/pubspec.yaml b/samples/client/petstore/dart/pubspec.yaml deleted file mode 100644 index e74546ea210..00000000000 --- a/samples/client/petstore/dart/pubspec.yaml +++ /dev/null @@ -1,14 +0,0 @@ -name: swagger -version: 1.0.0 -description: Swagger API client -dependencies: - http: '>=0.11.1 <0.12.0' - dartson: "^0.2.4" - intl: "^0.12.4+2" - -dev_dependencies: - guinness: '^0.1.17' - browser: any - -transformers: - - dartson From fa5b0e173cdb1e84717ca426586cf86fbbf268d5 Mon Sep 17 00:00:00 2001 From: Christian Loitsch Date: Thu, 14 Jul 2016 10:07:26 +0200 Subject: [PATCH 05/10] feat dart: refactor petstore test. The new layout resembles a real project. petstore test is now strong mode compatible. --- bin/dart-petstore.sh | 15 +- .../petstore/dart/petstore/.analysis_options | 2 + .../petstore/dart/petstore/pubspec.yaml | 7 +- .../petstore/dart/petstore/test/tests.dart | 1 + .../client/petstore/dart/swagger/.gitignore | 27 + samples/client/petstore/dart/swagger/LICENSE | 201 ++++++++ .../dart/{petstore => swagger}/git_push.sh | 0 .../client/petstore/dart/swagger/lib/api.dart | 31 ++ .../dart/swagger/lib/api/pet_api.dart | 485 ++++++++++++++++++ .../dart/swagger/lib/api/store_api.dart | 227 ++++++++ .../dart/swagger/lib/api/user_api.dart | 459 +++++++++++++++++ .../petstore/dart/swagger/lib/api_client.dart | 175 +++++++ .../dart/swagger/lib/api_exception.dart | 9 + .../petstore/dart/swagger/lib/api_helper.dart | 33 ++ .../dart/swagger/lib/auth/api_key_auth.dart | 27 + .../dart/swagger/lib/auth/authentication.dart | 7 + .../swagger/lib/auth/http_basic_auth.dart | 14 + .../petstore/dart/swagger/lib/auth/oauth.dart | 9 + .../dart/swagger/lib/model/api_response.dart | 26 + .../dart/swagger/lib/model/category.dart | 22 + .../dart/swagger/lib/model/order.dart | 38 ++ .../petstore/dart/swagger/lib/model/pet.dart | 38 ++ .../petstore/dart/swagger/lib/model/tag.dart | 22 + .../petstore/dart/swagger/lib/model/user.dart | 46 ++ .../client/petstore/dart/swagger/pubspec.yaml | 14 + 25 files changed, 1925 insertions(+), 10 deletions(-) create mode 100644 samples/client/petstore/dart/petstore/.analysis_options create mode 100644 samples/client/petstore/dart/swagger/.gitignore create mode 100644 samples/client/petstore/dart/swagger/LICENSE rename samples/client/petstore/dart/{petstore => swagger}/git_push.sh (100%) create mode 100644 samples/client/petstore/dart/swagger/lib/api.dart create mode 100644 samples/client/petstore/dart/swagger/lib/api/pet_api.dart create mode 100644 samples/client/petstore/dart/swagger/lib/api/store_api.dart create mode 100644 samples/client/petstore/dart/swagger/lib/api/user_api.dart create mode 100644 samples/client/petstore/dart/swagger/lib/api_client.dart create mode 100644 samples/client/petstore/dart/swagger/lib/api_exception.dart create mode 100644 samples/client/petstore/dart/swagger/lib/api_helper.dart create mode 100644 samples/client/petstore/dart/swagger/lib/auth/api_key_auth.dart create mode 100644 samples/client/petstore/dart/swagger/lib/auth/authentication.dart create mode 100644 samples/client/petstore/dart/swagger/lib/auth/http_basic_auth.dart create mode 100644 samples/client/petstore/dart/swagger/lib/auth/oauth.dart create mode 100644 samples/client/petstore/dart/swagger/lib/model/api_response.dart create mode 100644 samples/client/petstore/dart/swagger/lib/model/category.dart create mode 100644 samples/client/petstore/dart/swagger/lib/model/order.dart create mode 100644 samples/client/petstore/dart/swagger/lib/model/pet.dart create mode 100644 samples/client/petstore/dart/swagger/lib/model/tag.dart create mode 100644 samples/client/petstore/dart/swagger/lib/model/user.dart create mode 100644 samples/client/petstore/dart/swagger/pubspec.yaml diff --git a/bin/dart-petstore.sh b/bin/dart-petstore.sh index 2481fca0368..357cbac45ff 100755 --- a/bin/dart-petstore.sh +++ b/bin/dart-petstore.sh @@ -27,12 +27,15 @@ fi # if you've executed sbt assembly previously it will use that instead. export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties" -# first generate swagger library for browser rest client -#ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l dart -o samples/client/petstore/dart/swagger" +ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l dart -o samples/client/petstore/dart/swagger" + +# then options to generate the library for vm would be: +#ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l dart -o samples/client/petstore/dart/swagger_vm -DbrowserClient=false -DpubName=swagger_vm" java $JAVA_OPTS -jar $executable $ags -# then generate swagger library for vm -# for dart vm lib generation: -agsvm="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l dart -o samples/client/petstore/dart/swagger_vm -DbrowserClient=false -DpubName=swagger_vm" -java $JAVA_OPTS -jar $executable $agsvm +# There is a proposal to allow importing different libraries depending on the environment: +# https://github.com/munificent/dep-interface-libraries +# When this is implemented there will only be one library. + +# The current petstore test will then work for both: the browser library and the vm library. diff --git a/samples/client/petstore/dart/petstore/.analysis_options b/samples/client/petstore/dart/petstore/.analysis_options new file mode 100644 index 00000000000..a10d4c5a05c --- /dev/null +++ b/samples/client/petstore/dart/petstore/.analysis_options @@ -0,0 +1,2 @@ +analyzer: + strong-mode: true diff --git a/samples/client/petstore/dart/petstore/pubspec.yaml b/samples/client/petstore/dart/petstore/pubspec.yaml index 3a0d2cc4693..26f7d22205d 100644 --- a/samples/client/petstore/dart/petstore/pubspec.yaml +++ b/samples/client/petstore/dart/petstore/pubspec.yaml @@ -3,8 +3,7 @@ version: 1.0.0 description: Petstore client using swagger API library dependencies: swagger: - path:../swagger - swagger_vm: - path:../swagger_vm - + path: ../swagger +dev_dependencies: + guinness: '^0.1.17' \ No newline at end of file diff --git a/samples/client/petstore/dart/petstore/test/tests.dart b/samples/client/petstore/dart/petstore/test/tests.dart index 9511ea17875..1c072d2767d 100644 --- a/samples/client/petstore/dart/petstore/test/tests.dart +++ b/samples/client/petstore/dart/petstore/test/tests.dart @@ -17,6 +17,7 @@ int newId() { } main() { + defaultApiClient.client = new Client(); testPetApi(); testStoreApi(); testUserApi(); diff --git a/samples/client/petstore/dart/swagger/.gitignore b/samples/client/petstore/dart/swagger/.gitignore new file mode 100644 index 00000000000..7c280441649 --- /dev/null +++ b/samples/client/petstore/dart/swagger/.gitignore @@ -0,0 +1,27 @@ +# See https://www.dartlang.org/tools/private-files.html + +# Files and directories created by pub +.buildlog +.packages +.project +.pub/ +build/ +**/packages/ + +# Files created by dart2js +# (Most Dart developers will use pub build to compile Dart, use/modify these +# rules if you intend to use dart2js directly +# Convention is to use extension '.dart.js' for Dart compiled to Javascript to +# differentiate from explicit Javascript files) +*.dart.js +*.part.js +*.js.deps +*.js.map +*.info.json + +# Directory created by dartdoc +doc/api/ + +# Don't commit pubspec lock file +# (Library packages only! Remove pattern if developing an application package) +pubspec.lock diff --git a/samples/client/petstore/dart/swagger/LICENSE b/samples/client/petstore/dart/swagger/LICENSE new file mode 100644 index 00000000000..8dada3edaf5 --- /dev/null +++ b/samples/client/petstore/dart/swagger/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {yyyy} {name of copyright owner} + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/samples/client/petstore/dart/petstore/git_push.sh b/samples/client/petstore/dart/swagger/git_push.sh similarity index 100% rename from samples/client/petstore/dart/petstore/git_push.sh rename to samples/client/petstore/dart/swagger/git_push.sh diff --git a/samples/client/petstore/dart/swagger/lib/api.dart b/samples/client/petstore/dart/swagger/lib/api.dart new file mode 100644 index 00000000000..667f617176e --- /dev/null +++ b/samples/client/petstore/dart/swagger/lib/api.dart @@ -0,0 +1,31 @@ +library swagger.api; + +import 'dart:async'; +import 'dart:convert'; +import 'package:http/browser_client.dart'; +import 'package:http/http.dart'; +import 'package:dartson/dartson.dart'; +import 'package:intl/intl.dart'; + +part 'api_client.dart'; +part 'api_helper.dart'; +part 'api_exception.dart'; +part 'auth/authentication.dart'; +part 'auth/api_key_auth.dart'; +part 'auth/oauth.dart'; +part 'auth/http_basic_auth.dart'; + +part 'api/pet_api.dart'; +part 'api/store_api.dart'; +part 'api/user_api.dart'; + +part 'model/api_response.dart'; +part 'model/category.dart'; +part 'model/order.dart'; +part 'model/pet.dart'; +part 'model/tag.dart'; +part 'model/user.dart'; + + +ApiClient defaultApiClient = new ApiClient(); + diff --git a/samples/client/petstore/dart/swagger/lib/api/pet_api.dart b/samples/client/petstore/dart/swagger/lib/api/pet_api.dart new file mode 100644 index 00000000000..34f5e8f3560 --- /dev/null +++ b/samples/client/petstore/dart/swagger/lib/api/pet_api.dart @@ -0,0 +1,485 @@ +part of swagger.api; + + + +class PetApi { + final ApiClient apiClient; + + PetApi([ApiClient apiClient]) : apiClient = apiClient ?? defaultApiClient; + + /// Add a new pet to the store + /// + /// + Future addPet(Pet body, { bool justIgnoreThisFlag: true}) async { + if (!justIgnoreThisFlag) { + print('Why??? Just trust me, I only need this variable inside the mustache codegen template.'); + // This code may be removed as soon as dart accepts trailing spaces (has already been implemented). + } + Object postBody = body; + + // verify required params are set + if(body == null) { + throw new ApiException(400, "Missing required param: body"); + } + + // create path and map variables + String path = "/pet".replaceAll("{format}","json"); + + // query params + List queryParams = []; + Map headerParams = {}; + Map formParams = {}; + + List contentTypes = ["application/json","application/xml"]; + + String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; + List authNames = ["petstore_auth"]; + + if(contentType.startsWith("multipart/form-data")) { + bool hasFields = false; + MultipartRequest mp = new MultipartRequest(null, null); + + if(hasFields) + postBody = mp; + } + else { + } + + var response = await apiClient.invokeAPI(path, + 'POST', + queryParams, + postBody, + headerParams, + formParams, + contentType, + authNames); + + if(response.statusCode >= 400) { + throw new ApiException(response.statusCode, response.body); + } else if(response.body != null) { + return ; + } else { + return ; + } + } + /// Deletes a pet + /// + /// + Future deletePet(int petId, { String apiKey, bool justIgnoreThisFlag: true}) async { + if (!justIgnoreThisFlag) { + print('Why??? Just trust me, I only need this variable inside the mustache codegen template.'); + // This code may be removed as soon as dart accepts trailing spaces (has already been implemented). + } + Object postBody = null; + + // verify required params are set + if(petId == null) { + throw new ApiException(400, "Missing required param: petId"); + } + + // create path and map variables + String path = "/pet/{petId}".replaceAll("{format}","json").replaceAll("{" + "petId" + "}", petId.toString()); + + // query params + List queryParams = []; + Map headerParams = {}; + Map formParams = {}; + headerParams["api_key"] = apiKey; + + List contentTypes = []; + + String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; + List authNames = ["petstore_auth"]; + + if(contentType.startsWith("multipart/form-data")) { + bool hasFields = false; + MultipartRequest mp = new MultipartRequest(null, null); + + if(hasFields) + postBody = mp; + } + else { + } + + var response = await apiClient.invokeAPI(path, + 'DELETE', + queryParams, + postBody, + headerParams, + formParams, + contentType, + authNames); + + if(response.statusCode >= 400) { + throw new ApiException(response.statusCode, response.body); + } else if(response.body != null) { + return ; + } else { + return ; + } + } + /// Finds Pets by status + /// + /// Multiple status values can be provided with comma separated strings + Future> findPetsByStatus(List status, { bool justIgnoreThisFlag: true}) async { + if (!justIgnoreThisFlag) { + print('Why??? Just trust me, I only need this variable inside the mustache codegen template.'); + // This code may be removed as soon as dart accepts trailing spaces (has already been implemented). + } + Object postBody = null; + + // verify required params are set + if(status == null) { + throw new ApiException(400, "Missing required param: status"); + } + + // create path and map variables + String path = "/pet/findByStatus".replaceAll("{format}","json"); + + // query params + List queryParams = []; + Map headerParams = {}; + Map formParams = {}; + if("null" != status) { + queryParams.addAll(_convertParametersForCollectionFormat("csv", "status", status)); + } + + List contentTypes = []; + + String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; + List authNames = ["petstore_auth"]; + + if(contentType.startsWith("multipart/form-data")) { + bool hasFields = false; + MultipartRequest mp = new MultipartRequest(null, null); + + if(hasFields) + postBody = mp; + } + else { + } + + var response = await apiClient.invokeAPI(path, + 'GET', + queryParams, + postBody, + headerParams, + formParams, + contentType, + authNames); + + if(response.statusCode >= 400) { + throw new ApiException(response.statusCode, response.body); + } else if(response.body != null) { + return apiClient.deserialize(response.body, 'List') ; + } else { + return null; + } + } + /// Finds Pets by tags + /// + /// Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. + Future> findPetsByTags(List tags, { bool justIgnoreThisFlag: true}) async { + if (!justIgnoreThisFlag) { + print('Why??? Just trust me, I only need this variable inside the mustache codegen template.'); + // This code may be removed as soon as dart accepts trailing spaces (has already been implemented). + } + Object postBody = null; + + // verify required params are set + if(tags == null) { + throw new ApiException(400, "Missing required param: tags"); + } + + // create path and map variables + String path = "/pet/findByTags".replaceAll("{format}","json"); + + // query params + List queryParams = []; + Map headerParams = {}; + Map formParams = {}; + if("null" != tags) { + queryParams.addAll(_convertParametersForCollectionFormat("csv", "tags", tags)); + } + + List contentTypes = []; + + String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; + List authNames = ["petstore_auth"]; + + if(contentType.startsWith("multipart/form-data")) { + bool hasFields = false; + MultipartRequest mp = new MultipartRequest(null, null); + + if(hasFields) + postBody = mp; + } + else { + } + + var response = await apiClient.invokeAPI(path, + 'GET', + queryParams, + postBody, + headerParams, + formParams, + contentType, + authNames); + + if(response.statusCode >= 400) { + throw new ApiException(response.statusCode, response.body); + } else if(response.body != null) { + return apiClient.deserialize(response.body, 'List') ; + } else { + return null; + } + } + /// Find pet by ID + /// + /// Returns a single pet + Future getPetById(int petId, { bool justIgnoreThisFlag: true}) async { + if (!justIgnoreThisFlag) { + print('Why??? Just trust me, I only need this variable inside the mustache codegen template.'); + // This code may be removed as soon as dart accepts trailing spaces (has already been implemented). + } + Object postBody = null; + + // verify required params are set + if(petId == null) { + throw new ApiException(400, "Missing required param: petId"); + } + + // create path and map variables + String path = "/pet/{petId}".replaceAll("{format}","json").replaceAll("{" + "petId" + "}", petId.toString()); + + // query params + List queryParams = []; + Map headerParams = {}; + Map formParams = {}; + + List contentTypes = []; + + String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; + List authNames = ["api_key"]; + + if(contentType.startsWith("multipart/form-data")) { + bool hasFields = false; + MultipartRequest mp = new MultipartRequest(null, null); + + if(hasFields) + postBody = mp; + } + else { + } + + var response = await apiClient.invokeAPI(path, + 'GET', + queryParams, + postBody, + headerParams, + formParams, + contentType, + authNames); + + if(response.statusCode >= 400) { + throw new ApiException(response.statusCode, response.body); + } else if(response.body != null) { + return apiClient.deserialize(response.body, 'Pet') ; + } else { + return null; + } + } + /// Update an existing pet + /// + /// + Future updatePet(Pet body, { bool justIgnoreThisFlag: true}) async { + if (!justIgnoreThisFlag) { + print('Why??? Just trust me, I only need this variable inside the mustache codegen template.'); + // This code may be removed as soon as dart accepts trailing spaces (has already been implemented). + } + Object postBody = body; + + // verify required params are set + if(body == null) { + throw new ApiException(400, "Missing required param: body"); + } + + // create path and map variables + String path = "/pet".replaceAll("{format}","json"); + + // query params + List queryParams = []; + Map headerParams = {}; + Map formParams = {}; + + List contentTypes = ["application/json","application/xml"]; + + String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; + List authNames = ["petstore_auth"]; + + if(contentType.startsWith("multipart/form-data")) { + bool hasFields = false; + MultipartRequest mp = new MultipartRequest(null, null); + + if(hasFields) + postBody = mp; + } + else { + } + + var response = await apiClient.invokeAPI(path, + 'PUT', + queryParams, + postBody, + headerParams, + formParams, + contentType, + authNames); + + if(response.statusCode >= 400) { + throw new ApiException(response.statusCode, response.body); + } else if(response.body != null) { + return ; + } else { + return ; + } + } + /// Updates a pet in the store with form data + /// + /// + Future updatePetWithForm(int petId, { String name, String status, bool justIgnoreThisFlag: true}) async { + if (!justIgnoreThisFlag) { + print('Why??? Just trust me, I only need this variable inside the mustache codegen template.'); + // This code may be removed as soon as dart accepts trailing spaces (has already been implemented). + } + Object postBody = null; + + // verify required params are set + if(petId == null) { + throw new ApiException(400, "Missing required param: petId"); + } + + // create path and map variables + String path = "/pet/{petId}".replaceAll("{format}","json").replaceAll("{" + "petId" + "}", petId.toString()); + + // query params + List queryParams = []; + Map headerParams = {}; + Map formParams = {}; + + List contentTypes = ["application/x-www-form-urlencoded"]; + + String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; + List authNames = ["petstore_auth"]; + + if(contentType.startsWith("multipart/form-data")) { + bool hasFields = false; + MultipartRequest mp = new MultipartRequest(null, null); + + if (name != null) { + hasFields = true; + mp.fields['name'] = apiClient.parameterToString(name); + } + + if (status != null) { + hasFields = true; + mp.fields['status'] = apiClient.parameterToString(status); + } + + if(hasFields) + postBody = mp; + } + else { + if (name != null) + formParams['name'] = apiClient.parameterToString(name); +if (status != null) + formParams['status'] = apiClient.parameterToString(status); + } + + var response = await apiClient.invokeAPI(path, + 'POST', + queryParams, + postBody, + headerParams, + formParams, + contentType, + authNames); + + if(response.statusCode >= 400) { + throw new ApiException(response.statusCode, response.body); + } else if(response.body != null) { + return ; + } else { + return ; + } + } + /// uploads an image + /// + /// + Future uploadFile(int petId, { String additionalMetadata, MultipartFile file, bool justIgnoreThisFlag: true}) async { + if (!justIgnoreThisFlag) { + print('Why??? Just trust me, I only need this variable inside the mustache codegen template.'); + // This code may be removed as soon as dart accepts trailing spaces (has already been implemented). + } + Object postBody = null; + + // verify required params are set + if(petId == null) { + throw new ApiException(400, "Missing required param: petId"); + } + + // create path and map variables + String path = "/pet/{petId}/uploadImage".replaceAll("{format}","json").replaceAll("{" + "petId" + "}", petId.toString()); + + // query params + List queryParams = []; + Map headerParams = {}; + Map formParams = {}; + + List contentTypes = ["multipart/form-data"]; + + String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; + List authNames = ["petstore_auth"]; + + if(contentType.startsWith("multipart/form-data")) { + bool hasFields = false; + MultipartRequest mp = new MultipartRequest(null, null); + + if (additionalMetadata != null) { + hasFields = true; + mp.fields['additionalMetadata'] = apiClient.parameterToString(additionalMetadata); + } + + if (file != null) { + hasFields = true; + mp.fields['file'] = file.field; + mp.files.add(file); + } + + if(hasFields) + postBody = mp; + } + else { + if (additionalMetadata != null) + formParams['additionalMetadata'] = apiClient.parameterToString(additionalMetadata); + + } + + var response = await apiClient.invokeAPI(path, + 'POST', + queryParams, + postBody, + headerParams, + formParams, + contentType, + authNames); + + if(response.statusCode >= 400) { + throw new ApiException(response.statusCode, response.body); + } else if(response.body != null) { + return apiClient.deserialize(response.body, 'ApiResponse') ; + } else { + return null; + } + } +} diff --git a/samples/client/petstore/dart/swagger/lib/api/store_api.dart b/samples/client/petstore/dart/swagger/lib/api/store_api.dart new file mode 100644 index 00000000000..3f25ee112d5 --- /dev/null +++ b/samples/client/petstore/dart/swagger/lib/api/store_api.dart @@ -0,0 +1,227 @@ +part of swagger.api; + + + +class StoreApi { + final ApiClient apiClient; + + StoreApi([ApiClient apiClient]) : apiClient = apiClient ?? defaultApiClient; + + /// Delete purchase order by ID + /// + /// For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + Future deleteOrder(String orderId, { bool justIgnoreThisFlag: true}) async { + if (!justIgnoreThisFlag) { + print('Why??? Just trust me, I only need this variable inside the mustache codegen template.'); + // This code may be removed as soon as dart accepts trailing spaces (has already been implemented). + } + Object postBody = null; + + // verify required params are set + if(orderId == null) { + throw new ApiException(400, "Missing required param: orderId"); + } + + // create path and map variables + String path = "/store/order/{orderId}".replaceAll("{format}","json").replaceAll("{" + "orderId" + "}", orderId.toString()); + + // query params + List queryParams = []; + Map headerParams = {}; + Map formParams = {}; + + List contentTypes = []; + + String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; + List authNames = []; + + if(contentType.startsWith("multipart/form-data")) { + bool hasFields = false; + MultipartRequest mp = new MultipartRequest(null, null); + + if(hasFields) + postBody = mp; + } + else { + } + + var response = await apiClient.invokeAPI(path, + 'DELETE', + queryParams, + postBody, + headerParams, + formParams, + contentType, + authNames); + + if(response.statusCode >= 400) { + throw new ApiException(response.statusCode, response.body); + } else if(response.body != null) { + return ; + } else { + return ; + } + } + /// Returns pet inventories by status + /// + /// Returns a map of status codes to quantities + Future> getInventory( { bool justIgnoreThisFlag: true}) async { + if (!justIgnoreThisFlag) { + print('Why??? Just trust me, I only need this variable inside the mustache codegen template.'); + // This code may be removed as soon as dart accepts trailing spaces (has already been implemented). + } + Object postBody = null; + + // verify required params are set + + // create path and map variables + String path = "/store/inventory".replaceAll("{format}","json"); + + // query params + List queryParams = []; + Map headerParams = {}; + Map formParams = {}; + + List contentTypes = []; + + String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; + List authNames = ["api_key"]; + + if(contentType.startsWith("multipart/form-data")) { + bool hasFields = false; + MultipartRequest mp = new MultipartRequest(null, null); + + if(hasFields) + postBody = mp; + } + else { + } + + var response = await apiClient.invokeAPI(path, + 'GET', + queryParams, + postBody, + headerParams, + formParams, + contentType, + authNames); + + if(response.statusCode >= 400) { + throw new ApiException(response.statusCode, response.body); + } else if(response.body != null) { + return apiClient.deserialize(response.body, 'Map') ; + } else { + return null; + } + } + /// Find purchase order by ID + /// + /// For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions + Future getOrderById(int orderId, { bool justIgnoreThisFlag: true}) async { + if (!justIgnoreThisFlag) { + print('Why??? Just trust me, I only need this variable inside the mustache codegen template.'); + // This code may be removed as soon as dart accepts trailing spaces (has already been implemented). + } + Object postBody = null; + + // verify required params are set + if(orderId == null) { + throw new ApiException(400, "Missing required param: orderId"); + } + + // create path and map variables + String path = "/store/order/{orderId}".replaceAll("{format}","json").replaceAll("{" + "orderId" + "}", orderId.toString()); + + // query params + List queryParams = []; + Map headerParams = {}; + Map formParams = {}; + + List contentTypes = []; + + String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; + List authNames = []; + + if(contentType.startsWith("multipart/form-data")) { + bool hasFields = false; + MultipartRequest mp = new MultipartRequest(null, null); + + if(hasFields) + postBody = mp; + } + else { + } + + var response = await apiClient.invokeAPI(path, + 'GET', + queryParams, + postBody, + headerParams, + formParams, + contentType, + authNames); + + if(response.statusCode >= 400) { + throw new ApiException(response.statusCode, response.body); + } else if(response.body != null) { + return apiClient.deserialize(response.body, 'Order') ; + } else { + return null; + } + } + /// Place an order for a pet + /// + /// + Future placeOrder(Order body, { bool justIgnoreThisFlag: true}) async { + if (!justIgnoreThisFlag) { + print('Why??? Just trust me, I only need this variable inside the mustache codegen template.'); + // This code may be removed as soon as dart accepts trailing spaces (has already been implemented). + } + Object postBody = body; + + // verify required params are set + if(body == null) { + throw new ApiException(400, "Missing required param: body"); + } + + // create path and map variables + String path = "/store/order".replaceAll("{format}","json"); + + // query params + List queryParams = []; + Map headerParams = {}; + Map formParams = {}; + + List contentTypes = []; + + String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; + List authNames = []; + + if(contentType.startsWith("multipart/form-data")) { + bool hasFields = false; + MultipartRequest mp = new MultipartRequest(null, null); + + if(hasFields) + postBody = mp; + } + else { + } + + var response = await apiClient.invokeAPI(path, + 'POST', + queryParams, + postBody, + headerParams, + formParams, + contentType, + authNames); + + if(response.statusCode >= 400) { + throw new ApiException(response.statusCode, response.body); + } else if(response.body != null) { + return apiClient.deserialize(response.body, 'Order') ; + } else { + return null; + } + } +} diff --git a/samples/client/petstore/dart/swagger/lib/api/user_api.dart b/samples/client/petstore/dart/swagger/lib/api/user_api.dart new file mode 100644 index 00000000000..e09239a941a --- /dev/null +++ b/samples/client/petstore/dart/swagger/lib/api/user_api.dart @@ -0,0 +1,459 @@ +part of swagger.api; + + + +class UserApi { + final ApiClient apiClient; + + UserApi([ApiClient apiClient]) : apiClient = apiClient ?? defaultApiClient; + + /// Create user + /// + /// This can only be done by the logged in user. + Future createUser(User body, { bool justIgnoreThisFlag: true}) async { + if (!justIgnoreThisFlag) { + print('Why??? Just trust me, I only need this variable inside the mustache codegen template.'); + // This code may be removed as soon as dart accepts trailing spaces (has already been implemented). + } + Object postBody = body; + + // verify required params are set + if(body == null) { + throw new ApiException(400, "Missing required param: body"); + } + + // create path and map variables + String path = "/user".replaceAll("{format}","json"); + + // query params + List queryParams = []; + Map headerParams = {}; + Map formParams = {}; + + List contentTypes = []; + + String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; + List authNames = []; + + if(contentType.startsWith("multipart/form-data")) { + bool hasFields = false; + MultipartRequest mp = new MultipartRequest(null, null); + + if(hasFields) + postBody = mp; + } + else { + } + + var response = await apiClient.invokeAPI(path, + 'POST', + queryParams, + postBody, + headerParams, + formParams, + contentType, + authNames); + + if(response.statusCode >= 400) { + throw new ApiException(response.statusCode, response.body); + } else if(response.body != null) { + return ; + } else { + return ; + } + } + /// Creates list of users with given input array + /// + /// + Future createUsersWithArrayInput(List body, { bool justIgnoreThisFlag: true}) async { + if (!justIgnoreThisFlag) { + print('Why??? Just trust me, I only need this variable inside the mustache codegen template.'); + // This code may be removed as soon as dart accepts trailing spaces (has already been implemented). + } + Object postBody = body; + + // verify required params are set + if(body == null) { + throw new ApiException(400, "Missing required param: body"); + } + + // create path and map variables + String path = "/user/createWithArray".replaceAll("{format}","json"); + + // query params + List queryParams = []; + Map headerParams = {}; + Map formParams = {}; + + List contentTypes = []; + + String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; + List authNames = []; + + if(contentType.startsWith("multipart/form-data")) { + bool hasFields = false; + MultipartRequest mp = new MultipartRequest(null, null); + + if(hasFields) + postBody = mp; + } + else { + } + + var response = await apiClient.invokeAPI(path, + 'POST', + queryParams, + postBody, + headerParams, + formParams, + contentType, + authNames); + + if(response.statusCode >= 400) { + throw new ApiException(response.statusCode, response.body); + } else if(response.body != null) { + return ; + } else { + return ; + } + } + /// Creates list of users with given input array + /// + /// + Future createUsersWithListInput(List body, { bool justIgnoreThisFlag: true}) async { + if (!justIgnoreThisFlag) { + print('Why??? Just trust me, I only need this variable inside the mustache codegen template.'); + // This code may be removed as soon as dart accepts trailing spaces (has already been implemented). + } + Object postBody = body; + + // verify required params are set + if(body == null) { + throw new ApiException(400, "Missing required param: body"); + } + + // create path and map variables + String path = "/user/createWithList".replaceAll("{format}","json"); + + // query params + List queryParams = []; + Map headerParams = {}; + Map formParams = {}; + + List contentTypes = []; + + String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; + List authNames = []; + + if(contentType.startsWith("multipart/form-data")) { + bool hasFields = false; + MultipartRequest mp = new MultipartRequest(null, null); + + if(hasFields) + postBody = mp; + } + else { + } + + var response = await apiClient.invokeAPI(path, + 'POST', + queryParams, + postBody, + headerParams, + formParams, + contentType, + authNames); + + if(response.statusCode >= 400) { + throw new ApiException(response.statusCode, response.body); + } else if(response.body != null) { + return ; + } else { + return ; + } + } + /// Delete user + /// + /// This can only be done by the logged in user. + Future deleteUser(String username, { bool justIgnoreThisFlag: true}) async { + if (!justIgnoreThisFlag) { + print('Why??? Just trust me, I only need this variable inside the mustache codegen template.'); + // This code may be removed as soon as dart accepts trailing spaces (has already been implemented). + } + Object postBody = null; + + // verify required params are set + if(username == null) { + throw new ApiException(400, "Missing required param: username"); + } + + // create path and map variables + String path = "/user/{username}".replaceAll("{format}","json").replaceAll("{" + "username" + "}", username.toString()); + + // query params + List queryParams = []; + Map headerParams = {}; + Map formParams = {}; + + List contentTypes = []; + + String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; + List authNames = []; + + if(contentType.startsWith("multipart/form-data")) { + bool hasFields = false; + MultipartRequest mp = new MultipartRequest(null, null); + + if(hasFields) + postBody = mp; + } + else { + } + + var response = await apiClient.invokeAPI(path, + 'DELETE', + queryParams, + postBody, + headerParams, + formParams, + contentType, + authNames); + + if(response.statusCode >= 400) { + throw new ApiException(response.statusCode, response.body); + } else if(response.body != null) { + return ; + } else { + return ; + } + } + /// Get user by user name + /// + /// + Future getUserByName(String username, { bool justIgnoreThisFlag: true}) async { + if (!justIgnoreThisFlag) { + print('Why??? Just trust me, I only need this variable inside the mustache codegen template.'); + // This code may be removed as soon as dart accepts trailing spaces (has already been implemented). + } + Object postBody = null; + + // verify required params are set + if(username == null) { + throw new ApiException(400, "Missing required param: username"); + } + + // create path and map variables + String path = "/user/{username}".replaceAll("{format}","json").replaceAll("{" + "username" + "}", username.toString()); + + // query params + List queryParams = []; + Map headerParams = {}; + Map formParams = {}; + + List contentTypes = []; + + String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; + List authNames = []; + + if(contentType.startsWith("multipart/form-data")) { + bool hasFields = false; + MultipartRequest mp = new MultipartRequest(null, null); + + if(hasFields) + postBody = mp; + } + else { + } + + var response = await apiClient.invokeAPI(path, + 'GET', + queryParams, + postBody, + headerParams, + formParams, + contentType, + authNames); + + if(response.statusCode >= 400) { + throw new ApiException(response.statusCode, response.body); + } else if(response.body != null) { + return apiClient.deserialize(response.body, 'User') ; + } else { + return null; + } + } + /// Logs user into the system + /// + /// + Future loginUser(String username, String password, { bool justIgnoreThisFlag: true}) async { + if (!justIgnoreThisFlag) { + print('Why??? Just trust me, I only need this variable inside the mustache codegen template.'); + // This code may be removed as soon as dart accepts trailing spaces (has already been implemented). + } + Object postBody = null; + + // verify required params are set + if(username == null) { + throw new ApiException(400, "Missing required param: username"); + } + if(password == null) { + throw new ApiException(400, "Missing required param: password"); + } + + // create path and map variables + String path = "/user/login".replaceAll("{format}","json"); + + // query params + List queryParams = []; + Map headerParams = {}; + Map formParams = {}; + if("null" != username) { + queryParams.addAll(_convertParametersForCollectionFormat("", "username", username)); + } + if("null" != password) { + queryParams.addAll(_convertParametersForCollectionFormat("", "password", password)); + } + + List contentTypes = []; + + String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; + List authNames = []; + + if(contentType.startsWith("multipart/form-data")) { + bool hasFields = false; + MultipartRequest mp = new MultipartRequest(null, null); + + if(hasFields) + postBody = mp; + } + else { + } + + var response = await apiClient.invokeAPI(path, + 'GET', + queryParams, + postBody, + headerParams, + formParams, + contentType, + authNames); + + if(response.statusCode >= 400) { + throw new ApiException(response.statusCode, response.body); + } else if(response.body != null) { + return apiClient.deserialize(response.body, 'String') ; + } else { + return null; + } + } + /// Logs out current logged in user session + /// + /// + Future logoutUser( { bool justIgnoreThisFlag: true}) async { + if (!justIgnoreThisFlag) { + print('Why??? Just trust me, I only need this variable inside the mustache codegen template.'); + // This code may be removed as soon as dart accepts trailing spaces (has already been implemented). + } + Object postBody = null; + + // verify required params are set + + // create path and map variables + String path = "/user/logout".replaceAll("{format}","json"); + + // query params + List queryParams = []; + Map headerParams = {}; + Map formParams = {}; + + List contentTypes = []; + + String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; + List authNames = []; + + if(contentType.startsWith("multipart/form-data")) { + bool hasFields = false; + MultipartRequest mp = new MultipartRequest(null, null); + + if(hasFields) + postBody = mp; + } + else { + } + + var response = await apiClient.invokeAPI(path, + 'GET', + queryParams, + postBody, + headerParams, + formParams, + contentType, + authNames); + + if(response.statusCode >= 400) { + throw new ApiException(response.statusCode, response.body); + } else if(response.body != null) { + return ; + } else { + return ; + } + } + /// Updated user + /// + /// This can only be done by the logged in user. + Future updateUser(String username, User body, { bool justIgnoreThisFlag: true}) async { + if (!justIgnoreThisFlag) { + print('Why??? Just trust me, I only need this variable inside the mustache codegen template.'); + // This code may be removed as soon as dart accepts trailing spaces (has already been implemented). + } + Object postBody = body; + + // verify required params are set + if(username == null) { + throw new ApiException(400, "Missing required param: username"); + } + if(body == null) { + throw new ApiException(400, "Missing required param: body"); + } + + // create path and map variables + String path = "/user/{username}".replaceAll("{format}","json").replaceAll("{" + "username" + "}", username.toString()); + + // query params + List queryParams = []; + Map headerParams = {}; + Map formParams = {}; + + List contentTypes = []; + + String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; + List authNames = []; + + if(contentType.startsWith("multipart/form-data")) { + bool hasFields = false; + MultipartRequest mp = new MultipartRequest(null, null); + + if(hasFields) + postBody = mp; + } + else { + } + + var response = await apiClient.invokeAPI(path, + 'PUT', + queryParams, + postBody, + headerParams, + formParams, + contentType, + authNames); + + if(response.statusCode >= 400) { + throw new ApiException(response.statusCode, response.body); + } else if(response.body != null) { + return ; + } else { + return ; + } + } +} diff --git a/samples/client/petstore/dart/swagger/lib/api_client.dart b/samples/client/petstore/dart/swagger/lib/api_client.dart new file mode 100644 index 00000000000..e19e390573c --- /dev/null +++ b/samples/client/petstore/dart/swagger/lib/api_client.dart @@ -0,0 +1,175 @@ +part of swagger.api; + +class QueryParam { + String name; + String value; + + QueryParam(this.name, this.value); +} + +class ApiClient { + + String basePath; + var client = new BrowserClient(); + + Map _defaultHeaderMap = {}; + Map _authentications = {}; + + final dson = new Dartson.JSON(); + final DateFormat _dateFormatter = new DateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); + + final _RegList = new RegExp(r'^List<(.*)>$'); + final _RegMap = new RegExp(r'^Map$'); + + ApiClient({this.basePath: "http://petstore.swagger.io/v2"}) { + // Setup authentications (key: authentication name, value: authentication). + _authentications['petstore_auth'] = new OAuth(); + _authentications['api_key'] = new ApiKeyAuth("header", "api_key"); + } + + void addDefaultHeader(String key, String value) { + _defaultHeaderMap[key] = value; + } + + /// Format the given Date object into string. + String formatDate(DateTime date) { + return _dateFormatter.format(date); + } + + /// Format the given parameter object into string. + String parameterToString(Object param) { + if (param == null) { + return ''; + } else if (param is DateTime) { + return formatDate(param); + } else if (param is List) { + return (param).join(','); + } else { + return param.toString(); + } + } + + dynamic _deserialize(dynamic value, String targetType) { + try { + switch (targetType) { + case 'String': + return '$value'; + case 'int': + return value is int ? value : int.parse('$value'); + case 'bool': + return value is bool ? value : '$value'.toLowerCase() == 'true'; + case 'double': + return value is double ? value : double.parse('$value'); + case 'ApiResponse': + return dson.map(value, new ApiResponse()); + case 'Category': + return dson.map(value, new Category()); + case 'Order': + return dson.map(value, new Order()); + case 'Pet': + return dson.map(value, new Pet()); + case 'Tag': + return dson.map(value, new Tag()); + case 'User': + return dson.map(value, new User()); + default: + { + Match match; + if (value is List && + (match = _RegList.firstMatch(targetType)) != null) { + var valueL = value as List; + var newTargetType = match[1]; + return valueL.map((v) => _deserialize(v, newTargetType)).toList(); + } else if (value is Map && + (match = _RegMap.firstMatch(targetType)) != null) { + var valueM = value as Map; + var newTargetType = match[1]; + return new Map.fromIterables(valueM.keys, + valueM.values.map((v) => _deserialize(v, newTargetType))); + } + } + } + } catch(e) { + // Just throw the ApiException below + } + throw new ApiException(500, 'Could not find a suitable class for deserialization'); + } + + dynamic deserialize(String json, String targetType) { + // Remove all spaces. Necessary for reg expressions as well. + targetType = targetType.replaceAll(' ', ''); + + if (targetType == 'String') return json; + + var decodedJson = JSON.decode(json); + return _deserialize(decodedJson, targetType); + } + + String serialize(Object obj) { + String serialized = ''; + if (obj == null) { + serialized = ''; + } else if (obj is String) { + serialized = obj; + } else { + serialized = dson.encode(obj); + } + return serialized; + } + + // We don't use a Map for queryParams. + // If collectionFormat is 'multi' a key might appear multiple times. + Future invokeAPI(String path, + String method, + List queryParams, + Object body, + Map headerParams, + Map formParams, + String contentType, + List authNames) async { + + _updateParamsForAuth(authNames, queryParams, headerParams); + + var ps = queryParams.where((p) => p.value != null).map((p) => '${p.name}=${p.value}'); + String queryString = ps.isNotEmpty ? + '?' + ps.join('&') : + ''; + + String url = basePath + path + queryString; + + headerParams.addAll(_defaultHeaderMap); + headerParams['Content-Type'] = contentType; + + if(body is MultipartRequest) { + var request = new MultipartRequest(method, Uri.parse(url)); + request.fields.addAll(body.fields); + request.files.addAll(body.files); + request.headers.addAll(body.headers); + request.headers.addAll(headerParams); + var response = await client.send(request); + return Response.fromStream(response); + } else { + var msgBody = contentType == "application/x-www-form-urlencoded" ? formParams : serialize(body); + switch(method) { + case "POST": + return client.post(url, headers: headerParams, body: msgBody); + case "PUT": + return client.put(url, headers: headerParams, body: msgBody); + case "DELETE": + return client.delete(url, headers: headerParams); + default: + return client.get(url, headers: headerParams); + } + } + } + + /// Update query and header parameters based on authentication settings. + /// @param authNames The authentications to apply + void _updateParamsForAuth(List authNames, List queryParams, Map headerParams) { + authNames.forEach((authName) { + Authentication auth = _authentications[authName]; + if (auth == null) throw new ArgumentError("Authentication undefined: " + authName); + auth.applyToParams(queryParams, headerParams); + }); + } +} diff --git a/samples/client/petstore/dart/swagger/lib/api_exception.dart b/samples/client/petstore/dart/swagger/lib/api_exception.dart new file mode 100644 index 00000000000..6a043acb7a7 --- /dev/null +++ b/samples/client/petstore/dart/swagger/lib/api_exception.dart @@ -0,0 +1,9 @@ +part of swagger.api; + +class ApiException implements Exception { + int code = 0; + String message = null; + + ApiException(this.code, this.message); + +} \ No newline at end of file diff --git a/samples/client/petstore/dart/swagger/lib/api_helper.dart b/samples/client/petstore/dart/swagger/lib/api_helper.dart new file mode 100644 index 00000000000..0092a121bc4 --- /dev/null +++ b/samples/client/petstore/dart/swagger/lib/api_helper.dart @@ -0,0 +1,33 @@ +part of swagger.api; + +const _delimiters = const {'csv': ',', 'ssv': ' ', 'tsv': '\t', 'pipes': '|'}; + +// port from Java version +List _convertParametersForCollectionFormat( + String collectionFormat, String name, dynamic value) { + var params = []; + + // preconditions + if (name == null || name.isEmpty || value == null) return params; + + if (value is! List) { + params.add(new QueryParam(name, value as String)); + return params; + } + + List values = value as List; + + // get the collection format + collectionFormat = (collectionFormat == null || collectionFormat.isEmpty) + ? "csv" + : collectionFormat; // default: csv + + if (collectionFormat == "multi") { + return values.map((v) => new QueryParam(name, v)); + } + + String delimiter = _delimiters[collectionFormat] ?? ","; + + params.add(new QueryParam(name, values.join(delimiter))); + return params; +} diff --git a/samples/client/petstore/dart/swagger/lib/auth/api_key_auth.dart b/samples/client/petstore/dart/swagger/lib/auth/api_key_auth.dart new file mode 100644 index 00000000000..d46fa15e9b8 --- /dev/null +++ b/samples/client/petstore/dart/swagger/lib/auth/api_key_auth.dart @@ -0,0 +1,27 @@ +part of swagger.api; + +class ApiKeyAuth implements Authentication { + + final String location; + final String paramName; + String apiKey; + String apiKeyPrefix; + + ApiKeyAuth(this.location, this.paramName); + + @override + void applyToParams(List queryParams, Map headerParams) { + String value; + if (apiKeyPrefix != null) { + value = '$apiKeyPrefix $apiKey'; + } else { + value = apiKey; + } + + if (location == 'query' && value != null) { + queryParams.add(new QueryParam(paramName, value)); + } else if (location == 'header' && value != null) { + headerParams[paramName] = value; + } + } +} \ No newline at end of file diff --git a/samples/client/petstore/dart/swagger/lib/auth/authentication.dart b/samples/client/petstore/dart/swagger/lib/auth/authentication.dart new file mode 100644 index 00000000000..3d6b6aadcda --- /dev/null +++ b/samples/client/petstore/dart/swagger/lib/auth/authentication.dart @@ -0,0 +1,7 @@ +part of swagger.api; + +abstract class Authentication { + + /// Apply authentication settings to header and query params. + void applyToParams(List queryParams, Map headerParams); +} \ No newline at end of file diff --git a/samples/client/petstore/dart/swagger/lib/auth/http_basic_auth.dart b/samples/client/petstore/dart/swagger/lib/auth/http_basic_auth.dart new file mode 100644 index 00000000000..7a118d6cdad --- /dev/null +++ b/samples/client/petstore/dart/swagger/lib/auth/http_basic_auth.dart @@ -0,0 +1,14 @@ +part of swagger.api; + +class HttpBasicAuth implements Authentication { + + String username; + String password; + + @override + void applyToParams(List queryParams, Map headerParams) { + String str = (username == null ? "" : username) + ":" + (password == null ? "" : password); + headerParams["Authorization"] = "Basic " + BASE64.encode(UTF8.encode(str)); + } + +} \ No newline at end of file diff --git a/samples/client/petstore/dart/swagger/lib/auth/oauth.dart b/samples/client/petstore/dart/swagger/lib/auth/oauth.dart new file mode 100644 index 00000000000..405c5119a45 --- /dev/null +++ b/samples/client/petstore/dart/swagger/lib/auth/oauth.dart @@ -0,0 +1,9 @@ +part of swagger.api; + +class OAuth implements Authentication { + + @override + void applyToParams(List queryParams, Map headerParams) { + // TODO: support oauth + } +} \ No newline at end of file diff --git a/samples/client/petstore/dart/swagger/lib/model/api_response.dart b/samples/client/petstore/dart/swagger/lib/model/api_response.dart new file mode 100644 index 00000000000..b2ac2c2577e --- /dev/null +++ b/samples/client/petstore/dart/swagger/lib/model/api_response.dart @@ -0,0 +1,26 @@ +part of swagger.api; + + +@Entity() +class ApiResponse { + + @Property(name: 'code') + int code = null; + + + @Property(name: 'type') + String type = null; + + + @Property(name: 'message') + String message = null; + + ApiResponse(); + + @override + String toString() { + return 'ApiResponse[code=$code, type=$type, message=$message, ]'; + } + +} + diff --git a/samples/client/petstore/dart/swagger/lib/model/category.dart b/samples/client/petstore/dart/swagger/lib/model/category.dart new file mode 100644 index 00000000000..9ab2a96fc37 --- /dev/null +++ b/samples/client/petstore/dart/swagger/lib/model/category.dart @@ -0,0 +1,22 @@ +part of swagger.api; + + +@Entity() +class Category { + + @Property(name: 'id') + int id = null; + + + @Property(name: 'name') + String name = null; + + Category(); + + @override + String toString() { + return 'Category[id=$id, name=$name, ]'; + } + +} + diff --git a/samples/client/petstore/dart/swagger/lib/model/order.dart b/samples/client/petstore/dart/swagger/lib/model/order.dart new file mode 100644 index 00000000000..d7ea97b3bad --- /dev/null +++ b/samples/client/petstore/dart/swagger/lib/model/order.dart @@ -0,0 +1,38 @@ +part of swagger.api; + + +@Entity() +class Order { + + @Property(name: 'id') + int id = null; + + + @Property(name: 'petId') + int petId = null; + + + @Property(name: 'quantity') + int quantity = null; + + + @Property(name: 'shipDate') + DateTime shipDate = null; + +/* Order Status */ + @Property(name: 'status') + String status = null; + //enum statusEnum { placed, approved, delivered, }; + + @Property(name: 'complete') + bool complete = null; + + Order(); + + @override + String toString() { + return 'Order[id=$id, petId=$petId, quantity=$quantity, shipDate=$shipDate, status=$status, complete=$complete, ]'; + } + +} + diff --git a/samples/client/petstore/dart/swagger/lib/model/pet.dart b/samples/client/petstore/dart/swagger/lib/model/pet.dart new file mode 100644 index 00000000000..03e13743763 --- /dev/null +++ b/samples/client/petstore/dart/swagger/lib/model/pet.dart @@ -0,0 +1,38 @@ +part of swagger.api; + + +@Entity() +class Pet { + + @Property(name: 'id') + int id = null; + + + @Property(name: 'category') + Category category = null; + + + @Property(name: 'name') + String name = null; + + + @Property(name: 'photoUrls') + List photoUrls = []; + + + @Property(name: 'tags') + List tags = []; + +/* pet status in the store */ + @Property(name: 'status') + String status = null; + //enum statusEnum { available, pending, sold, }; + Pet(); + + @override + String toString() { + return 'Pet[id=$id, category=$category, name=$name, photoUrls=$photoUrls, tags=$tags, status=$status, ]'; + } + +} + diff --git a/samples/client/petstore/dart/swagger/lib/model/tag.dart b/samples/client/petstore/dart/swagger/lib/model/tag.dart new file mode 100644 index 00000000000..485de92a615 --- /dev/null +++ b/samples/client/petstore/dart/swagger/lib/model/tag.dart @@ -0,0 +1,22 @@ +part of swagger.api; + + +@Entity() +class Tag { + + @Property(name: 'id') + int id = null; + + + @Property(name: 'name') + String name = null; + + Tag(); + + @override + String toString() { + return 'Tag[id=$id, name=$name, ]'; + } + +} + diff --git a/samples/client/petstore/dart/swagger/lib/model/user.dart b/samples/client/petstore/dart/swagger/lib/model/user.dart new file mode 100644 index 00000000000..f529d9432c1 --- /dev/null +++ b/samples/client/petstore/dart/swagger/lib/model/user.dart @@ -0,0 +1,46 @@ +part of swagger.api; + + +@Entity() +class User { + + @Property(name: 'id') + int id = null; + + + @Property(name: 'username') + String username = null; + + + @Property(name: 'firstName') + String firstName = null; + + + @Property(name: 'lastName') + String lastName = null; + + + @Property(name: 'email') + String email = null; + + + @Property(name: 'password') + String password = null; + + + @Property(name: 'phone') + String phone = null; + +/* User Status */ + @Property(name: 'userStatus') + int userStatus = null; + + User(); + + @override + String toString() { + return 'User[id=$id, username=$username, firstName=$firstName, lastName=$lastName, email=$email, password=$password, phone=$phone, userStatus=$userStatus, ]'; + } + +} + diff --git a/samples/client/petstore/dart/swagger/pubspec.yaml b/samples/client/petstore/dart/swagger/pubspec.yaml new file mode 100644 index 00000000000..e74546ea210 --- /dev/null +++ b/samples/client/petstore/dart/swagger/pubspec.yaml @@ -0,0 +1,14 @@ +name: swagger +version: 1.0.0 +description: Swagger API client +dependencies: + http: '>=0.11.1 <0.12.0' + dartson: "^0.2.4" + intl: "^0.12.4+2" + +dev_dependencies: + guinness: '^0.1.17' + browser: any + +transformers: + - dartson From c32a2d8d584922306fb0f644d8fa33b10fe7ca6e Mon Sep 17 00:00:00 2001 From: Christian Loitsch Date: Fri, 15 Jul 2016 18:00:11 +0200 Subject: [PATCH 06/10] feat: add DateTimerParser transformer --- .../src/main/resources/dart/api_client.mustache | 11 +++++------ .../src/main/resources/dart/api_helper.mustache | 2 +- .../src/main/resources/dart/apilib.mustache | 1 + samples/client/petstore/dart/lib/api.dart | 1 + samples/client/petstore/dart/lib/api_client.dart | 11 +++++------ samples/client/petstore/dart/lib/api_helper.dart | 2 +- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/dart/api_client.mustache b/modules/swagger-codegen/src/main/resources/dart/api_client.mustache index 26c9e051a43..94a4767eaf6 100644 --- a/modules/swagger-codegen/src/main/resources/dart/api_client.mustache +++ b/modules/swagger-codegen/src/main/resources/dart/api_client.mustache @@ -15,7 +15,8 @@ class ApiClient { Map _defaultHeaderMap = {}; Map _authentications = {}; - final dson = new Dartson.JSON(); + final dson = new Dartson.JSON() + ..addTransformer(new DateTimeParser(), DateTime); final DateFormat _dateFormatter = new DateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); final _RegList = new RegExp(r'^List<(.*)>$'); @@ -72,15 +73,13 @@ class ApiClient { Match match; if (value is List && (match = _RegList.firstMatch(targetType)) != null) { - var valueL = value as List; var newTargetType = match[1]; - return valueL.map((v) => _deserialize(v, newTargetType)).toList(); + return value.map((v) => _deserialize(v, newTargetType)).toList(); } else if (value is Map && (match = _RegMap.firstMatch(targetType)) != null) { - var valueM = value as Map; var newTargetType = match[1]; - return new Map.fromIterables(valueM.keys, - valueM.values.map((v) => _deserialize(v, newTargetType))); + return new Map.fromIterables(value.keys, + value.values.map((v) => _deserialize(v, newTargetType))); } } } diff --git a/modules/swagger-codegen/src/main/resources/dart/api_helper.mustache b/modules/swagger-codegen/src/main/resources/dart/api_helper.mustache index 0d2381ef592..6052dfb312b 100644 --- a/modules/swagger-codegen/src/main/resources/dart/api_helper.mustache +++ b/modules/swagger-codegen/src/main/resources/dart/api_helper.mustache @@ -23,7 +23,7 @@ Iterable _convertParametersForCollectionFormat( : collectionFormat; // default: csv if (collectionFormat == "multi") { - return values.map((v) => new QueryParam(name, '$v')) as Iterable; + return values.map((v) => new QueryParam(name, '$v')); } String delimiter = _delimiters[collectionFormat] ?? ","; diff --git a/modules/swagger-codegen/src/main/resources/dart/apilib.mustache b/modules/swagger-codegen/src/main/resources/dart/apilib.mustache index 2ff574432f7..f608cf214e0 100644 --- a/modules/swagger-codegen/src/main/resources/dart/apilib.mustache +++ b/modules/swagger-codegen/src/main/resources/dart/apilib.mustache @@ -5,6 +5,7 @@ import 'dart:convert';{{#browserClient}} import 'package:http/browser_client.dart';{{/browserClient}} import 'package:http/http.dart'; import 'package:dartson/dartson.dart'; +import 'package:dartson/transformers/date_time.dart'; import 'package:intl/intl.dart'; part 'api_client.dart'; diff --git a/samples/client/petstore/dart/lib/api.dart b/samples/client/petstore/dart/lib/api.dart index 667f617176e..db95000d614 100644 --- a/samples/client/petstore/dart/lib/api.dart +++ b/samples/client/petstore/dart/lib/api.dart @@ -5,6 +5,7 @@ import 'dart:convert'; import 'package:http/browser_client.dart'; import 'package:http/http.dart'; import 'package:dartson/dartson.dart'; +import 'package:dartson/transformers/date_time.dart'; import 'package:intl/intl.dart'; part 'api_client.dart'; diff --git a/samples/client/petstore/dart/lib/api_client.dart b/samples/client/petstore/dart/lib/api_client.dart index b3ee4065d2c..f18dce82f1f 100644 --- a/samples/client/petstore/dart/lib/api_client.dart +++ b/samples/client/petstore/dart/lib/api_client.dart @@ -15,7 +15,8 @@ class ApiClient { Map _defaultHeaderMap = {}; Map _authentications = {}; - final dson = new Dartson.JSON(); + final dson = new Dartson.JSON() + ..addTransformer(new DateTimeParser(), DateTime); final DateFormat _dateFormatter = new DateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); final _RegList = new RegExp(r'^List<(.*)>$'); @@ -77,15 +78,13 @@ class ApiClient { Match match; if (value is List && (match = _RegList.firstMatch(targetType)) != null) { - var valueL = value as List; var newTargetType = match[1]; - return valueL.map((v) => _deserialize(v, newTargetType)).toList(); + return value.map((v) => _deserialize(v, newTargetType)).toList(); } else if (value is Map && (match = _RegMap.firstMatch(targetType)) != null) { - var valueM = value as Map; var newTargetType = match[1]; - return new Map.fromIterables(valueM.keys, - valueM.values.map((v) => _deserialize(v, newTargetType))); + return new Map.fromIterables(value.keys, + value.values.map((v) => _deserialize(v, newTargetType))); } } } diff --git a/samples/client/petstore/dart/lib/api_helper.dart b/samples/client/petstore/dart/lib/api_helper.dart index 00d7836915a..ad73218ab40 100644 --- a/samples/client/petstore/dart/lib/api_helper.dart +++ b/samples/client/petstore/dart/lib/api_helper.dart @@ -23,7 +23,7 @@ Iterable _convertParametersForCollectionFormat( : collectionFormat; // default: csv if (collectionFormat == "multi") { - return values.map((v) => new QueryParam(name, '$v')) as Iterable; + return values.map((v) => new QueryParam(name, '$v')); } String delimiter = _delimiters[collectionFormat] ?? ","; From bc0e04b11709d75ccb7036b418fa7cb10388cd96 Mon Sep 17 00:00:00 2001 From: Anton WIMMER Date: Fri, 22 Jul 2016 13:35:39 +0200 Subject: [PATCH 07/10] feat: improved exception reporting --- .../src/main/resources/dart/api_client.mustache | 4 ++-- .../main/resources/dart/api_exception.mustache | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/dart/api_client.mustache b/modules/swagger-codegen/src/main/resources/dart/api_client.mustache index 94a4767eaf6..b591c974ea4 100644 --- a/modules/swagger-codegen/src/main/resources/dart/api_client.mustache +++ b/modules/swagger-codegen/src/main/resources/dart/api_client.mustache @@ -83,8 +83,8 @@ class ApiClient { } } } - } catch(e) { - // Just throw the ApiException below + } catch (e, stack) { + throw new ApiException.withInner(500, 'Exception during deserialization.', e, stack); } throw new ApiException(500, 'Could not find a suitable class for deserialization'); } diff --git a/modules/swagger-codegen/src/main/resources/dart/api_exception.mustache b/modules/swagger-codegen/src/main/resources/dart/api_exception.mustache index b0130dc61f5..b86af8d954c 100644 --- a/modules/swagger-codegen/src/main/resources/dart/api_exception.mustache +++ b/modules/swagger-codegen/src/main/resources/dart/api_exception.mustache @@ -3,7 +3,21 @@ part of {{pubName}}.api; class ApiException implements Exception { int code = 0; String message = null; + Exception innerException = null; + StackTrace stackTrace = null; ApiException(this.code, this.message); -} \ No newline at end of file + ApiException.withInner(this.code, this.message, this.innerException, this.stackTrace); + + String toString() { + if (message == null) return "ApiException"; + + if (innerException == null) { + return "ApiException $code: $message"; + } + + return "ApiException $code: $message (Inner exception: ${innerException})\n\n" + + stackTrace.toString(); + } +} From db4119373a3897c3df8d03cb2355a38c005f0f20 Mon Sep 17 00:00:00 2001 From: Anton WIMMER Date: Fri, 22 Jul 2016 13:36:35 +0200 Subject: [PATCH 08/10] feat[dart]: handle patch requests --- .../src/main/resources/dart/api_client.mustache | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/swagger-codegen/src/main/resources/dart/api_client.mustache b/modules/swagger-codegen/src/main/resources/dart/api_client.mustache index b591c974ea4..2b07ce853a6 100644 --- a/modules/swagger-codegen/src/main/resources/dart/api_client.mustache +++ b/modules/swagger-codegen/src/main/resources/dart/api_client.mustache @@ -96,7 +96,7 @@ class ApiClient { if (targetType == 'String') return json; var decodedJson = JSON.decode(json); - return _deserialize(decodedJson, targetType); + return _deserialize(deccodedJson, targetType); } String serialize(Object obj) { @@ -151,6 +151,8 @@ class ApiClient { return client.put(url, headers: headerParams, body: msgBody); case "DELETE": return client.delete(url, headers: headerParams); + case "PATCH": + return client.patch(url, headers: headerParams, body: msgBody); default: return client.get(url, headers: headerParams); } From 9c460da8105a301e26a7989c76a1f2bb903284a3 Mon Sep 17 00:00:00 2001 From: Anton WIMMER Date: Fri, 22 Jul 2016 13:42:12 +0200 Subject: [PATCH 09/10] fix[dart]: typo --- .../swagger-codegen/src/main/resources/dart/api_client.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/swagger-codegen/src/main/resources/dart/api_client.mustache b/modules/swagger-codegen/src/main/resources/dart/api_client.mustache index 2b07ce853a6..dcbd731d2af 100644 --- a/modules/swagger-codegen/src/main/resources/dart/api_client.mustache +++ b/modules/swagger-codegen/src/main/resources/dart/api_client.mustache @@ -96,7 +96,7 @@ class ApiClient { if (targetType == 'String') return json; var decodedJson = JSON.decode(json); - return _deserialize(deccodedJson, targetType); + return _deserialize(decodedJson, targetType); } String serialize(Object obj) { From d22aff21d3237308f8549d27d8a57265c89802f7 Mon Sep 17 00:00:00 2001 From: Christian Loitsch Date: Fri, 22 Jul 2016 16:53:27 +0200 Subject: [PATCH 10/10] fix dart: remove findPetsByTag test; enable strong-mode find pets by tag call is deprecated and returns 500 generated library is now strong mode compatible --- .../dart/petstore/test/browser/packages | 1 + .../petstore/dart/petstore/test/pet_test.dart | 28 ------------------- .../petstore/dart/petstore/test/tests.dart | 1 - .../petstore/dart/swagger/.analysis_options | 2 ++ .../petstore/dart/swagger/lib/api_client.dart | 6 ++-- .../dart/swagger/lib/api_exception.dart | 16 ++++++++++- 6 files changed, 22 insertions(+), 32 deletions(-) create mode 120000 samples/client/petstore/dart/petstore/test/browser/packages create mode 100644 samples/client/petstore/dart/swagger/.analysis_options diff --git a/samples/client/petstore/dart/petstore/test/browser/packages b/samples/client/petstore/dart/petstore/test/browser/packages new file mode 120000 index 00000000000..4b727bf6889 --- /dev/null +++ b/samples/client/petstore/dart/petstore/test/browser/packages @@ -0,0 +1 @@ +../../packages \ No newline at end of file diff --git a/samples/client/petstore/dart/petstore/test/pet_test.dart b/samples/client/petstore/dart/petstore/test/pet_test.dart index e9a7ccd5fa7..213396f29cb 100644 --- a/samples/client/petstore/dart/petstore/test/pet_test.dart +++ b/samples/client/petstore/dart/petstore/test/pet_test.dart @@ -71,34 +71,6 @@ testPetApi() { }); }); - it('finds pets by tag', () async { - var snowyId = newId(); - var grumpyId = newId(); - var snowyTags = [ - new Tag() - ..id = newId() - ..name = 'terrier' - ]; - var grumpyTags = [ - new Tag() - ..id = newId() - ..name = 'grumpy' - ]; - await petApi.addPet(new Pet() - ..id = snowyId - ..name = 'Snowy' - ..tags = snowyTags); - await petApi.addPet(new Pet() - ..id = grumpyId - ..name = 'Grumpy Cat' - ..tags = grumpyTags); - - var pets = await petApi.findPetsByTags(['grumpy']); - var petIds = pets.map((pet) => pet.id).toList(); - expect(petIds).toContain(grumpyId); - expect(petIds).not.toContain(snowyId); - }); - it('uploads a pet image', () async { var id = newId(); await petApi.addPet(new Pet()..id = id); diff --git a/samples/client/petstore/dart/petstore/test/tests.dart b/samples/client/petstore/dart/petstore/test/tests.dart index 1c072d2767d..9511ea17875 100644 --- a/samples/client/petstore/dart/petstore/test/tests.dart +++ b/samples/client/petstore/dart/petstore/test/tests.dart @@ -17,7 +17,6 @@ int newId() { } main() { - defaultApiClient.client = new Client(); testPetApi(); testStoreApi(); testUserApi(); diff --git a/samples/client/petstore/dart/swagger/.analysis_options b/samples/client/petstore/dart/swagger/.analysis_options new file mode 100644 index 00000000000..518eb901a6f --- /dev/null +++ b/samples/client/petstore/dart/swagger/.analysis_options @@ -0,0 +1,2 @@ +analyzer: + strong-mode: true \ No newline at end of file diff --git a/samples/client/petstore/dart/swagger/lib/api_client.dart b/samples/client/petstore/dart/swagger/lib/api_client.dart index f18dce82f1f..9087a80d8cc 100644 --- a/samples/client/petstore/dart/swagger/lib/api_client.dart +++ b/samples/client/petstore/dart/swagger/lib/api_client.dart @@ -88,8 +88,8 @@ class ApiClient { } } } - } catch(e) { - // Just throw the ApiException below + } catch (e, stack) { + throw new ApiException.withInner(500, 'Exception during deserialization.', e, stack); } throw new ApiException(500, 'Could not find a suitable class for deserialization'); } @@ -156,6 +156,8 @@ class ApiClient { return client.put(url, headers: headerParams, body: msgBody); case "DELETE": return client.delete(url, headers: headerParams); + case "PATCH": + return client.patch(url, headers: headerParams, body: msgBody); default: return client.get(url, headers: headerParams); } diff --git a/samples/client/petstore/dart/swagger/lib/api_exception.dart b/samples/client/petstore/dart/swagger/lib/api_exception.dart index 6a043acb7a7..b861591bec0 100644 --- a/samples/client/petstore/dart/swagger/lib/api_exception.dart +++ b/samples/client/petstore/dart/swagger/lib/api_exception.dart @@ -3,7 +3,21 @@ part of swagger.api; class ApiException implements Exception { int code = 0; String message = null; + Exception innerException = null; + StackTrace stackTrace = null; ApiException(this.code, this.message); -} \ No newline at end of file + ApiException.withInner(this.code, this.message, this.innerException, this.stackTrace); + + String toString() { + if (message == null) return "ApiException"; + + if (innerException == null) { + return "ApiException $code: $message"; + } + + return "ApiException $code: $message (Inner exception: ${innerException})\n\n" + + stackTrace.toString(); + } +}