Permalink
Browse files

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

* Add an option for Dart2

* add dart2 samples, update travis

* fix dart installation

* Upper constraints on the SDK version

* Update dependencies

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

* Update petstore tests

* Update dart2-petstore.sh

* Running tests on Dart VM

* Fixed JSON deserialization bugs

* Fixed missing initialization of postBody

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

* Update pom.xml

* Added SDK version constraints in pubspec.mustache

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

* move dart2 test to the end
  • Loading branch information...
swipesight authored and wing328 committed Aug 31, 2018
1 parent 31149a5 commit d327c5be464d02aa31e24d2ef6eae959e0563a86
Showing with 10,604 additions and 2 deletions.
  1. +11 −1 .travis.yml
  2. +50 −0 bin/dart2-petstore.sh
  3. +9 −1 modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartClientCodegen.java
  4. +133 −0 modules/openapi-generator/src/main/resources/dart2/README.mustache
  5. +117 −0 modules/openapi-generator/src/main/resources/dart2/api.mustache
  6. +164 −0 modules/openapi-generator/src/main/resources/dart2/api_client.mustache
  7. +86 −0 modules/openapi-generator/src/main/resources/dart2/api_doc.mustache
  8. +23 −0 modules/openapi-generator/src/main/resources/dart2/api_exception.mustache
  9. +52 −0 modules/openapi-generator/src/main/resources/dart2/api_helper.mustache
  10. +21 −0 modules/openapi-generator/src/main/resources/dart2/apilib.mustache
  11. +27 −0 modules/openapi-generator/src/main/resources/dart2/auth/api_key_auth.mustache
  12. +7 −0 modules/openapi-generator/src/main/resources/dart2/auth/authentication.mustache
  13. +14 −0 modules/openapi-generator/src/main/resources/dart2/auth/http_basic_auth.mustache
  14. +18 −0 modules/openapi-generator/src/main/resources/dart2/auth/oauth.mustache
  15. +82 −0 modules/openapi-generator/src/main/resources/dart2/class.mustache
  16. +36 −0 modules/openapi-generator/src/main/resources/dart2/enum.mustache
  17. +52 −0 modules/openapi-generator/src/main/resources/dart2/git_push.sh.mustache
  18. +27 −0 modules/openapi-generator/src/main/resources/dart2/gitignore.mustache
  19. +12 −0 modules/openapi-generator/src/main/resources/dart2/model.mustache
  20. +16 −0 modules/openapi-generator/src/main/resources/dart2/object_doc.mustache
  21. +7 −0 modules/openapi-generator/src/main/resources/dart2/pubspec.mustache
  22. +1 −0 ...s/openapi-generator/src/test/java/org/openapitools/codegen/options/DartClientOptionsProvider.java
  23. +1 −0 pom.xml
  24. +2 −0 samples/client/petstore/dart2/flutter_petstore/openapi/.analysis_options
  25. +27 −0 samples/client/petstore/dart2/flutter_petstore/openapi/.gitignore
  26. +23 −0 samples/client/petstore/dart2/flutter_petstore/openapi/.openapi-generator-ignore
  27. +1 −0 samples/client/petstore/dart2/flutter_petstore/openapi/.openapi-generator/VERSION
  28. +121 −0 samples/client/petstore/dart2/flutter_petstore/openapi/README.md
  29. +17 −0 samples/client/petstore/dart2/flutter_petstore/openapi/docs/ApiResponse.md
  30. +16 −0 samples/client/petstore/dart2/flutter_petstore/openapi/docs/Category.md
  31. +20 −0 samples/client/petstore/dart2/flutter_petstore/openapi/docs/Order.md
  32. +20 −0 samples/client/petstore/dart2/flutter_petstore/openapi/docs/Pet.md
  33. +379 −0 samples/client/petstore/dart2/flutter_petstore/openapi/docs/PetApi.md
  34. +186 −0 samples/client/petstore/dart2/flutter_petstore/openapi/docs/StoreApi.md
  35. +16 −0 samples/client/petstore/dart2/flutter_petstore/openapi/docs/Tag.md
  36. +22 −0 samples/client/petstore/dart2/flutter_petstore/openapi/docs/User.md
  37. +349 −0 samples/client/petstore/dart2/flutter_petstore/openapi/docs/UserApi.md
  38. +52 −0 samples/client/petstore/dart2/flutter_petstore/openapi/git_push.sh
  39. +27 −0 samples/client/petstore/dart2/flutter_petstore/openapi/lib/api.dart
  40. +432 −0 samples/client/petstore/dart2/flutter_petstore/openapi/lib/api/pet_api.dart
  41. +207 −0 samples/client/petstore/dart2/flutter_petstore/openapi/lib/api/store_api.dart
  42. +409 −0 samples/client/petstore/dart2/flutter_petstore/openapi/lib/api/user_api.dart
  43. +160 −0 samples/client/petstore/dart2/flutter_petstore/openapi/lib/api_client.dart
  44. +23 −0 samples/client/petstore/dart2/flutter_petstore/openapi/lib/api_exception.dart
  45. +44 −0 samples/client/petstore/dart2/flutter_petstore/openapi/lib/api_helper.dart
  46. +27 −0 samples/client/petstore/dart2/flutter_petstore/openapi/lib/auth/api_key_auth.dart
  47. +7 −0 samples/client/petstore/dart2/flutter_petstore/openapi/lib/auth/authentication.dart
  48. +14 −0 samples/client/petstore/dart2/flutter_petstore/openapi/lib/auth/http_basic_auth.dart
  49. +18 −0 samples/client/petstore/dart2/flutter_petstore/openapi/lib/auth/oauth.dart
  50. +44 −0 samples/client/petstore/dart2/flutter_petstore/openapi/lib/model/api_response.dart
  51. +40 −0 samples/client/petstore/dart2/flutter_petstore/openapi/lib/model/category.dart
  52. +57 −0 samples/client/petstore/dart2/flutter_petstore/openapi/lib/model/order.dart
  53. +57 −0 samples/client/petstore/dart2/flutter_petstore/openapi/lib/model/pet.dart
  54. +40 −0 samples/client/petstore/dart2/flutter_petstore/openapi/lib/model/tag.dart
  55. +64 −0 samples/client/petstore/dart2/flutter_petstore/openapi/lib/model/user.dart
  56. +7 −0 samples/client/petstore/dart2/flutter_petstore/openapi/pubspec.yaml
  57. +2 −0 samples/client/petstore/dart2/openapi-browser-client/.analysis_options
  58. +27 −0 samples/client/petstore/dart2/openapi-browser-client/.gitignore
  59. +23 −0 samples/client/petstore/dart2/openapi-browser-client/.openapi-generator-ignore
  60. +1 −0 samples/client/petstore/dart2/openapi-browser-client/.openapi-generator/VERSION
  61. +121 −0 samples/client/petstore/dart2/openapi-browser-client/README.md
  62. +17 −0 samples/client/petstore/dart2/openapi-browser-client/docs/ApiResponse.md
  63. +16 −0 samples/client/petstore/dart2/openapi-browser-client/docs/Category.md
  64. +20 −0 samples/client/petstore/dart2/openapi-browser-client/docs/Order.md
  65. +20 −0 samples/client/petstore/dart2/openapi-browser-client/docs/Pet.md
  66. +379 −0 samples/client/petstore/dart2/openapi-browser-client/docs/PetApi.md
  67. +186 −0 samples/client/petstore/dart2/openapi-browser-client/docs/StoreApi.md
  68. +16 −0 samples/client/petstore/dart2/openapi-browser-client/docs/Tag.md
  69. +22 −0 samples/client/petstore/dart2/openapi-browser-client/docs/User.md
  70. +349 −0 samples/client/petstore/dart2/openapi-browser-client/docs/UserApi.md
  71. +52 −0 samples/client/petstore/dart2/openapi-browser-client/git_push.sh
  72. +28 −0 samples/client/petstore/dart2/openapi-browser-client/lib/api.dart
  73. +432 −0 samples/client/petstore/dart2/openapi-browser-client/lib/api/pet_api.dart
  74. +207 −0 samples/client/petstore/dart2/openapi-browser-client/lib/api/store_api.dart
  75. +409 −0 samples/client/petstore/dart2/openapi-browser-client/lib/api/user_api.dart
  76. +160 −0 samples/client/petstore/dart2/openapi-browser-client/lib/api_client.dart
  77. +23 −0 samples/client/petstore/dart2/openapi-browser-client/lib/api_exception.dart
  78. +44 −0 samples/client/petstore/dart2/openapi-browser-client/lib/api_helper.dart
  79. +27 −0 samples/client/petstore/dart2/openapi-browser-client/lib/auth/api_key_auth.dart
  80. +7 −0 samples/client/petstore/dart2/openapi-browser-client/lib/auth/authentication.dart
  81. +14 −0 samples/client/petstore/dart2/openapi-browser-client/lib/auth/http_basic_auth.dart
  82. +18 −0 samples/client/petstore/dart2/openapi-browser-client/lib/auth/oauth.dart
  83. +44 −0 samples/client/petstore/dart2/openapi-browser-client/lib/model/api_response.dart
  84. +40 −0 samples/client/petstore/dart2/openapi-browser-client/lib/model/category.dart
  85. +57 −0 samples/client/petstore/dart2/openapi-browser-client/lib/model/order.dart
  86. +57 −0 samples/client/petstore/dart2/openapi-browser-client/lib/model/pet.dart
  87. +40 −0 samples/client/petstore/dart2/openapi-browser-client/lib/model/tag.dart
  88. +64 −0 samples/client/petstore/dart2/openapi-browser-client/lib/model/user.dart
  89. +7 −0 samples/client/petstore/dart2/openapi-browser-client/pubspec.yaml
  90. +2 −0 samples/client/petstore/dart2/openapi/.analysis_options
  91. +27 −0 samples/client/petstore/dart2/openapi/.gitignore
  92. +23 −0 samples/client/petstore/dart2/openapi/.openapi-generator-ignore
  93. +1 −0 samples/client/petstore/dart2/openapi/.openapi-generator/VERSION
  94. +121 −0 samples/client/petstore/dart2/openapi/README.md
  95. +17 −0 samples/client/petstore/dart2/openapi/docs/ApiResponse.md
  96. +16 −0 samples/client/petstore/dart2/openapi/docs/Category.md
  97. +20 −0 samples/client/petstore/dart2/openapi/docs/Order.md
  98. +20 −0 samples/client/petstore/dart2/openapi/docs/Pet.md
  99. +379 −0 samples/client/petstore/dart2/openapi/docs/PetApi.md
  100. +186 −0 samples/client/petstore/dart2/openapi/docs/StoreApi.md
  101. +16 −0 samples/client/petstore/dart2/openapi/docs/Tag.md
  102. +22 −0 samples/client/petstore/dart2/openapi/docs/User.md
  103. +349 −0 samples/client/petstore/dart2/openapi/docs/UserApi.md
  104. +52 −0 samples/client/petstore/dart2/openapi/git_push.sh
  105. +27 −0 samples/client/petstore/dart2/openapi/lib/api.dart
  106. +432 −0 samples/client/petstore/dart2/openapi/lib/api/pet_api.dart
  107. +207 −0 samples/client/petstore/dart2/openapi/lib/api/store_api.dart
  108. +409 −0 samples/client/petstore/dart2/openapi/lib/api/user_api.dart
  109. +160 −0 samples/client/petstore/dart2/openapi/lib/api_client.dart
  110. +23 −0 samples/client/petstore/dart2/openapi/lib/api_exception.dart
  111. +44 −0 samples/client/petstore/dart2/openapi/lib/api_helper.dart
  112. +27 −0 samples/client/petstore/dart2/openapi/lib/auth/api_key_auth.dart
  113. +7 −0 samples/client/petstore/dart2/openapi/lib/auth/authentication.dart
  114. +14 −0 samples/client/petstore/dart2/openapi/lib/auth/http_basic_auth.dart
  115. +18 −0 samples/client/petstore/dart2/openapi/lib/auth/oauth.dart
  116. +44 −0 samples/client/petstore/dart2/openapi/lib/model/api_response.dart
  117. +40 −0 samples/client/petstore/dart2/openapi/lib/model/category.dart
  118. +57 −0 samples/client/petstore/dart2/openapi/lib/model/order.dart
  119. +57 −0 samples/client/petstore/dart2/openapi/lib/model/pet.dart
  120. +40 −0 samples/client/petstore/dart2/openapi/lib/model/tag.dart
  121. +64 −0 samples/client/petstore/dart2/openapi/lib/model/user.dart
  122. +7 −0 samples/client/petstore/dart2/openapi/pubspec.yaml
  123. +2 −0 samples/client/petstore/dart2/petstore/.analysis_options
  124. +58 −0 samples/client/petstore/dart2/petstore/README.md
  125. +61 −0 samples/client/petstore/dart2/petstore/pom.xml
  126. +516 −0 samples/client/petstore/dart2/petstore/pubspec.lock
  127. +13 −0 samples/client/petstore/dart2/petstore/pubspec.yaml
  128. +86 −0 samples/client/petstore/dart2/petstore/test/pet_test.dart
  129. +7 −0 samples/client/petstore/dart2/petstore/test/random_id.dart
  130. +31 −0 samples/client/petstore/dart2/petstore/test/store_test.dart
  131. +79 −0 samples/client/petstore/dart2/petstore/test/user_test.dart
