diff --git a/appveyor.yml b/appveyor.yml index c0feaeaa5052..d3c02aa19f1e 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -50,7 +50,7 @@ build_script: # install openapi-generator locally - mvn --no-snapshot-updates --quiet clean install -Dorg.slf4j.simpleLogger.defaultLogLevel=error # run the locally installed openapi-generator-gradle-plugin - - gradle -b modules\openapi-generator-gradle-plugin\samples\local-spec\build.gradle buildGoSdk --info + - gradle -b modules\openapi-generator-gradle-plugin\samples\local-spec\build.gradle buildGoSdk --stacktrace test_script: # restore test-related files - copy /b/v/y CI\samples.ci\client\petstore\csharp\OpenAPIClient\src\Org.OpenAPITools.Test\Org.OpenAPITools.Test.csproj samples\client\petstore\csharp\OpenAPIClient\src\Org.OpenAPITools.Test\Org.OpenAPITools.Test.csproj diff --git a/bin/ci/java-feign.json b/bin/ci/java-feign.json index 3e2d314e4d51..8d2c23fa7ea4 100644 --- a/bin/ci/java-feign.json +++ b/bin/ci/java-feign.json @@ -3,7 +3,7 @@ "generatorName": "java", "inputSpec": "modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml", "outputDir": "samples/client/petstore/java/feign", - "templateDir": "modules/openapi-generator/src/main/resources/Java/libraries/feign", + "templateDir": "modules/openapi-generator/src/main/resources/Java", "additionalProperties": { "hideGenerationTimestamp": true, "booleanGetterPrefix": "is", diff --git a/bin/ci/java-feign10x.json b/bin/ci/java-feign10x.json index 77262b06219d..50574a954232 100644 --- a/bin/ci/java-feign10x.json +++ b/bin/ci/java-feign10x.json @@ -3,7 +3,7 @@ "generatorName": "java", "inputSpec": "modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml", "outputDir": "samples/client/petstore/java/feign10x", - "templateDir": "modules/openapi-generator/src/main/resources/Java/libraries/feign", + "templateDir": "modules/openapi-generator/src/main/resources/Java", "additionalProperties": { "hideGenerationTimestamp": true, "booleanGetterPrefix": "is" diff --git a/bin/ci/java-google-api-client.json b/bin/ci/java-google-api-client.json index 1a447f387fec..e30057f3c914 100644 --- a/bin/ci/java-google-api-client.json +++ b/bin/ci/java-google-api-client.json @@ -3,7 +3,7 @@ "generatorName": "java", "inputSpec": "modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml", "outputDir": "samples/client/petstore/java/google-api-client", - "templateDir": "modules/openapi-generator/src/main/resources/Java/libraries/google-api-client", + "templateDir": "modules/openapi-generator/src/main/resources/Java", "additionalProperties": { "hideGenerationTimestamp": true } diff --git a/bin/ci/java-native.json b/bin/ci/java-native.json index 99506422cfa3..7d8c792e5bc7 100644 --- a/bin/ci/java-native.json +++ b/bin/ci/java-native.json @@ -3,7 +3,7 @@ "generatorName": "java", "inputSpec": "modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml", "outputDir": "samples/client/petstore/java/native", - "templateDir": "modules/openapi-generator/src/main/resources/Java/libraries/native", + "templateDir": "modules/openapi-generator/src/main/resources/Java", "additionalProperties": { "hideGenerationTimestamp": true } diff --git a/bin/ci/java-okhttp-gson-parcelableModel.json b/bin/ci/java-okhttp-gson-parcelableModel.json index 31b5cd136e9d..332fa46a24f0 100644 --- a/bin/ci/java-okhttp-gson-parcelableModel.json +++ b/bin/ci/java-okhttp-gson-parcelableModel.json @@ -4,7 +4,7 @@ "generatorName": "java", "inputSpec": "modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml", "outputDir": "samples/client/petstore/java/okhttp-gson-parcelableModel", - "templateDir": "modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson", + "templateDir": "modules/openapi-generator/src/main/resources/Java", "additionalProperties": { "hideGenerationTimestamp": true, "parcelableModel": true diff --git a/bin/ci/java-okhttp-gson.json b/bin/ci/java-okhttp-gson.json index 78ca97e598dc..cdba0e712874 100644 --- a/bin/ci/java-okhttp-gson.json +++ b/bin/ci/java-okhttp-gson.json @@ -3,7 +3,7 @@ "generatorName": "java", "inputSpec": "modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml", "outputDir": "samples/client/petstore/java/okhttp-gson", - "templateDir": "modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson", + "templateDir": "modules/openapi-generator/src/main/resources/Java", "additionalProperties": { "hideGenerationTimestamp": true } diff --git a/bin/ci/java-petstore-feign-10x.json b/bin/ci/java-petstore-feign-10x.json index 186e64fc9e35..50994004159b 100644 --- a/bin/ci/java-petstore-feign-10x.json +++ b/bin/ci/java-petstore-feign-10x.json @@ -1,7 +1,7 @@ { "generatorName": "java", "inputSpec": "modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml", - "templateDir": "modules/openapi-generator/src/main/resources/Java/libraries/feign", + "templateDir": "modules/openapi-generator/src/main/resources/Java", "outputDir": "samples/client/petstore/java/feign10x", "additionalProperties": { "hideGenerationTimestamp": true, diff --git a/bin/ci/java-rest-assured-jackson.json b/bin/ci/java-rest-assured-jackson.json index 1ff56d80ea83..c652a9bf7a2d 100644 --- a/bin/ci/java-rest-assured-jackson.json +++ b/bin/ci/java-rest-assured-jackson.json @@ -3,7 +3,7 @@ "generatorName": "java", "inputSpec": "modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml", "outputDir": "samples/client/petstore/java/rest-assured-jackson", - "templateDir": "modules/openapi-generator/src/main/resources/Java/libraries/rest-assured", + "templateDir": "modules/openapi-generator/src/main/resources/Java", "additionalProperties": { "hideGenerationTimestamp": true, "booleanGetterPrefix": "is", diff --git a/bin/ci/java-rest-assured.json b/bin/ci/java-rest-assured.json index 19119b115c75..c1328500ad3f 100644 --- a/bin/ci/java-rest-assured.json +++ b/bin/ci/java-rest-assured.json @@ -3,7 +3,7 @@ "generatorName": "java", "inputSpec": "modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml", "outputDir": "samples/client/petstore/java/rest-assured", - "templateDir": "modules/openapi-generator/src/main/resources/Java/libraries/rest-assured", + "templateDir": "modules/openapi-generator/src/main/resources/Java", "additionalProperties": { "hideGenerationTimestamp": true, "booleanGetterPrefix": "is" diff --git a/bin/ci/java-retrofit2.json b/bin/ci/java-retrofit2.json index 2b3d251241ac..8f2c2a8fba19 100644 --- a/bin/ci/java-retrofit2.json +++ b/bin/ci/java-retrofit2.json @@ -3,7 +3,7 @@ "generatorName": "java", "inputSpec": "modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml", "outputDir": "samples/client/petstore/java/retrofit2", - "templateDir": "modules/openapi-generator/src/main/resources/Java/libraries/retrofit2", + "templateDir": "modules/openapi-generator/src/main/resources/Java", "additionalProperties": { "hideGenerationTimestamp": true } diff --git a/bin/ci/java-retrofit2rx.json b/bin/ci/java-retrofit2rx.json index 3479b1d08b03..35ca3ab5831c 100644 --- a/bin/ci/java-retrofit2rx.json +++ b/bin/ci/java-retrofit2rx.json @@ -3,7 +3,7 @@ "generatorName": "java", "inputSpec": "modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml", "outputDir": "samples/client/petstore/java/retrofit2rx", - "templateDir": "modules/openapi-generator/src/main/resources/Java/libraries/retrofit2", + "templateDir": "modules/openapi-generator/src/main/resources/Java", "additionalProperties": { "useRxJava": true, "hideGenerationTimestamp": true diff --git a/bin/ci/java-retrofit2rx2.json b/bin/ci/java-retrofit2rx2.json index c3a6d8416839..ce0d7d89d4c7 100644 --- a/bin/ci/java-retrofit2rx2.json +++ b/bin/ci/java-retrofit2rx2.json @@ -3,7 +3,7 @@ "generatorName": "java", "inputSpec": "modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml", "outputDir": "samples/client/petstore/java/retrofit2rx2", - "templateDir": "modules/openapi-generator/src/main/resources/Java/libraries/retrofit2", + "templateDir": "modules/openapi-generator/src/main/resources/Java", "additionalProperties": { "useRxJava2": true, "hideGenerationTimestamp": true diff --git a/bin/ci/java-vertx.json b/bin/ci/java-vertx.json index 0e6bf3edd75b..2eb162e1c375 100644 --- a/bin/ci/java-vertx.json +++ b/bin/ci/java-vertx.json @@ -3,7 +3,7 @@ "generatorName": "java", "inputSpec": "modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml", "outputDir": "samples/client/petstore/java/vertx", - "templateDir": "modules/openapi-generator/src/main/resources/Java/libraries/vertx", + "templateDir": "modules/openapi-generator/src/main/resources/Java", "additionalProperties": { "hideGenerationTimestamp": true } diff --git a/bin/java-petstore-feign-10x.sh b/bin/java-petstore-feign-10x.sh index 15b1b40e2149..3a98ad061bb1 100755 --- a/bin/java-petstore-feign-10x.sh +++ b/bin/java-petstore-feign-10x.sh @@ -27,7 +27,7 @@ fi # if you've executed sbt assembly previously it will use that instead. export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties" -ags="generate -t modules/openapi-generator/src/main/resources/Java/libraries/feign -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin/java-petstore-feign-10x.json -o samples/client/petstore/java/feign10x --additional-properties hideGenerationTimestamp=true,booleanGetterPrefix=is $@" +ags="generate -t modules/openapi-generator/src/main/resources/Java -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin/java-petstore-feign-10x.json -o samples/client/petstore/java/feign10x --additional-properties hideGenerationTimestamp=true,booleanGetterPrefix=is $@" echo "Removing files and folders under samples/client/petstore/java/feign10x/src/main" rm -rf samples/client/petstore/java/feign10x/src/main diff --git a/bin/java-petstore-google-api-client.sh b/bin/java-petstore-google-api-client.sh index 20e3577f1974..866e8d401061 100755 --- a/bin/java-petstore-google-api-client.sh +++ b/bin/java-petstore-google-api-client.sh @@ -27,7 +27,7 @@ fi # if you've executed sbt assembly previously it will use that instead. export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties" -ags="generate -t modules/openapi-generator/src/main/resources/Java/libraries/google-api-client -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin/java-petstore-google-api-client.json -o samples/client/petstore/java/google-api-client --additional-properties hideGenerationTimestamp=true $@" +ags="generate -t modules/openapi-generator/src/main/resources/Java -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin/java-petstore-google-api-client.json -o samples/client/petstore/java/google-api-client --additional-properties hideGenerationTimestamp=true $@" echo "Removing files and folders under samples/client/petstore/java/google-api-client/src/main" rm -rf samples/client/petstore/java/google-api-client/src/main diff --git a/bin/java-petstore-native-async.sh b/bin/java-petstore-native-async.sh index d163250beb6d..1782614d9eea 100755 --- a/bin/java-petstore-native-async.sh +++ b/bin/java-petstore-native-async.sh @@ -27,7 +27,7 @@ fi # if you've executed sbt assembly previously it will use that instead. export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties" -ags="generate -t modules/openapi-generator/src/main/resources/Java/libraries/native -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin/java-petstore-native.json -o samples/client/petstore/java/native-async --additional-properties hideGenerationTimestamp=true,asyncNative=true $@" +ags="generate -t modules/openapi-generator/src/main/resources/Java -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin/java-petstore-native.json -o samples/client/petstore/java/native-async --additional-properties hideGenerationTimestamp=true,asyncNative=true $@" echo "Removing files and folders under samples/client/petstore/java/httpclient/src/main" rm -rf samples/client/petstore/java/native-async/src/main diff --git a/bin/java-petstore-native.sh b/bin/java-petstore-native.sh index d155429a3a6a..063275017e9e 100755 --- a/bin/java-petstore-native.sh +++ b/bin/java-petstore-native.sh @@ -27,7 +27,7 @@ fi # if you've executed sbt assembly previously it will use that instead. export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties" -ags="generate -t modules/openapi-generator/src/main/resources/Java/libraries/native -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin/java-petstore-native.json -o samples/client/petstore/java/native --additional-properties hideGenerationTimestamp=true $@" +ags="generate -t modules/openapi-generator/src/main/resources/Java -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin/java-petstore-native.json -o samples/client/petstore/java/native --additional-properties hideGenerationTimestamp=true $@" echo "Removing files and folders under samples/client/petstore/java/httpclient/src/main" rm -rf samples/client/petstore/java/native/src/main diff --git a/bin/java-petstore-okhttp-gson-parcelable.sh b/bin/java-petstore-okhttp-gson-parcelable.sh index ae4fbfd8d2b1..92087756ddbd 100755 --- a/bin/java-petstore-okhttp-gson-parcelable.sh +++ b/bin/java-petstore-okhttp-gson-parcelable.sh @@ -27,7 +27,7 @@ fi # if you've executed sbt assembly previously it will use that instead. export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties" -ags="generate --artifact-id petstore-okhttp-gson-parcelableModel -t modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin/java-petstore-okhttp-gson.json -o samples/client/petstore/java/okhttp-gson-parcelableModel --additional-properties hideGenerationTimestamp=true,parcelableModel=true $@" +ags="generate --artifact-id petstore-okhttp-gson-parcelableModel -t modules/openapi-generator/src/main/resources/Java -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin/java-petstore-okhttp-gson.json -o samples/client/petstore/java/okhttp-gson-parcelableModel --additional-properties hideGenerationTimestamp=true,parcelableModel=true $@" rm -rf samples/client/petstore/java/okhttp-gson-parcelableModel/src/main find samples/client/petstore/java/okhttp-gson-parcelableModel -maxdepth 1 -type f ! -name "README.md" -exec rm {} + diff --git a/bin/java-petstore-okhttp-gson.sh b/bin/java-petstore-okhttp-gson.sh index 8e7e7ac84e43..8e2e527d2a3e 100755 --- a/bin/java-petstore-okhttp-gson.sh +++ b/bin/java-petstore-okhttp-gson.sh @@ -27,7 +27,7 @@ fi # if you've executed sbt assembly previously it will use that instead. export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties" -ags="generate -t modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin/java-petstore-okhttp-gson.json -o samples/client/petstore/java/okhttp-gson --additional-properties hideGenerationTimestamp=true $@" +ags="generate -t modules/openapi-generator/src/main/resources/Java -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin/java-petstore-okhttp-gson.json -o samples/client/petstore/java/okhttp-gson --additional-properties hideGenerationTimestamp=true $@" rm -rf samples/client/petstore/java/okhttp-gson/src/main find samples/client/petstore/java/okhttp-gson -maxdepth 1 -type f ! -name "README.md" -exec rm {} + diff --git a/bin/java-petstore-rest-assured-jackson.sh b/bin/java-petstore-rest-assured-jackson.sh index eeffe6aaceed..b5d1888032b9 100755 --- a/bin/java-petstore-rest-assured-jackson.sh +++ b/bin/java-petstore-rest-assured-jackson.sh @@ -28,7 +28,7 @@ fi # if you've executed sbt assembly previously it will use that instead. export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties" -args="generate -t modules/openapi-generator/src/main/resources/Java/libraries/rest-assured -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin/java-petstore-rest-assured-jackson.json -o ${target_dir} --additional-properties hideGenerationTimestamp=true --additional-properties useBeanValidation=true --additional-properties performBeanValidation=true --additional-properties booleanGetterPrefix=is --additional-properties java8=true --additional-properties dateLibrary=java8 --additional-properties serializationLibrary=jackson $@" +args="generate -t modules/openapi-generator/src/main/resources/Java -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin/java-petstore-rest-assured-jackson.json -o ${target_dir} --additional-properties hideGenerationTimestamp=true --additional-properties useBeanValidation=true --additional-properties performBeanValidation=true --additional-properties booleanGetterPrefix=is --additional-properties java8=true --additional-properties dateLibrary=java8 --additional-properties serializationLibrary=jackson $@" echo "Removing ${target_dir}" rm -rf "${target_dir}" diff --git a/bin/java-petstore-rest-assured.sh b/bin/java-petstore-rest-assured.sh index 93de0703ed77..81f1893ed895 100755 --- a/bin/java-petstore-rest-assured.sh +++ b/bin/java-petstore-rest-assured.sh @@ -27,7 +27,7 @@ fi # if you've executed sbt assembly previously it will use that instead. export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties" -ags="generate -t modules/openapi-generator/src/main/resources/Java/libraries/rest-assured -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin/java-petstore-rest-assured.json -o samples/client/petstore/java/rest-assured --additional-properties hideGenerationTimestamp=true --additional-properties useBeanValidation=true --additional-properties performBeanValidation=true --additional-properties booleanGetterPrefix=is $@" +ags="generate -t modules/openapi-generator/src/main/resources/Java -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin/java-petstore-rest-assured.json -o samples/client/petstore/java/rest-assured --additional-properties hideGenerationTimestamp=true --additional-properties useBeanValidation=true --additional-properties performBeanValidation=true --additional-properties booleanGetterPrefix=is $@" echo "Removing files and folders under samples/client/petstore/java/rest-assured/src/main" rm -rf samples/client/petstore/java/rest-assured/src/main diff --git a/bin/java-petstore-retrofit2.sh b/bin/java-petstore-retrofit2.sh index 2dce65f27248..09bd66f45409 100755 --- a/bin/java-petstore-retrofit2.sh +++ b/bin/java-petstore-retrofit2.sh @@ -27,7 +27,7 @@ fi # if you've executed sbt assembly previously it will use that instead. export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties" -ags="generate -t modules/openapi-generator/src/main/resources/Java/libraries/retrofit2 -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin/java-petstore-retrofit2.json -o samples/client/petstore/java/retrofit2 --additional-properties hideGenerationTimestamp=true $@" +ags="generate -t modules/openapi-generator/src/main/resources/Java -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin/java-petstore-retrofit2.json -o samples/client/petstore/java/retrofit2 --additional-properties hideGenerationTimestamp=true $@" echo "Removing files and folders under samples/client/petstore/java/retrofit2/src/main" rm -rf samples/client/petstore/java/retrofit2/src/main diff --git a/bin/java-petstore-retrofit2rx.sh b/bin/java-petstore-retrofit2rx.sh index 74729919db17..c1ddc268e5ab 100755 --- a/bin/java-petstore-retrofit2rx.sh +++ b/bin/java-petstore-retrofit2rx.sh @@ -27,7 +27,7 @@ fi # if you've executed sbt assembly previously it will use that instead. export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties" -ags="generate -t modules/openapi-generator/src/main/resources/Java/libraries/retrofit2 -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin/java-petstore-retrofit2rx.json -o samples/client/petstore/java/retrofit2rx --additional-properties useRxJava=true,hideGenerationTimestamp=true $@" +ags="generate -t modules/openapi-generator/src/main/resources/Java -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin/java-petstore-retrofit2rx.json -o samples/client/petstore/java/retrofit2rx --additional-properties useRxJava=true,hideGenerationTimestamp=true $@" echo "Removing files and folders under samples/client/petstore/java/retrofit2rx/src/main" rm -rf samples/client/petstore/java/retrofit2rx/src/main diff --git a/bin/java-petstore-retrofit2rx2.sh b/bin/java-petstore-retrofit2rx2.sh index 05d6acb7bd0c..9e7d0fe40466 100755 --- a/bin/java-petstore-retrofit2rx2.sh +++ b/bin/java-petstore-retrofit2rx2.sh @@ -27,7 +27,7 @@ fi # if you've executed sbt assembly previously it will use that instead. export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties" -ags="generate -t modules/openapi-generator/src/main/resources/Java/libraries/retrofit2 -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin/java-petstore-retrofit2rx2.json -o samples/client/petstore/java/retrofit2rx2 --additional-properties useRxJava2=true,hideGenerationTimestamp=true $@" +ags="generate -t modules/openapi-generator/src/main/resources/Java -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin/java-petstore-retrofit2rx2.json -o samples/client/petstore/java/retrofit2rx2 --additional-properties useRxJava2=true,hideGenerationTimestamp=true $@" echo "Removing files and folders under samples/client/petstore/java/retrofit2rx2/src/main" rm -rf samples/client/petstore/java/retrofit2rx2/src/main diff --git a/bin/java-petstore-vertx.sh b/bin/java-petstore-vertx.sh index 8eeb623b2785..a2536a3dbf28 100755 --- a/bin/java-petstore-vertx.sh +++ b/bin/java-petstore-vertx.sh @@ -27,7 +27,7 @@ fi # if you've executed sbt assembly previously it will use that instead. export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties" -ags="generate -t modules/openapi-generator/src/main/resources/Java/libraries/vertx -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin/java-petstore-vertx.json -o samples/client/petstore/java/vertx --additional-properties hideGenerationTimestamp=true $@" +ags="generate -t modules/openapi-generator/src/main/resources/Java -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin/java-petstore-vertx.json -o samples/client/petstore/java/vertx --additional-properties hideGenerationTimestamp=true $@" echo "Removing files and folders under samples/client/petstore/java/vertx/src/main" rm -rf samples/client/petstore/java/vertx/src/main diff --git a/bin/windows/java-petstore-feign-10x.bat b/bin/windows/java-petstore-feign-10x.bat index d9163fdac993..68fda6d02362 100644 --- a/bin/windows/java-petstore-feign-10x.bat +++ b/bin/windows/java-petstore-feign-10x.bat @@ -5,6 +5,6 @@ If Not Exist %executable% ( ) REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M -set ags=generate -t modules\openapi-generator\src\main\resources\Java\libraries\feign -i modules\openapi-generator\src\test\resources\2_0\petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin\java-petstore-feign-10x.json -o samples\client\petstore\java\feign10x --additional-properties hideGenerationTimestamp=true,booleanGetterPrefix=is +set ags=generate -t modules\openapi-generator\src\main\resources\Java -i modules\openapi-generator\src\test\resources\2_0\petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin\java-petstore-feign-10x.json -o samples\client\petstore\java\feign10x --additional-properties hideGenerationTimestamp=true,booleanGetterPrefix=is java %JAVA_OPTS% -jar %executable% %ags% diff --git a/bin/windows/java-petstore-google-api-client.bat b/bin/windows/java-petstore-google-api-client.bat index c9d2d761b663..ae005af5c94e 100644 --- a/bin/windows/java-petstore-google-api-client.bat +++ b/bin/windows/java-petstore-google-api-client.bat @@ -5,6 +5,6 @@ If Not Exist %executable% ( ) REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M -set ags=generate -t modules\openapi-generator\src\main\resources\Java\libraries\google-api-client -i modules\openapi-generator\src\test\resources\2_0\petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin\java-petstore-google-api-client.json -o samples\client\petstore\java\google-api-client --additional-properties hideGenerationTimestamp=true +set ags=generate -t modules\openapi-generator\src\main\resources\Java -i modules\openapi-generator\src\test\resources\2_0\petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin\java-petstore-google-api-client.json -o samples\client\petstore\java\google-api-client --additional-properties hideGenerationTimestamp=true java %JAVA_OPTS% -jar %executable% %ags% diff --git a/bin/windows/java-petstore-native.bat b/bin/windows/java-petstore-native.bat index e7301e906796..8980399c8156 100644 --- a/bin/windows/java-petstore-native.bat +++ b/bin/windows/java-petstore-native.bat @@ -5,6 +5,6 @@ If Not Exist %executable% ( ) REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M -set ags=generate -t modules\openapi-generator\src\main\resources\Java\libraries\native -i modules\openapi-generator\src\test\resources\2_0\petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin\java-petstore-native.json -o samples\client\petstore\java\native --additional-properties hideGenerationTimestamp=true +set ags=generate -t modules\openapi-generator\src\main\resources\Java -i modules\openapi-generator\src\test\resources\2_0\petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin\java-petstore-native.json -o samples\client\petstore\java\native --additional-properties hideGenerationTimestamp=true java %JAVA_OPTS% -jar %executable% %ags% diff --git a/bin/windows/java-petstore-okhttp-gson-parcelable.bat b/bin/windows/java-petstore-okhttp-gson-parcelable.bat index 402a3cda7f95..fb88907214eb 100644 --- a/bin/windows/java-petstore-okhttp-gson-parcelable.bat +++ b/bin/windows/java-petstore-okhttp-gson-parcelable.bat @@ -5,6 +5,6 @@ If Not Exist %executable% ( ) REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M -set ags=generate --artifact-id petstore-okhttp-gson-parcelableModel -t modules\openapi-generator\src\main\resources\Java\libraries\okhttp-gson -i modules\openapi-generator\src\test\resources\2_0\petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin\java-petstore-okhttp-gson.json -o samples\client\petstore\java\okhttp-gson-parcelableModel --additional-properties hideGenerationTimestamp=true,parcelableModel=true +set ags=generate --artifact-id petstore-okhttp-gson-parcelableModel -t modules\openapi-generator\src\main\resources\Java -i modules\openapi-generator\src\test\resources\2_0\petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin\java-petstore-okhttp-gson.json -o samples\client\petstore\java\okhttp-gson-parcelableModel --additional-properties hideGenerationTimestamp=true,parcelableModel=true java %JAVA_OPTS% -jar %executable% %ags% diff --git a/bin/windows/java-petstore-okhttp-gson.bat b/bin/windows/java-petstore-okhttp-gson.bat index 80581ca14d44..0965f6a6ae50 100755 --- a/bin/windows/java-petstore-okhttp-gson.bat +++ b/bin/windows/java-petstore-okhttp-gson.bat @@ -5,6 +5,6 @@ If Not Exist %executable% ( ) REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M -set ags=generate -t modules\openapi-generator\src\main\resources\Java\libraries\okhttp-gson -i modules\openapi-generator\src\test\resources\2_0\petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin\java-petstore-okhttp-gson.json -o samples\client\petstore\java\okhttp-gson --additional-properties hideGenerationTimestamp=true +set ags=generate -t modules\openapi-generator\src\main\resources\Java -i modules\openapi-generator\src\test\resources\2_0\petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin\java-petstore-okhttp-gson.json -o samples\client\petstore\java\okhttp-gson --additional-properties hideGenerationTimestamp=true java %JAVA_OPTS% -jar %executable% %ags% diff --git a/bin/windows/java-petstore-rest-assured-jackson.bat b/bin/windows/java-petstore-rest-assured-jackson.bat index 8104df8b771d..070156e2f4e1 100644 --- a/bin/windows/java-petstore-rest-assured-jackson.bat +++ b/bin/windows/java-petstore-rest-assured-jackson.bat @@ -5,6 +5,6 @@ If Not Exist %executable% ( ) REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M -set ags=generate -t modules\openapi-generator\src\main\resources\Java\libraries\rest-assured -i modules\openapi-generator\src\test\resources\2_0\petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin\java-petstore-rest-assured-jackson.json -o samples\client\petstore\java\rest-assured-jackson --additional-properties hideGenerationTimestamp=true,booleanGetterPrefix=is,java8=true,dateLibrary=java8,serializationLibrary=jackson,useBeanValidation=true,performBeanValidation=true, +set ags=generate -t modules\openapi-generator\src\main\resources\Java -i modules\openapi-generator\src\test\resources\2_0\petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin\java-petstore-rest-assured-jackson.json -o samples\client\petstore\java\rest-assured-jackson --additional-properties hideGenerationTimestamp=true,booleanGetterPrefix=is,java8=true,dateLibrary=java8,serializationLibrary=jackson,useBeanValidation=true,performBeanValidation=true, java %JAVA_OPTS% -jar %executable% %ags% diff --git a/bin/windows/java-petstore-rest-assured.bat b/bin/windows/java-petstore-rest-assured.bat index 758af2475861..d83f8c428987 100644 --- a/bin/windows/java-petstore-rest-assured.bat +++ b/bin/windows/java-petstore-rest-assured.bat @@ -5,6 +5,6 @@ If Not Exist %executable% ( ) REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M -set ags=generate -t modules\openapi-generator\src\main\resources\Java\libraries\rest-assured -i modules\openapi-generator\src\test\resources\2_0\petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin\java-petstore-rest-assured.json -o samples\client\petstore\java\rest-assured --additional-properties hideGenerationTimestamp=true --additional-properties useBeanValidation=true --additional-properties performBeanValidation=true --additional-properties booleanGetterPrefix=is +set ags=generate -t modules\openapi-generator\src\main\resources\Java -i modules\openapi-generator\src\test\resources\2_0\petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin\java-petstore-rest-assured.json -o samples\client\petstore\java\rest-assured --additional-properties hideGenerationTimestamp=true --additional-properties useBeanValidation=true --additional-properties performBeanValidation=true --additional-properties booleanGetterPrefix=is java %JAVA_OPTS% -jar %executable% %ags% diff --git a/bin/windows/java-petstore-retrofit2.bat b/bin/windows/java-petstore-retrofit2.bat index e0d57dfdaa25..c21b2941a5f2 100644 --- a/bin/windows/java-petstore-retrofit2.bat +++ b/bin/windows/java-petstore-retrofit2.bat @@ -5,6 +5,6 @@ If Not Exist %executable% ( ) REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M -set ags=generate -t modules\openapi-generator\src\main\resources\Java\libraries\retrofit2 -i modules\openapi-generator\src\test\resources\2_0\petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin\java-petstore-retrofit2.json -o samples\client\petstore\java\retrofit2 --additional-properties hideGenerationTimestamp=true +set ags=generate -t modules\openapi-generator\src\main\resources\Java -i modules\openapi-generator\src\test\resources\2_0\petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin\java-petstore-retrofit2.json -o samples\client\petstore\java\retrofit2 --additional-properties hideGenerationTimestamp=true java %JAVA_OPTS% -jar %executable% %ags% diff --git a/bin/windows/java-petstore-retrofit2rx.bat b/bin/windows/java-petstore-retrofit2rx.bat index e3801c9b7cd0..c62e07cf07f6 100644 --- a/bin/windows/java-petstore-retrofit2rx.bat +++ b/bin/windows/java-petstore-retrofit2rx.bat @@ -5,6 +5,6 @@ If Not Exist %executable% ( ) REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M -set ags=generate -t modules\openapi-generator\src\main\resources\Java\libraries\retrofit2 -i modules\openapi-generator\src\test\resources\2_0\petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin\java-petstore-retrofit2rx.json -o samples\client\petstore\java\retrofit2rx --additional-properties useRxJava=true,hideGenerationTimestamp=true +set ags=generate -t modules\openapi-generator\src\main\resources\Java -i modules\openapi-generator\src\test\resources\2_0\petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin\java-petstore-retrofit2rx.json -o samples\client\petstore\java\retrofit2rx --additional-properties useRxJava=true,hideGenerationTimestamp=true java %JAVA_OPTS% -jar %executable% %ags% diff --git a/bin/windows/java-petstore-retrofit2rx2.bat b/bin/windows/java-petstore-retrofit2rx2.bat index 29899b369604..a9521ef27c31 100644 --- a/bin/windows/java-petstore-retrofit2rx2.bat +++ b/bin/windows/java-petstore-retrofit2rx2.bat @@ -5,6 +5,6 @@ If Not Exist %executable% ( ) REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M -set ags=generate -t modules\openapi-generator\src\main\resources\Java\libraries\retrofit2 -i modules\openapi-generator\src\test\resources\2_0\petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin\java-petstore-retrofit2rx2.json -o samples\client\petstore\java\retrofit2rx2 --additional-properties useRxJava2=true,hideGenerationTimestamp=true +set ags=generate -t modules\openapi-generator\src\main\resources\Java -i modules\openapi-generator\src\test\resources\2_0\petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin\java-petstore-retrofit2rx2.json -o samples\client\petstore\java\retrofit2rx2 --additional-properties useRxJava2=true,hideGenerationTimestamp=true java %JAVA_OPTS% -jar %executable% %ags% diff --git a/bin/windows/java-petstore-vertx.bat b/bin/windows/java-petstore-vertx.bat index 151d1ac1fb3d..133b8eb71734 100644 --- a/bin/windows/java-petstore-vertx.bat +++ b/bin/windows/java-petstore-vertx.bat @@ -5,6 +5,6 @@ If Not Exist %executable% ( ) REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M -set ags=generate -t modules\openapi-generator\src\main\resources\Java\libraries\vertx -i modules\openapi-generator\src\test\resources\2_0\petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin\java-petstore-vertx.json -o samples\client\petstore\java\vertx --additional-properties hideGenerationTimestamp=true +set ags=generate -t modules\openapi-generator\src\main\resources\Java -i modules\openapi-generator\src\test\resources\2_0\petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin\java-petstore-vertx.json -o samples\client\petstore\java\vertx --additional-properties hideGenerationTimestamp=true java %JAVA_OPTS% -jar %executable% %ags% diff --git a/modules/openapi-generator-cli/src/main/java/org/openapitools/codegen/cmd/Meta.java b/modules/openapi-generator-cli/src/main/java/org/openapitools/codegen/cmd/Meta.java index 9fa400098fb1..0c4a8f7cf189 100644 --- a/modules/openapi-generator-cli/src/main/java/org/openapitools/codegen/cmd/Meta.java +++ b/modules/openapi-generator-cli/src/main/java/org/openapitools/codegen/cmd/Meta.java @@ -30,6 +30,11 @@ import org.openapitools.codegen.CodegenConfig; import org.openapitools.codegen.DefaultGenerator; import org.openapitools.codegen.SupportingFile; +import org.openapitools.codegen.TemplateManager; +import org.openapitools.codegen.api.TemplatePathLocator; +import org.openapitools.codegen.templating.MustacheEngineAdapter; +import org.openapitools.codegen.templating.TemplateManagerOptions; +import org.openapitools.codegen.templating.CommonTemplateContentLocator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -136,52 +141,38 @@ public void execute() { */ private static Converter processFiles(final File targetDir, final Map data) { - return new Converter() { - private DefaultGenerator generator = new DefaultGenerator(); - - @Override - public File convert(SupportingFile support) { - try { - File destinationFolder = - new File(new File(targetDir.getAbsolutePath()), support.folder); - File outputFile = new File(destinationFolder, support.destinationFilename); - - String template = - generator.readTemplate(new File(TEMPLATE_DIR_CLASSPATH, - support.templateFile).getPath()); - String formatted = template; - - if (support.templateFile.endsWith(MUSTACHE_EXTENSION)) { - LOGGER.info("writing file to {}", outputFile.getAbsolutePath()); - formatted = - Mustache.compiler().withLoader(loader(generator)).defaultValue("") - .compile(template).execute(data); - } else { - LOGGER.info("copying file to {}", outputFile.getAbsolutePath()); - } - - FileUtils.writeStringToFile(outputFile, formatted, StandardCharsets.UTF_8); - return outputFile; - - } catch (IOException e) { - throw new RuntimeException("Can't generate project", e); + return support -> { + try { + File destinationFolder = + new File(new File(targetDir.getAbsolutePath()), support.folder); + File outputFile = new File(destinationFolder, support.destinationFilename); + + TemplateManager templateProcessor = new TemplateManager( + new TemplateManagerOptions(false, false), + new MustacheEngineAdapter(), + new TemplatePathLocator[]{ new CommonTemplateContentLocator("codegen") } + ); + + String template = templateProcessor.readTemplate(new File(TEMPLATE_DIR_CLASSPATH, support.templateFile).getPath()); + + String formatted = template; + + Mustache.TemplateLoader loader = name -> templateProcessor.getTemplateReader(name.concat(MUSTACHE_EXTENSION)); + + if (support.templateFile.endsWith(MUSTACHE_EXTENSION)) { + LOGGER.info("writing file to {}", outputFile.getAbsolutePath()); + formatted = + Mustache.compiler().withLoader(loader).defaultValue("") + .compile(template).execute(data); + } else { + LOGGER.info("copying file to {}", outputFile.getAbsolutePath()); } - } - }; - } - /** - * Creates mustache loader for template using classpath loader - * - * @param generator - class with reader getter - * @return loader for template - */ - private static Mustache.TemplateLoader loader(final DefaultGenerator generator) { - return new Mustache.TemplateLoader() { - @Override - public Reader getTemplate(String name) { - return generator.getTemplateReader(TEMPLATE_DIR_CLASSPATH + File.separator - + name.concat(MUSTACHE_EXTENSION)); + FileUtils.writeStringToFile(outputFile, formatted, StandardCharsets.UTF_8); + return outputFile; + + } catch (IOException e) { + throw new RuntimeException("Can't generate project", e); } }; } diff --git a/modules/openapi-generator-core/src/main/java/org/openapitools/codegen/api/TemplatePathLocator.java b/modules/openapi-generator-core/src/main/java/org/openapitools/codegen/api/TemplatePathLocator.java new file mode 100644 index 000000000000..9bcd4e2cc8b2 --- /dev/null +++ b/modules/openapi-generator-core/src/main/java/org/openapitools/codegen/api/TemplatePathLocator.java @@ -0,0 +1,14 @@ +package org.openapitools.codegen.api; + +/** + * Provides means for searching for "actual" template location based on relative template file. + */ +public interface TemplatePathLocator { + /** + * Get the full path to a relative template file. + * + * @param relativeTemplateFile Template file + * @return String Full template file path + */ + String getFullTemplatePath(String relativeTemplateFile); +} diff --git a/modules/openapi-generator-core/src/main/java/org/openapitools/codegen/api/TemplateProcessor.java b/modules/openapi-generator-core/src/main/java/org/openapitools/codegen/api/TemplateProcessor.java new file mode 100644 index 000000000000..6f1051676052 --- /dev/null +++ b/modules/openapi-generator-core/src/main/java/org/openapitools/codegen/api/TemplateProcessor.java @@ -0,0 +1,57 @@ +package org.openapitools.codegen.api; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Path; +import java.util.Map; + +/** + * Interface for abstractions around writing templated data to a file. + */ +public interface TemplateProcessor { + /** + * Writes data to a compiled template + * + * @param data Input data + * @param template Input template location + * @param target The targeted file output location + * + * @return The actual file + * @throws IOException If file cannot be written. + */ + File write(Map data, String template, File target) throws IOException; + + /** + * Write bytes to a file + * + * @param filename The name of file to write + * @param contents The contents bytes. Typically this is a UTF-8 formatted string. + * @return File representing the written file. + * @throws IOException If file cannot be written. + */ + File writeToFile(String filename, byte[] contents) throws IOException; + + /** + * Allow a caller to mark a path as ignored with accompanying reason + * + * @param path The ignored path + * @param context The reason for ignoring this path + */ + void ignore(Path path, String context); + + /** + * Allow a caller to mark a path as skipped with accompanying reason + * + * @param path The skipped path + * @param context The reason for skipping this path + */ + void skip(Path path, String context); + + /** + * Allow a caller to mark a path having errored during processing with accompanying reason + * + * @param path The path which has caused an error + * @param context The reason for the error + */ + default void error(Path path, String context) { }; +} diff --git a/modules/openapi-generator-core/src/main/java/org/openapitools/codegen/api/TemplatingEngineAdapter.java b/modules/openapi-generator-core/src/main/java/org/openapitools/codegen/api/TemplatingEngineAdapter.java index 7fceac5246a3..c7240cfe6c2c 100644 --- a/modules/openapi-generator-core/src/main/java/org/openapitools/codegen/api/TemplatingEngineAdapter.java +++ b/modules/openapi-generator-core/src/main/java/org/openapitools/codegen/api/TemplatingEngineAdapter.java @@ -36,27 +36,27 @@ public interface TemplatingEngineAdapter { */ String getIdentifier(); + /** + * During generation, if a supporting file has a file extension that is + * inside that array, then it is considered a templated supporting file + * and we use the templating engine adapter to generate it + * + * @return string array of the valid file extensions for this templating engine + */ + String[] getFileExtensions(); + /** * Compiles a template into a string * - * @param generator From where we can fetch the templates content (e.g. an instance of DefaultGenerator) + * @param executor From where we can fetch the templates content (e.g. an instance of DefaultGenerator) * @param bundle The map of values to pass to the template * @param templateFile The name of the template (e.g. model.mustache ) * @return the processed template result * @throws IOException an error ocurred in the template processing */ - String compileTemplate(TemplatingGenerator generator, Map bundle, + String compileTemplate(TemplatingExecutor executor, Map bundle, String templateFile) throws IOException; - /** - * During generation, if a supporting file has a file extension that is - * inside that array, then it is considered a templated supporting file - * and we use the templating engine adapter to generate it - * - * @return string array of the valid file extensions for this templating engine - */ - String[] getFileExtensions(); - /** * Determines whether the template file with supported extensions exists. This may be on the filesystem, * external filesystem, or classpath (implementation is up to TemplatingGenerator). @@ -65,7 +65,7 @@ String compileTemplate(TemplatingGenerator generator, Map bundle * @param templateFile The original target filename * @return True if the template is available in the template search path, false if it can not be found */ - default boolean templateExists(TemplatingGenerator generator, String templateFile) { + default boolean templateExists(TemplatingExecutor generator, String templateFile) { return Arrays.stream(getFileExtensions()).anyMatch(ext -> { int idx = templateFile.lastIndexOf("."); String baseName; diff --git a/modules/openapi-generator-core/src/main/java/org/openapitools/codegen/api/TemplatingExecutor.java b/modules/openapi-generator-core/src/main/java/org/openapitools/codegen/api/TemplatingExecutor.java new file mode 100644 index 000000000000..d0fbb86b5db9 --- /dev/null +++ b/modules/openapi-generator-core/src/main/java/org/openapitools/codegen/api/TemplatingExecutor.java @@ -0,0 +1,26 @@ +package org.openapitools.codegen.api; + +import java.nio.file.Path; + +/** + * interface to the full template content + * implementers might take into account the -t cli option, + * look in the resources for a generator specific template, etc + */ +public interface TemplatingExecutor { + /** + * returns the template content by name + * + * @param name the template name (e.g. model.mustache) + * @return the contents of that template + */ + String getFullTemplateContents(String name); + + /** + * Returns the path of a template, allowing access to the template where consuming literal contents aren't desirable or possible. + * + * @param name the template name (e.g. model.mustache) + * @return The {@link Path} to the template + */ + Path getFullTemplatePath(String name); +} \ No newline at end of file diff --git a/modules/openapi-generator-core/src/main/java/org/openapitools/codegen/api/TemplatingGenerator.java b/modules/openapi-generator-core/src/main/java/org/openapitools/codegen/api/TemplatingGenerator.java index 268cda6cdfba..30927307e96b 100644 --- a/modules/openapi-generator-core/src/main/java/org/openapitools/codegen/api/TemplatingGenerator.java +++ b/modules/openapi-generator-core/src/main/java/org/openapitools/codegen/api/TemplatingGenerator.java @@ -16,28 +16,15 @@ package org.openapitools.codegen.api; -import java.nio.file.Path; - +// TODO: 6.0 Remove /** * interface to the full template content * implementers might take into account the -t cli option, * look in the resources for a language specific template, etc + * + * @deprecated as of 5.0, replaced by {@link TemplatingExecutor}. */ -public interface TemplatingGenerator { - - /** - * returns the template content by name - * - * @param name the template name (e.g. model.mustache) - * @return the contents of that template - */ - String getFullTemplateContents(String name); +@Deprecated() +public interface TemplatingGenerator extends TemplatingExecutor { - /** - * Returns the path of a template, allowing access to the template where consuming literal contents aren't desirable or possible. - * - * @param name the template name (e.g. model.mustache) - * @return The {@link Path} to the template - */ - Path getFullTemplatePath(String name); } diff --git a/modules/openapi-generator-gradle-plugin/src/main/kotlin/org/openapitools/generator/gradle/plugin/tasks/MetaTask.kt b/modules/openapi-generator-gradle-plugin/src/main/kotlin/org/openapitools/generator/gradle/plugin/tasks/MetaTask.kt index 6a4a180665aa..9bebdd4f4571 100644 --- a/modules/openapi-generator-gradle-plugin/src/main/kotlin/org/openapitools/generator/gradle/plugin/tasks/MetaTask.kt +++ b/modules/openapi-generator-gradle-plugin/src/main/kotlin/org/openapitools/generator/gradle/plugin/tasks/MetaTask.kt @@ -24,10 +24,12 @@ import org.gradle.api.tasks.TaskAction import org.gradle.internal.logging.text.StyledTextOutput import org.gradle.internal.logging.text.StyledTextOutputFactory import org.gradle.kotlin.dsl.property -import org.openapitools.codegen.CodegenConfig -import org.openapitools.codegen.CodegenConstants -import org.openapitools.codegen.DefaultGenerator -import org.openapitools.codegen.SupportingFile +import org.openapitools.codegen.* +import org.openapitools.codegen.api.TemplatePathLocator +import org.openapitools.codegen.templating.CommonTemplateContentLocator +import org.openapitools.codegen.templating.GeneratorTemplateContentLocator +import org.openapitools.codegen.templating.MustacheEngineAdapter +import org.openapitools.codegen.templating.TemplateManagerOptions import java.io.File import java.io.IOException import java.nio.charset.Charset @@ -83,19 +85,28 @@ open class MetaTask : DefaultTask() { "fullyQualifiedGeneratorClass" to "${packageName.get()}.$klass", "openapiGeneratorVersion" to currentVersion) - val generator = DefaultGenerator() supportingFiles.map { try { val destinationFolder = File(File(dir.absolutePath), it.folder) destinationFolder.mkdirs() val outputFile = File(destinationFolder, it.destinationFilename) - val template = generator.readTemplate(File("codegen", it.templateFile).path) + val templateProcessor = TemplateManager( + TemplateManagerOptions(false, false), + MustacheEngineAdapter(), + arrayOf(CommonTemplateContentLocator("codegen")) + ) + + val template = templateProcessor.getFullTemplateContents(it.templateFile) var formatted = template + val loader = Mustache.TemplateLoader { name -> + templateProcessor.getTemplateReader("$name.mustache") + } + if (it.templateFile.endsWith(".mustache")) { formatted = Mustache.compiler() - .withLoader(loader(generator)) + .withLoader(loader) .defaultValue("") .compile(template).execute(data) } @@ -115,12 +126,6 @@ open class MetaTask : DefaultTask() { out.formatln("Created generator %s", klass) } - private fun loader(generator: DefaultGenerator): Mustache.TemplateLoader { - return Mustache.TemplateLoader { name -> - generator.getTemplateReader("codegen${File.separator}$name.mustache") - } - } - private fun String.titleCasedTextOnly(): String = this.split(Regex("[^a-zA-Z0-9]")).joinToString(separator = "", transform = String::capitalize) diff --git a/modules/openapi-generator-gradle-plugin/src/test/kotlin/GenerateTaskDslTest.kt b/modules/openapi-generator-gradle-plugin/src/test/kotlin/GenerateTaskDslTest.kt index 6aecc119252b..5586a1d3fbf5 100644 --- a/modules/openapi-generator-gradle-plugin/src/test/kotlin/GenerateTaskDslTest.kt +++ b/modules/openapi-generator-gradle-plugin/src/test/kotlin/GenerateTaskDslTest.kt @@ -152,13 +152,14 @@ class GenerateTaskDslTest : TestBase() { // Act val result = GradleRunner.create() .withProjectDir(temp) - .withArguments("openApiGenerate") + .withArguments("openApiGenerate", "--stacktrace") .withPluginClasspath() .buildAndFail() // Assert // rather than write out full handlebars generator templates, we'll just test that the configurator has set handlebars as the engine. - assertTrue(result.output.contains("kotlin-client/model.handlebars (No such file or directory)"), "Build should have attempted to use handlebars.") + assertTrue(result.output.contains("HandlebarsException"), "Stack should expose an exception for missing templates.") + assertTrue(result.output.contains("handlebars"), "Build should have attempted to use handlebars.") assertEquals(TaskOutcome.FAILED, result.task(":openApiGenerate")?.outcome, "Expected a failed run, but found ${result.task(":openApiGenerate")?.outcome}") } diff --git a/modules/openapi-generator-gradle-plugin/src/test/kotlin/MetaTaskDslTest.kt b/modules/openapi-generator-gradle-plugin/src/test/kotlin/MetaTaskDslTest.kt index fe857d1b94a8..62e600a92eb8 100644 --- a/modules/openapi-generator-gradle-plugin/src/test/kotlin/MetaTaskDslTest.kt +++ b/modules/openapi-generator-gradle-plugin/src/test/kotlin/MetaTaskDslTest.kt @@ -29,7 +29,7 @@ class MetaTaskDslTest : TestBase() { // Act val result = GradleRunner.create() .withProjectDir(temp) - .withArguments("openApiMeta") + .withArguments("openApiMeta", "--stacktrace") .withPluginClasspath() .build() diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/AbstractGenerator.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/AbstractGenerator.java deleted file mode 100644 index 3a2fecbc5411..000000000000 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/AbstractGenerator.java +++ /dev/null @@ -1,213 +0,0 @@ -/* - * Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech) - * Copyright 2018 SmartBear Software - * - * 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 - * - * https://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; - -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.StandardCopyOption; -import java.util.Arrays; -import org.apache.commons.lang3.StringUtils; -import org.openapitools.codegen.api.TemplatingGenerator; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.*; -import java.nio.file.Paths; -import java.util.HashMap; -import java.util.Map; -import java.util.Scanner; -import java.util.regex.Pattern; - -public abstract class AbstractGenerator implements TemplatingGenerator { - private static final Logger LOGGER = LoggerFactory.getLogger(AbstractGenerator.class); - protected boolean dryRun = false; - protected Map dryRunStatusMap = new HashMap<>(); - - /** - * Is the minimal-file-update option enabled? - * - * @return Option value - */ - public abstract boolean getEnableMinimalUpdate(); - - /** - * Write String to a file, formatting as UTF-8 - * - * @param filename The name of file to write - * @param contents The contents string. - * @return File representing the written file. - * @throws IOException If file cannot be written. - */ - public File writeToFile(String filename, String contents) throws IOException { - return writeToFile(filename, contents.getBytes(StandardCharsets.UTF_8)); - } - - /** - * Write bytes to a file - * - * @param filename The name of file to write - * @param contents The contents bytes. Typically, this is a UTF-8 formatted string. - * @return File representing the written file. - * @throws IOException If file cannot be written. - */ - @SuppressWarnings("static-method") - public File writeToFile(String filename, byte[] contents) throws IOException { - if (getEnableMinimalUpdate()) { - String tempFilename = filename + ".tmp"; - // Use Paths.get here to normalize path (for Windows file separator, space escaping on Linux/Mac, etc) - File outputFile = Paths.get(filename).toFile(); - File tempFile = null; - try { - tempFile = writeToFileRaw(tempFilename, contents); - if (!filesEqual(tempFile, outputFile)) { - LOGGER.info("writing file " + filename); - Files.move(tempFile.toPath(), outputFile.toPath(), StandardCopyOption.REPLACE_EXISTING); - tempFile = null; - } else { - LOGGER.info("skipping unchanged file " + filename); - } - } finally { - if (tempFile != null && tempFile.exists()) { - try { - tempFile.delete(); - } catch (Exception ex) { - LOGGER.error("Error removing temporary file " + tempFile, ex); - } - } - } - return outputFile; - } else { - LOGGER.info("writing file " + filename); - return writeToFileRaw(filename, contents); - } - } - - private boolean filesEqual(File file1, File file2) throws IOException { - return file1.exists() && file2.exists() && Arrays.equals(Files.readAllBytes(file1.toPath()), Files.readAllBytes(file2.toPath())); - } - - private File writeToFileRaw(String filename, byte[] contents) throws IOException { - // Use Paths.get here to normalize path (for Windows file separator, space escaping on Linux/Mac, etc) - File output = Paths.get(filename).toFile(); - if (output.getParent() != null && !new File(output.getParent()).exists()) { - File parent = Paths.get(output.getParent()).toFile(); - parent.mkdirs(); - } - Files.write(output.toPath(), contents); - return output; - } - - public String readTemplate(String name) { - try { - Reader reader = getTemplateReader(name); - if (reader == null) { - throw new RuntimeException("no file found"); - } - Scanner s = new Scanner(reader).useDelimiter("\\A"); - return s.hasNext() ? s.next() : ""; - } catch (Exception e) { - LOGGER.error(e.getMessage()); - } - throw new RuntimeException("can't load template " + name); - } - - @SuppressWarnings("squid:S2095") - // ignored rule as used in the CLI and it's required to return a reader - public Reader getTemplateReader(String name) { - InputStream is = null; - try { - is = this.getClass().getClassLoader().getResourceAsStream(getCPResourcePath(name)); - if (is == null) { - is = new FileInputStream(new File(name)); // May throw but never return a null value - } - return new InputStreamReader(is, "UTF-8"); - } catch (FileNotFoundException | UnsupportedEncodingException e) { - LOGGER.error(e.getMessage()); - throw new RuntimeException("can't load template " + name); - } - } - - private String buildLibraryFilePath(String dir, String library, String file) { - return dir + File.separator + "libraries" + File.separator + library + File.separator + file; - } - - /** - * Get the template file path with template dir prepended, and use the - * library template if exists. - * - * @param config Codegen config - * @param templateFile Template file - * @return String Full template file path - */ - public String getFullTemplateFile(CodegenConfig config, String templateFile) { - //1st the code will check if there's a