Permalink
Browse files

Dart (Jaguar) client generator (#998)

* generator for dart jaguar

* migrate to openapi-generator

* fix locale issue

* add auth generation for dart jaguar

* fix generation of jaguar api with auth (#1009)

* update deps (#1016)

* add CI tests for dart jaguar

* update dart jaguar bin script

* trigger build failure

* Revert "trigger build failure"

This reverts commit a7d8bfd.
  • Loading branch information...
wing328 committed Sep 13, 2018
1 parent 9a19a06 commit 29322da2f6192006c1db7646c84ab528f1cd2efb
Showing with 20,104 additions and 4 deletions.
  1. +42 −0 bin/dart-jaguar-petstore.sh
  2. +12 −0 bin/windows/dart-client-petstore.bat
  3. +217 −0 ...s/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartJaguarClientCodegen.java
  4. +1 −0 ...les/openapi-generator/src/main/resources/META-INF/services/org.openapitools.codegen.CodegenConfig
  5. +142 −0 modules/openapi-generator/src/main/resources/dart-jaguar/README.mustache
  6. +2 −0 modules/openapi-generator/src/main/resources/dart-jaguar/analysis_options.mustache
  7. +53 −0 modules/openapi-generator/src/main/resources/dart-jaguar/api.mustache
  8. +86 −0 modules/openapi-generator/src/main/resources/dart-jaguar/api_doc.mustache
  9. +75 −0 modules/openapi-generator/src/main/resources/dart-jaguar/apilib.mustache
  10. +33 −0 modules/openapi-generator/src/main/resources/dart-jaguar/auth/api_key_auth.mustache
  11. +23 −0 modules/openapi-generator/src/main/resources/dart-jaguar/auth/auth.mustache
  12. +34 −0 modules/openapi-generator/src/main/resources/dart-jaguar/auth/basic_auth.mustache
  13. +25 −0 modules/openapi-generator/src/main/resources/dart-jaguar/auth/oauth.mustache
  14. +26 −0 modules/openapi-generator/src/main/resources/dart-jaguar/class.mustache
  15. +38 −0 modules/openapi-generator/src/main/resources/dart-jaguar/enum.mustache
  16. +52 −0 modules/openapi-generator/src/main/resources/dart-jaguar/git_push.sh.mustache
  17. +27 −0 modules/openapi-generator/src/main/resources/dart-jaguar/gitignore.mustache
  18. +9 −0 modules/openapi-generator/src/main/resources/dart-jaguar/model.mustache
  19. +16 −0 modules/openapi-generator/src/main/resources/dart-jaguar/object_doc.mustache
  20. +12 −0 modules/openapi-generator/src/main/resources/dart-jaguar/pubspec.mustache
  21. +2 −0 pom.xml
  22. +10 −0 samples/client/petstore/dart-jaguar/flutter_petstore/.gitignore
  23. +8 −0 samples/client/petstore/dart-jaguar/flutter_petstore/.metadata
  24. +8 −0 samples/client/petstore/dart-jaguar/flutter_petstore/README.md
  25. +9 −0 samples/client/petstore/dart-jaguar/flutter_petstore/android/.gitignore
  26. +52 −0 samples/client/petstore/dart-jaguar/flutter_petstore/android/app/build.gradle
  27. +39 −0 samples/client/petstore/dart-jaguar/flutter_petstore/android/app/src/main/AndroidManifest.xml
  28. +14 −0 ...guar/flutter_petstore/android/app/src/main/java/com/yourcompany/flutterpetstore/MainActivity.java
  29. +12 −0 ...ent/petstore/dart-jaguar/flutter_petstore/android/app/src/main/res/drawable/launch_background.xml
  30. BIN ...client/petstore/dart-jaguar/flutter_petstore/android/app/src/main/res/mipmap-hdpi/ic_launcher.png
  31. BIN ...client/petstore/dart-jaguar/flutter_petstore/android/app/src/main/res/mipmap-mdpi/ic_launcher.png
  32. BIN ...lient/petstore/dart-jaguar/flutter_petstore/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png
  33. BIN ...ient/petstore/dart-jaguar/flutter_petstore/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
  34. BIN ...ent/petstore/dart-jaguar/flutter_petstore/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
  35. +8 −0 samples/client/petstore/dart-jaguar/flutter_petstore/android/app/src/main/res/values/styles.xml
  36. +31 −0 samples/client/petstore/dart-jaguar/flutter_petstore/android/build.gradle
  37. +1 −0 samples/client/petstore/dart-jaguar/flutter_petstore/android/gradle.properties
  38. BIN samples/client/petstore/dart-jaguar/flutter_petstore/android/gradle/wrapper/gradle-wrapper.jar
  39. +6 −0 ...les/client/petstore/dart-jaguar/flutter_petstore/android/gradle/wrapper/gradle-wrapper.properties
  40. +160 −0 samples/client/petstore/dart-jaguar/flutter_petstore/android/gradlew
  41. +90 −0 samples/client/petstore/dart-jaguar/flutter_petstore/android/gradlew.bat
  42. +15 −0 samples/client/petstore/dart-jaguar/flutter_petstore/android/settings.gradle
  43. +41 −0 samples/client/petstore/dart-jaguar/flutter_petstore/ios/.gitignore
  44. +30 −0 samples/client/petstore/dart-jaguar/flutter_petstore/ios/Flutter/AppFrameworkInfo.plist
  45. +1 −0 samples/client/petstore/dart-jaguar/flutter_petstore/ios/Flutter/Debug.xcconfig
  46. +1 −0 samples/client/petstore/dart-jaguar/flutter_petstore/ios/Flutter/Release.xcconfig
  47. +1 −0 samples/client/petstore/dart-jaguar/flutter_petstore/ios/Flutter/flutter_assets/AssetManifest.json
  48. +1 −0 samples/client/petstore/dart-jaguar/flutter_petstore/ios/Flutter/flutter_assets/FontManifest.json
  49. +12,514 −0 samples/client/petstore/dart-jaguar/flutter_petstore/ios/Flutter/flutter_assets/LICENSE
  50. BIN .../petstore/dart-jaguar/flutter_petstore/ios/Flutter/flutter_assets/fonts/MaterialIcons-Regular.ttf
  51. BIN ...les/client/petstore/dart-jaguar/flutter_petstore/ios/Flutter/flutter_assets/isolate_snapshot_data
  52. BIN samples/client/petstore/dart-jaguar/flutter_petstore/ios/Flutter/flutter_assets/kernel_blob.bin
  53. BIN samples/client/petstore/dart-jaguar/flutter_petstore/ios/Flutter/flutter_assets/platform_strong.dill
  54. BIN samples/client/petstore/dart-jaguar/flutter_petstore/ios/Flutter/flutter_assets/vm_snapshot_data
  55. +436 −0 samples/client/petstore/dart-jaguar/flutter_petstore/ios/Runner.xcodeproj/project.pbxproj
  56. +7 −0 ...re/dart-jaguar/flutter_petstore/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata
  57. +93 −0 ...petstore/dart-jaguar/flutter_petstore/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme
  58. +7 −0 samples/client/petstore/dart-jaguar/flutter_petstore/ios/Runner.xcworkspace/contents.xcworkspacedata
  59. +6 −0 samples/client/petstore/dart-jaguar/flutter_petstore/ios/Runner/AppDelegate.h
  60. +12 −0 samples/client/petstore/dart-jaguar/flutter_petstore/ios/Runner/AppDelegate.m
  61. +116 −0 ...petstore/dart-jaguar/flutter_petstore/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json
  62. BIN .../dart-jaguar/flutter_petstore/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png
  63. BIN .../dart-jaguar/flutter_petstore/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png
  64. BIN .../dart-jaguar/flutter_petstore/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png
  65. BIN .../dart-jaguar/flutter_petstore/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png
  66. BIN .../dart-jaguar/flutter_petstore/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png
  67. BIN .../dart-jaguar/flutter_petstore/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png
  68. BIN .../dart-jaguar/flutter_petstore/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png
  69. BIN .../dart-jaguar/flutter_petstore/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png
  70. BIN .../dart-jaguar/flutter_petstore/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png
  71. BIN .../dart-jaguar/flutter_petstore/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png
  72. BIN .../dart-jaguar/flutter_petstore/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png
  73. BIN .../dart-jaguar/flutter_petstore/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png
  74. BIN .../dart-jaguar/flutter_petstore/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png
  75. BIN ...t-jaguar/flutter_petstore/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png
  76. +23 −0 ...tstore/dart-jaguar/flutter_petstore/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json
  77. BIN ...tore/dart-jaguar/flutter_petstore/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png
  78. BIN ...e/dart-jaguar/flutter_petstore/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png
  79. BIN ...e/dart-jaguar/flutter_petstore/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png
  80. +5 −0 ...t/petstore/dart-jaguar/flutter_petstore/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md
  81. +37 −0 samples/client/petstore/dart-jaguar/flutter_petstore/ios/Runner/Base.lproj/LaunchScreen.storyboard
  82. +26 −0 samples/client/petstore/dart-jaguar/flutter_petstore/ios/Runner/Base.lproj/Main.storyboard
  83. +49 −0 samples/client/petstore/dart-jaguar/flutter_petstore/ios/Runner/Info.plist
  84. +9 −0 samples/client/petstore/dart-jaguar/flutter_petstore/ios/Runner/main.m
  85. +172 −0 samples/client/petstore/dart-jaguar/flutter_petstore/lib/main.dart
  86. +2 −0 samples/client/petstore/dart-jaguar/flutter_petstore/openapi/.analysis_options
  87. +27 −0 samples/client/petstore/dart-jaguar/flutter_petstore/openapi/.gitignore
  88. +23 −0 samples/client/petstore/dart-jaguar/flutter_petstore/openapi/.openapi-generator-ignore
  89. +1 −0 samples/client/petstore/dart-jaguar/flutter_petstore/openapi/.openapi-generator/VERSION
  90. +131 −0 samples/client/petstore/dart-jaguar/flutter_petstore/openapi/README.md
  91. +2 −0 samples/client/petstore/dart-jaguar/flutter_petstore/openapi/analysis_options.yaml
  92. +17 −0 samples/client/petstore/dart-jaguar/flutter_petstore/openapi/docs/ApiResponse.md
  93. +16 −0 samples/client/petstore/dart-jaguar/flutter_petstore/openapi/docs/Category.md
  94. +20 −0 samples/client/petstore/dart-jaguar/flutter_petstore/openapi/docs/Order.md
  95. +20 −0 samples/client/petstore/dart-jaguar/flutter_petstore/openapi/docs/Pet.md
  96. +379 −0 samples/client/petstore/dart-jaguar/flutter_petstore/openapi/docs/PetApi.md
  97. +186 −0 samples/client/petstore/dart-jaguar/flutter_petstore/openapi/docs/StoreApi.md
  98. +16 −0 samples/client/petstore/dart-jaguar/flutter_petstore/openapi/docs/Tag.md
  99. +22 −0 samples/client/petstore/dart-jaguar/flutter_petstore/openapi/docs/User.md
  100. +349 −0 samples/client/petstore/dart-jaguar/flutter_petstore/openapi/docs/UserApi.md
  101. +52 −0 samples/client/petstore/dart-jaguar/flutter_petstore/openapi/git_push.sh
  102. +117 −0 samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/api.dart
  103. +99 −0 samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/api/pet_api.dart
  104. +146 −0 samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/api/pet_api.jretro.dart
  105. +52 −0 samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/api/store_api.dart
  106. +51 −0 samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/api/store_api.jretro.dart
  107. +91 −0 samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/api/user_api.dart
  108. +70 −0 samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/api/user_api.jretro.dart
  109. +33 −0 samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/auth/api_key_auth.dart
  110. +23 −0 samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/auth/auth.dart
  111. +34 −0 samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/auth/basic_auth.dart
  112. +25 −0 samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/auth/oauth.dart
  113. +34 −0 samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/api_response.dart
  114. +29 −0 samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/api_response.jser.dart
  115. +31 −0 samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/category.dart
  116. +27 −0 samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/category.jser.dart
  117. +43 −0 samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/order.dart
  118. +37 −0 samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/order.jser.dart
  119. +45 −0 samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/pet.dart
  120. +47 −0 samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/pet.jser.dart
  121. +31 −0 samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/tag.dart
  122. +27 −0 samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/tag.jser.dart
  123. +49 −0 samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/user.dart
  124. +39 −0 samples/client/petstore/dart-jaguar/flutter_petstore/openapi/lib/model/user.jser.dart
  125. +62 −0 samples/client/petstore/dart-jaguar/flutter_petstore/openapi/pom.xml
  126. +12 −0 samples/client/petstore/dart-jaguar/flutter_petstore/openapi/pubspec.yaml
  127. +59 −0 samples/client/petstore/dart-jaguar/flutter_petstore/pubspec.yaml
  128. +29 −0 samples/client/petstore/dart-jaguar/flutter_petstore/test/widget_test.dart
  129. +2 −0 samples/client/petstore/dart-jaguar/openapi/.analysis_options
  130. +27 −0 samples/client/petstore/dart-jaguar/openapi/.gitignore
  131. +23 −0 samples/client/petstore/dart-jaguar/openapi/.openapi-generator-ignore
  132. +1 −0 samples/client/petstore/dart-jaguar/openapi/.openapi-generator/VERSION
  133. +131 −0 samples/client/petstore/dart-jaguar/openapi/README.md
  134. +2 −0 samples/client/petstore/dart-jaguar/openapi/analysis_options.yaml
  135. +17 −0 samples/client/petstore/dart-jaguar/openapi/docs/ApiResponse.md
  136. +16 −0 samples/client/petstore/dart-jaguar/openapi/docs/Category.md
  137. +20 −0 samples/client/petstore/dart-jaguar/openapi/docs/Order.md
  138. +20 −0 samples/client/petstore/dart-jaguar/openapi/docs/Pet.md
  139. +379 −0 samples/client/petstore/dart-jaguar/openapi/docs/PetApi.md
  140. +186 −0 samples/client/petstore/dart-jaguar/openapi/docs/StoreApi.md
  141. +16 −0 samples/client/petstore/dart-jaguar/openapi/docs/Tag.md
  142. +22 −0 samples/client/petstore/dart-jaguar/openapi/docs/User.md
  143. +349 −0 samples/client/petstore/dart-jaguar/openapi/docs/UserApi.md
  144. +52 −0 samples/client/petstore/dart-jaguar/openapi/git_push.sh
  145. +117 −0 samples/client/petstore/dart-jaguar/openapi/lib/api.dart
  146. +99 −0 samples/client/petstore/dart-jaguar/openapi/lib/api/pet_api.dart
  147. +146 −0 samples/client/petstore/dart-jaguar/openapi/lib/api/pet_api.jretro.dart
  148. +52 −0 samples/client/petstore/dart-jaguar/openapi/lib/api/store_api.dart
  149. +51 −0 samples/client/petstore/dart-jaguar/openapi/lib/api/store_api.jretro.dart
  150. +91 −0 samples/client/petstore/dart-jaguar/openapi/lib/api/user_api.dart
  151. +70 −0 samples/client/petstore/dart-jaguar/openapi/lib/api/user_api.jretro.dart
  152. +33 −0 samples/client/petstore/dart-jaguar/openapi/lib/auth/api_key_auth.dart
  153. +23 −0 samples/client/petstore/dart-jaguar/openapi/lib/auth/auth.dart
  154. +34 −0 samples/client/petstore/dart-jaguar/openapi/lib/auth/basic_auth.dart
  155. +25 −0 samples/client/petstore/dart-jaguar/openapi/lib/auth/oauth.dart
  156. +34 −0 samples/client/petstore/dart-jaguar/openapi/lib/model/api_response.dart
  157. +29 −0 samples/client/petstore/dart-jaguar/openapi/lib/model/api_response.jser.dart
  158. +31 −0 samples/client/petstore/dart-jaguar/openapi/lib/model/category.dart
  159. +27 −0 samples/client/petstore/dart-jaguar/openapi/lib/model/category.jser.dart
  160. +43 −0 samples/client/petstore/dart-jaguar/openapi/lib/model/order.dart
  161. +37 −0 samples/client/petstore/dart-jaguar/openapi/lib/model/order.jser.dart
  162. +45 −0 samples/client/petstore/dart-jaguar/openapi/lib/model/pet.dart
  163. +47 −0 samples/client/petstore/dart-jaguar/openapi/lib/model/pet.jser.dart
  164. +31 −0 samples/client/petstore/dart-jaguar/openapi/lib/model/tag.dart
  165. +27 −0 samples/client/petstore/dart-jaguar/openapi/lib/model/tag.jser.dart
  166. +49 −0 samples/client/petstore/dart-jaguar/openapi/lib/model/user.dart
  167. +39 −0 samples/client/petstore/dart-jaguar/openapi/lib/model/user.jser.dart
  168. +62 −0 samples/client/petstore/dart-jaguar/openapi/pom.xml
  169. +12 −0 samples/client/petstore/dart-jaguar/openapi/pubspec.yaml
  170. +4 −4 samples/client/petstore/dart/flutter_petstore/ios/Runner.xcodeproj/project.pbxproj
  171. +1 −0 samples/client/petstore/dart/flutter_petstore/pubspec.yaml
@@ -0,0 +1,42 @@
#!/bin/sh
SCRIPT="$0"
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 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 client
ags="$@ generate -t modules/openapi-generator/src/main/resources/dart-jaguar -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -l dart-jaguar -o samples/client/petstore/dart-jaguar/openapi -DhideGenerationTimestamp=true -DpubName=openapi"
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-jaguar -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -l dart-jaguar -o samples/client/petstore/dart-jaguar/flutter_petstore/openapi -DhideGenerationTimestamp=true -DpubName=openapi"
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.
@@ -0,0 +1,12 @@
set executable=.\modules\swagger-codegen-cli\target\swagger-codegen-cli.jar
If Not Exist %executable% (
mvn clean package
)
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M -DloggerPath=conf/log4j.properties
set ags=generate -i modules\swagger-codegen\src\test\resources\2_0\petstore.yaml -l dart-jaguar -o samples\client\petstore\dart-jaguar\swagger -DhideGenerationTimestamp=true -DbrowserClient=false
java %JAVA_OPTS% -jar %executable% %ags%
set ags=generate -i modules\swagger-codegen\src\test\resources\2_0\petstore.yaml -l dart-jaguar -o samples\client\petstore\dart-jaguar\flutter_petstore\swagger -DhideGenerationTimestamp=true
java %JAVA_OPTS% -jar %executable% %ags%
@@ -0,0 +1,217 @@
/*
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
*
* 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.
*/
package org.openapitools.codegen.languages;
import com.samskivert.mustache.Mustache;
import com.samskivert.mustache.Template;
import io.swagger.models.Model;
import org.openapitools.codegen.CliOption;
import org.openapitools.codegen.CodegenConfig;
import org.openapitools.codegen.CodegenConstants;
import org.openapitools.codegen.CodegenModel;
import org.openapitools.codegen.CodegenOperation;
import org.openapitools.codegen.CodegenProperty;
import org.openapitools.codegen.CodegenType;
import org.openapitools.codegen.DefaultCodegen;
import org.openapitools.codegen.SupportingFile;
import org.openapitools.codegen.utils.ModelUtils;
import io.swagger.v3.oas.models.media.*;
import org.apache.commons.lang3.StringUtils;
import java.io.File;
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
public class DartJaguarClientCodegen extends DartClientCodegen {
private static Set<String> modelToIgnore = new HashSet<>();
static {
modelToIgnore.add("datetime");
modelToIgnore.add("list");
modelToIgnore.add("map");
modelToIgnore.add("file");
}
public DartJaguarClientCodegen() {
super();
browserClient = false;
outputFolder = "generated-code/dart-jaguar";
embeddedTemplateDir = templateDir = "dart-jaguar";
}
@Override
public String getName() {
return "dart-jaguar";
}
@Override
public String getHelp() {
return "Generates a Dart Jaguar client library.";
}
@Override
public String toDefaultValue(Schema p) {
if (ModelUtils.isMapSchema(p)) {
return "const {}";
} else if (ModelUtils.isArraySchema(p)) {
return "const []";
}
return super.toDefaultValue(p);
}
@Override
public void processOpts() {
if (additionalProperties.containsKey(PUB_NAME)) {
this.setPubName((String) additionalProperties.get(PUB_NAME));
} else {
//not set, use to be passed to template
additionalProperties.put(PUB_NAME, pubName);
}
if (additionalProperties.containsKey(PUB_VERSION)) {
this.setPubVersion((String) additionalProperties.get(PUB_VERSION));
} else {
//not set, use to be passed to template
additionalProperties.put(PUB_VERSION, pubVersion);
}
if (additionalProperties.containsKey(PUB_DESCRIPTION)) {
this.setPubDescription((String) additionalProperties.get(PUB_DESCRIPTION));
} else {
//not set, use to be passed to template
additionalProperties.put(PUB_DESCRIPTION, pubDescription);
}
if (additionalProperties.containsKey(USE_ENUM_EXTENSION)) {
this.setUseEnumExtension(convertPropertyToBooleanAndWriteBack(USE_ENUM_EXTENSION));
} else {
// Not set, use to be passed to template.
additionalProperties.put(USE_ENUM_EXTENSION, useEnumExtension);
}
if (additionalProperties.containsKey(CodegenConstants.SOURCE_FOLDER)) {
this.setSourceFolder((String) additionalProperties.get(CodegenConstants.SOURCE_FOLDER));
}
// make api and model doc path available in mustache template
additionalProperties.put("apiDocPath", apiDocPath);
additionalProperties.put("modelDocPath", modelDocPath);
final String libFolder = sourceFolder + File.separator + "lib";
supportingFiles.add(new SupportingFile("pubspec.mustache", "", "pubspec.yaml"));
supportingFiles.add(new SupportingFile("analysis_options.mustache", "", "analysis_options.yaml"));
supportingFiles.add(new SupportingFile("apilib.mustache", libFolder, "api.dart"));
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
final String authFolder = sourceFolder + File.separator + "lib" + File.separator + "auth";
supportingFiles.add(new SupportingFile("auth/api_key_auth.mustache", authFolder, "api_key_auth.dart"));
supportingFiles.add(new SupportingFile("auth/basic_auth.mustache", authFolder, "basic_auth.dart"));
supportingFiles.add(new SupportingFile("auth/oauth.mustache", authFolder, "oauth.dart"));
supportingFiles.add(new SupportingFile("auth/auth.mustache", authFolder, "auth.dart"));
}
@Override
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
objs = super.postProcessModels(objs);
List<Object> models = (List<Object>) objs.get("models");
for (Object _mo : models) {
Map<String, Object> mo = (Map<String, Object>) _mo;
Set<String> modelImports = new HashSet<>();
CodegenModel cm = (CodegenModel) mo.get("model");
for (String modelImport : cm.imports) {
if(!modelToIgnore.contains(modelImport.toLowerCase(Locale.ROOT))) {
modelImports.add(underscore(modelImport));
}
}
cm.imports = modelImports;
cm.vendorExtensions.put("hasVars", cm.vars.size() > 0);
}
//objs.put("modelImports", modelImports);
return objs;
}
@Override
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
objs = super.postProcessOperations(objs);
Map<String, Object> operations = (Map<String, Object>) objs.get("operations");
List<CodegenOperation> operationList = (List<CodegenOperation>) operations.get("operation");
Set<String> modelImports = new HashSet<>();
for (CodegenOperation op : operationList) {
op.httpMethod = StringUtils.capitalize(op.httpMethod.toLowerCase(Locale.ROOT));
boolean isJson = true; //default to JSON
boolean isForm = false;
boolean isMultipart = false;
if(op.consumes != null) {
for (Map<String, String> consume : op.consumes) {
if (consume.containsKey("mediaType")) {
String type = consume.get("mediaType");
isJson = type.equalsIgnoreCase("application/json");
isForm = type.equalsIgnoreCase("application/x-www-form-urlencoded");
isMultipart = type.equalsIgnoreCase("multipart/form-data");
break;
}
}
}
op.vendorExtensions.put("isJson", isJson);
op.vendorExtensions.put("isForm", isForm);
op.vendorExtensions.put("isMultipart", isMultipart);
Set<String> imports = new HashSet<>();
for (String item : op.imports) {
if(!modelToIgnore.contains(item.toLowerCase(Locale.ROOT))) {
imports.add(underscore(item));
}
}
modelImports.addAll(imports);
op.imports = imports;
String[] items = op.path.split("/", -1);
String jaguarPath = "";
for (int i = 0; i < items.length; ++i) {
if (items[i].matches("^\\{(.*)\\}$")) { // wrap in {}
jaguarPath = jaguarPath + ":" + items[i].replace("{", "").replace("}", "");
} else {
jaguarPath = jaguarPath + items[i];
}
if (i != items.length -1) {
jaguarPath = jaguarPath + "/";
}
}
op.path = jaguarPath;
}
objs.put("modelImports", modelImports);
return objs;
}
}
@@ -17,6 +17,7 @@ org.openapitools.codegen.languages.CSharpClientCodegen
org.openapitools.codegen.languages.CSharpDotNet2ClientCodegen
org.openapitools.codegen.languages.CSharpNancyFXServerCodegen
org.openapitools.codegen.languages.DartClientCodegen
org.openapitools.codegen.languages.DartJaguarClientCodegen
org.openapitools.codegen.languages.EiffelClientCodegen
org.openapitools.codegen.languages.ElixirClientCodegen
org.openapitools.codegen.languages.ElmClientCodegen
Oops, something went wrong.

0 comments on commit 29322da

Please sign in to comment.