View
@@ -30,6 +30,7 @@ cache:
- $HOME/perl5
- $HOME/.cargo
- $HOME/.stack
- $HOME/.pub-cache
- $HOME/samples/server/petstore/cpp-pistache/pistache
- $HOME/.npm
- $HOME/.rvm/gems/ruby-2.4.1
@@ -72,6 +73,13 @@ before_install:
- sudo apt-get update -qq
- sudo apt-get install -qq bats
- sudo apt-get install -qq curl
# install dart
#- sudo apt-get update
- sudo apt-get install apt-transport-https
- sudo sh -c 'curl https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -'
- sudo sh -c 'curl https://storage.googleapis.com/download.dartlang.org/linux/debian/dart_stable.list > /etc/apt/sources.list.d/dart_stable.list'
- sudo apt-get update
- sudo apt-get install dart
# install perl module
#- cpanm --local-lib=~/perl5 local::lib && eval $(perl -I ~/perl5/lib/perl5/ -Mlocal::lib)
#- cpanm Test::Exception Test::More Log::Any LWP::UserAgent JSON URI:Query Module::Runtime DateTime Module::Find Moose::Role
@@ -96,11 +104,13 @@ install:
# Add Godeps dependencies to GOPATH and PATH
#- eval "$(curl -sL https://raw.githubusercontent.com/travis-ci/gimme/master/gimme | GIMME_GO_VERSION=1.4 bash)"
#- export GOPATH="${TRAVIS_BUILD_DIR}/Godeps/_workspace"
- export PATH="${TRAVIS_BUILD_DIR}/Godeps/_workspace/bin:$HOME/.cargo/bin:$PATH"
- export PATH="${TRAVIS_BUILD_DIR}/Godeps/_workspace/bin:$HOME/.cargo/bin:$PATH:/usr/lib/dart/bin"
#- go version
- gcc -v
- echo $CC
- echo $CXX
- pub version
- dart --version
script:
# fail fast
View
@@ -0,0 +1,50 @@
#!/bin/sh
SCRIPT="$0"
echo "# START SCRIPT: $SCRIPT"
while [ -h "$SCRIPT" ] ; do
ls=`ls -ld "$SCRIPT"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
SCRIPT="$link"
else
SCRIPT=`dirname "$SCRIPT"`/"$link"
fi
done
if [ ! -d "${APP_DIR}" ]; then
APP_DIR=`dirname "$SCRIPT"`/..
APP_DIR=`cd "${APP_DIR}"; pwd`
fi
executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar"
if [ ! -f "$executable" ]
then
mvn -B clean package
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"
# Generate non-browserClient
ags="generate -t modules/openapi-generator/src/main/resources/dart -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g dart -o samples/client/petstore/dart2/openapi -DhideGenerationTimestamp=true -DbrowserClient=false --additional-properties supportDart2=true $@"
# then options to generate the library for vm would be:
#ags="generate -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g dart -o samples/client/petstore/dart2/openapi_vm -DbrowserClient=false -DpubName=openapi_vm $@"
java $JAVA_OPTS -jar $executable $ags
# Generate browserClient
ags="generate -t modules/openapi-generator/src/main/resources/dart -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g dart -o samples/client/petstore/dart2/openapi-browser-client -DhideGenerationTimestamp=true -DbrowserClient=true --additional-properties supportDart2=true $@"
java $JAVA_OPTS -jar $executable $ags
# Generate non-browserClient and put it to the flutter sample app
ags="generate -t modules/openapi-generator/src/main/resources/dart -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g dart -o samples/client/petstore/dart2/flutter_petstore/openapi -DhideGenerationTimestamp=true -DbrowserClient=false --additional-properties supportDart2=true $@"
java $JAVA_OPTS -jar $executable $ags
# 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.
@@ -28,6 +28,7 @@
import org.openapitools.codegen.utils.ModelUtils;
import io.swagger.v3.oas.models.media.*;
import io.swagger.v3.parser.util.SchemaTypeUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -48,6 +49,7 @@
public static final String PUB_VERSION = "pubVersion";
public static final String PUB_DESCRIPTION = "pubDescription";
public static final String USE_ENUM_EXTENSION = "useEnumExtension";
public static final String SUPPORT_DART2 = "supportDart2";
protected boolean browserClient = true;
protected String pubName = "openapi";
protected String pubVersion = "1.0.0";
@@ -125,6 +127,7 @@ public DartClientCodegen() {
cliOptions.add(new CliOption(PUB_DESCRIPTION, "Description in generated pubspec"));
cliOptions.add(new CliOption(USE_ENUM_EXTENSION, "Allow the 'x-enum-values' extension for enums"));
cliOptions.add(new CliOption(CodegenConstants.SOURCE_FOLDER, "source folder for generated code"));
cliOptions.add(CliOption.newBoolean(SUPPORT_DART2, "support dart2").defaultValue(Boolean.FALSE.toString()));
}
@Override
@@ -189,9 +192,14 @@ public void processOpts() {
additionalProperties.put("apiDocPath", apiDocPath);
additionalProperties.put("modelDocPath", modelDocPath);
final Object isSupportDart2 = additionalProperties.get(SUPPORT_DART2);
if (Boolean.TRUE.equals(isSupportDart2) || (isSupportDart2 instanceof String && Boolean.parseBoolean((String)isSupportDart2))) {
embeddedTemplateDir = templateDir = "dart2";
} else {
supportingFiles.add(new SupportingFile("analysis_options.mustache", "", ".analysis_options"));
}
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"));
@@ -0,0 +1,133 @@
# {{pubName}}
{{#appDescription}}
{{{appDescription}}}
{{/appDescription}}
This Dart package is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project:
- API version: {{appVersion}}
{{#artifactVersion}}
- Package version: {{artifactVersion}}
{{/artifactVersion}}
{{^hideGenerationTimestamp}}
- Build date: {{generatedDate}}
{{/hideGenerationTimestamp}}
- Build package: {{generatorClass}}
{{#infoUrl}}
For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}})
{{/infoUrl}}
## Requirements
Dart 1.20.0 or later OR Flutter 0.0.20 or later
## Installation & Usage
### Github
If this Dart package is published to Github, please include the following in pubspec.yaml
```
name: {{pubName}}
version: {{pubVersion}}
description: {{pubDescription}}
dependencies:
{{pubName}}:
git: https://github.com/{{gitUserId}}/{{gitRepoId}}.git
version: 'any'
```
### Local
To use the package in your local drive, please include the following in pubspec.yaml
```
dependencies:
{{pubName}}:
path: /path/to/{{pubName}}
```
## Tests
TODO
## Getting Started
Please follow the [installation procedure](#installation--usage) and then run the following:
```dart
import 'package:{{pubName}}/api.dart';
{{#apiInfo}}{{#apis}}{{#-first}}{{#operations}}{{#operation}}{{#-first}}
{{#hasAuthMethods}}
{{#authMethods}}
{{#isBasic}}
// TODO Configure HTTP basic authorization: {{{name}}}
//{{pubName}}.api.Configuration.username = 'YOUR_USERNAME';
//{{pubName}}.api.Configuration.password = 'YOUR_PASSWORD';
{{/isBasic}}
{{#isApiKey}}
// TODO Configure API key authorization: {{{name}}}
//{{pubName}}.api.Configuration.apiKey{'{{{keyParamName}}}'} = 'YOUR_API_KEY';
// uncomment below to setup prefix (e.g. Bearer) for API key, if needed
//{{pubName}}.api.Configuration.apiKeyPrefix{'{{{keyParamName}}}'} = "Bearer";
{{/isApiKey}}
{{#isOAuth}}
// TODO Configure OAuth2 access token for authorization: {{{name}}}
//{{pubName}}.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN';
{{/isOAuth}}
{{/authMethods}}
{{/hasAuthMethods}}
var api_instance = new {{classname}}();
{{#allParams}}
var {{paramName}} = {{#isListContainer}}[{{/isListContainer}}{{#isBodyParam}}new {{dataType}}(){{/isBodyParam}}{{^isBodyParam}}{{{example}}}{{/isBodyParam}}{{#isListContainer}}]{{/isListContainer}}; // {{{dataType}}} | {{{description}}}
{{/allParams}}
try {
{{#returnType}}var result = {{/returnType}}api_instance.{{{operationId}}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
{{#returnType}}
print(result);
{{/returnType}}
} catch (e) {
print("Exception when calling {{classname}}->{{operationId}}: $e\n");
}
{{/-first}}{{/operation}}{{/operations}}{{/-first}}{{/apis}}{{/apiInfo}}
```
## Documentation for API Endpoints
All URIs are relative to *{{basePath}}*
Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}*{{classname}}* | [**{{operationId}}**]({{apiDocPath}}/{{classname}}.md#{{operationIdLowerCase}}) | **{{httpMethod}}** {{path}} | {{#summary}}{{summary}}{{/summary}}
{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}}
## Documentation For Models
{{#models}}{{#model}} - [{{{classname}}}]({{modelDocPath}}/{{{classname}}}.md)
{{/model}}{{/models}}
## Documentation For Authorization
{{^authMethods}} All endpoints do not require authorization.
{{/authMethods}}{{#authMethods}}{{#last}} Authentication schemes defined for the API:{{/last}}{{/authMethods}}
{{#authMethods}}## {{{name}}}
{{#isApiKey}}- **Type**: API key
- **API key parameter name**: {{{keyParamName}}}
- **Location**: {{#isKeyInQuery}}URL query string{{/isKeyInQuery}}{{#isKeyInHeader}}HTTP header{{/isKeyInHeader}}
{{/isApiKey}}
{{#isBasic}}- **Type**: HTTP basic authentication
{{/isBasic}}
{{#isOAuth}}- **Type**: OAuth
- **Flow**: {{{flow}}}
- **Authorization URL**: {{{authorizationUrl}}}
- **Scopes**: {{^scopes}}N/A{{/scopes}}
{{#scopes}} - **{{{scope}}}**: {{{description}}}
{{/scopes}}
{{/isOAuth}}
{{/authMethods}}
## Author
{{#apiInfo}}{{#apis}}{{^hasMore}}{{infoEmail}}
{{/hasMore}}{{/apis}}{{/apiInfo}}
@@ -0,0 +1,117 @@
part of {{pubName}}.api;
{{#operations}}
class {{classname}} {
final ApiClient apiClient;
{{classname}}([ApiClient apiClient]) : apiClient = apiClient ?? defaultApiClient;
{{#operation}}
/// {{summary}}
///
/// {{notes}}
{{#returnType}}Future<{{{returnType}}}> {{/returnType}}{{^returnType}}Future {{/returnType}}{{nickname}}({{#allParams}}{{#required}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/required}}{{/allParams}}{{#hasOptionalParams}}{ {{#allParams}}{{^required}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/required}}{{/allParams}} }{{/hasOptionalParams}}) async {
Object postBody{{#bodyParam}} = {{paramName}}{{/bodyParam}};
// verify required params are set
{{#allParams}}
{{#required}}
if({{paramName}} == null) {
throw new ApiException(400, "Missing required param: {{paramName}}");
}
{{/required}}
{{/allParams}}
// create path and map variables
String path = "{{{path}}}".replaceAll("{format}","json"){{#pathParams}}.replaceAll("{" + "{{baseName}}" + "}", {{{paramName}}}.toString()){{/pathParams}};
// query params
List<QueryParam> queryParams = [];
Map<String, String> headerParams = {};
Map<String, String> formParams = {};
{{#queryParams}}
{{^required}}
if({{paramName}} != null) {
{{/required}}
queryParams.addAll(_convertParametersForCollectionFormat("{{collectionFormat}}", "{{baseName}}", {{paramName}}));
{{^required}}
}
{{/required}}
{{/queryParams}}
{{#headerParams}}
headerParams["{{baseName}}"] = {{paramName}};
{{/headerParams}}
List<String> contentTypes = [{{#consumes}}"{{{mediaType}}}"{{#hasMore}},{{/hasMore}}{{/consumes}}];
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
List<String> authNames = [{{#authMethods}}"{{name}}"{{#hasMore}}, {{/hasMore}}{{/authMethods}}];
if(contentType.startsWith("multipart/form-data")) {
bool hasFields = false;
MultipartRequest mp = new MultipartRequest(null, null);
{{#formParams}}
{{^isFile}}
if ({{paramName}} != null) {
hasFields = true;
mp.fields['{{baseName}}'] = parameterToString({{paramName}});
}
{{/isFile}}
{{#isFile}}
if ({{paramName}} != null) {
hasFields = true;
mp.fields['{{baseName}}'] = {{paramName}}.field;
mp.files.add({{paramName}});
}
{{/isFile}}
{{/formParams}}
if(hasFields)
postBody = mp;
}
else {
{{#formParams}}
{{^isFile}}
if ({{paramName}} != null)
formParams['{{baseName}}'] = parameterToString({{paramName}});
{{/isFile}}
{{/formParams}}
}
var response = await apiClient.invokeAPI(path,
'{{httpMethod}}',
queryParams,
postBody,
headerParams,
formParams,
contentType,
authNames);
if(response.statusCode >= 400) {
throw new ApiException(response.statusCode, response.body);
} else if(response.body != null) {
{{#isListContainer}}
{{#returnType}}
return (apiClient.deserialize(response.body, '{{{returnType}}}') as List).map((item) => item as {{returnBaseType}}).toList();
{{/returnType}}
{{/isListContainer}}
{{^isListContainer}}
{{#isMapContainer}}
{{#returnType}}
return new {{{returnType}}}.from(apiClient.deserialize(response.body, '{{{returnType}}}'));
{{/returnType}};
{{/isMapContainer}}
{{^isMapContainer}}
{{#returnType}}
return apiClient.deserialize(response.body, '{{{returnType}}}') as {{{returnType}}};
{{/returnType}}
{{/isMapContainer}}
{{/isListContainer}}
} else {
return{{#returnType}} null{{/returnType}};
}
}
{{/operation}}
}
{{/operations}}
Oops, something went wrong.

0 comments on commit d327c5b

Please sign in to comment.