From 89ad5e59b8d1ed7ec876a13f3db988a813ecff20 Mon Sep 17 00:00:00 2001 From: wing328 Date: Wed, 8 Mar 2017 17:39:22 +0800 Subject: [PATCH] use convertPropertyToBooleanAndWriteBack in some generators (#4975) --- bin/dart-petstore.sh | 2 +- .../swagger/codegen/languages/BashClientCodegen.java | 12 +++--------- .../swagger/codegen/languages/DartClientCodegen.java | 11 +++++++++-- .../io/swagger/codegen/languages/Swift3Codegen.java | 9 ++++++--- .../io/swagger/codegen/languages/SwiftCodegen.java | 10 ++++++---- samples/client/petstore/dart/swagger/README.md | 1 - 6 files changed, 25 insertions(+), 20 deletions(-) diff --git a/bin/dart-petstore.sh b/bin/dart-petstore.sh index bfb9e8179f0..466a27b657b 100755 --- a/bin/dart-petstore.sh +++ b/bin/dart-petstore.sh @@ -27,7 +27,7 @@ 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 -t modules/swagger-codegen/src/main/resources/dart -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l dart -o samples/client/petstore/dart/swagger" +ags="$@ generate -t modules/swagger-codegen/src/main/resources/dart -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l dart -o samples/client/petstore/dart/swagger -DhideGenerationTimestamp=true" # 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" diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/BashClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/BashClientCodegen.java index edd4f52bc71..eae094e6335 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/BashClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/BashClientCodegen.java @@ -201,21 +201,15 @@ public class BashClientCodegen extends DefaultCodegen implements CodegenConfig { } if (additionalProperties.containsKey(PROCESS_MARKDOWN)) { - setProcessMarkdown( - Boolean.parseBoolean( - additionalProperties.get(PROCESS_MARKDOWN).toString())); + setProcessMarkdown(convertPropertyToBooleanAndWriteBack(PROCESS_MARKDOWN)); } if (additionalProperties.containsKey(GENERATE_BASH_COMPLETION)) { - setGenerateBashCompletion( - Boolean.parseBoolean( - additionalProperties.get(GENERATE_BASH_COMPLETION).toString())); + setGenerateBashCompletion(convertPropertyToBooleanAndWriteBack(GENERATE_BASH_COMPLETION)); } if (additionalProperties.containsKey(GENERATE_ZSH_COMPLETION)) { - setGenerateZshCompletion( - Boolean.parseBoolean( - additionalProperties.get(GENERATE_ZSH_COMPLETION).toString())); + setGenerateZshCompletion(convertPropertyToBooleanAndWriteBack(GENERATE_ZSH_COMPLETION)); } if (additionalProperties.containsKey(SCRIPT_NAME)) { 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 d2a09a8ee3c..b85b1dd0151 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 @@ -117,8 +117,7 @@ public class DartClientCodegen extends DefaultCodegen implements CodegenConfig { super.processOpts(); if (additionalProperties.containsKey(BROWSER_CLIENT)) { - this.setBrowserClient(Boolean.parseBoolean((String) additionalProperties.get(BROWSER_CLIENT))); - additionalProperties.put(BROWSER_CLIENT, browserClient); + this.setBrowserClient(convertPropertyToBooleanAndWriteBack(BROWSER_CLIENT)); } else { //not set, use to be passed to template additionalProperties.put(BROWSER_CLIENT, browserClient); @@ -149,6 +148,14 @@ public class DartClientCodegen extends DefaultCodegen implements CodegenConfig { this.setSourceFolder((String) additionalProperties.get(CodegenConstants.SOURCE_FOLDER)); } + // default HIDE_GENERATION_TIMESTAMP to true + if (!additionalProperties.containsKey(CodegenConstants.HIDE_GENERATION_TIMESTAMP)) { + additionalProperties.put(CodegenConstants.HIDE_GENERATION_TIMESTAMP, Boolean.TRUE.toString()); + } else { + additionalProperties.put(CodegenConstants.HIDE_GENERATION_TIMESTAMP, + Boolean.valueOf(additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP).toString())); + } + // make api and model doc path available in mustache template additionalProperties.put("apiDocPath", apiDocPath); additionalProperties.put("modelDocPath", modelDocPath); diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/Swift3Codegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/Swift3Codegen.java index 626af3f8265..7c45302d43a 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/Swift3Codegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/Swift3Codegen.java @@ -185,7 +185,7 @@ public class Swift3Codegen extends DefaultCodegen implements CodegenConfig { // Setup unwrapRequired option, which makes all the properties with "required" non-optional if (additionalProperties.containsKey(UNWRAP_REQUIRED)) { - setUnwrapRequired(Boolean.parseBoolean(String.valueOf(additionalProperties.get(UNWRAP_REQUIRED)))); + setUnwrapRequired(convertPropertyToBooleanAndWriteBack(UNWRAP_REQUIRED)); } additionalProperties.put(UNWRAP_REQUIRED, unwrapRequired); @@ -208,9 +208,8 @@ public class Swift3Codegen extends DefaultCodegen implements CodegenConfig { // Setup swiftUseApiNamespace option, which makes all the API classes inner-class of {{projectName}}API if (additionalProperties.containsKey(SWIFT_USE_API_NAMESPACE)) { - swiftUseApiNamespace = Boolean.parseBoolean(String.valueOf(additionalProperties.get(SWIFT_USE_API_NAMESPACE))); + setSwiftUseApiNamespace(convertPropertyToBooleanAndWriteBack(SWIFT_USE_API_NAMESPACE)); } - additionalProperties.put(SWIFT_USE_API_NAMESPACE, swiftUseApiNamespace); if (!additionalProperties.containsKey(POD_AUTHORS)) { additionalProperties.put(POD_AUTHORS, DEFAULT_POD_AUTHORS); @@ -497,6 +496,10 @@ public class Swift3Codegen extends DefaultCodegen implements CodegenConfig { this.responseAs = responseAs; } + public void setSwiftUseApiNamespace(boolean swiftUseApiNamespace) { + this.swiftUseApiNamespace = swiftUseApiNamespace; + } + @Override public String toEnumValue(String value, String datatype) { return String.valueOf(value); diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/SwiftCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/SwiftCodegen.java index 01fce85c3db..1a12f287471 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/SwiftCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/SwiftCodegen.java @@ -184,9 +184,8 @@ public class SwiftCodegen extends DefaultCodegen implements CodegenConfig { // Setup unwrapRequired option, which makes all the properties with "required" non-optional if (additionalProperties.containsKey(UNWRAP_REQUIRED)) { - setUnwrapRequired(Boolean.parseBoolean(String.valueOf(additionalProperties.get(UNWRAP_REQUIRED)))); + setUnwrapRequired(convertPropertyToBooleanAndWriteBack(UNWRAP_REQUIRED)); } - additionalProperties.put(UNWRAP_REQUIRED, unwrapRequired); // Setup unwrapRequired option, which makes all the properties with "required" non-optional if (additionalProperties.containsKey(RESPONSE_AS)) { @@ -207,9 +206,8 @@ public class SwiftCodegen extends DefaultCodegen implements CodegenConfig { // Setup swiftUseApiNamespace option, which makes all the API classes inner-class of {{projectName}}API if (additionalProperties.containsKey(SWIFT_USE_API_NAMESPACE)) { - swiftUseApiNamespace = Boolean.parseBoolean(String.valueOf(additionalProperties.get(SWIFT_USE_API_NAMESPACE))); + setSwiftUseApiNamespace(convertPropertyToBooleanAndWriteBack(SWIFT_USE_API_NAMESPACE)); } - additionalProperties.put(SWIFT_USE_API_NAMESPACE, swiftUseApiNamespace); if (!additionalProperties.containsKey(POD_AUTHORS)) { additionalProperties.put(POD_AUTHORS, DEFAULT_POD_AUTHORS); @@ -531,6 +529,10 @@ public class SwiftCodegen extends DefaultCodegen implements CodegenConfig { this.responseAs = responseAs; } + public void setSwiftUseApiNamespace(boolean swiftUseApiNamespace) { + this.swiftUseApiNamespace = swiftUseApiNamespace; + } + @Override public String toEnumValue(String value, String datatype) { if ("int".equals(datatype) || "double".equals(datatype) || "float".equals(datatype)) { diff --git a/samples/client/petstore/dart/swagger/README.md b/samples/client/petstore/dart/swagger/README.md index 6998182066d..4ac75e49d78 100644 --- a/samples/client/petstore/dart/swagger/README.md +++ b/samples/client/petstore/dart/swagger/README.md @@ -4,7 +4,6 @@ This is a sample server Petstore server. You can find out more about Swagger at This Dart package is automatically generated by the [Swagger Codegen](https://github.com/swagger-api/swagger-codegen) project: - API version: 1.0.0 -- Build date: 2017-03-02T21:05:05.222+01:00 - Build package: io.swagger.codegen.languages.DartClientCodegen ## Requirements