From 78280aab98ee80fdbe3bb5f10cd510e1058870c5 Mon Sep 17 00:00:00 2001 From: Arnold Galovics Date: Wed, 15 Jun 2022 10:57:12 +0200 Subject: [PATCH] Allow headers to be passed for generated fineract client APIs --- fineract-client/build.gradle | 2 +- .../java/template/build.gradle.mustache | 218 -------- .../main/resources/java/template/pom.mustache | 479 ------------------ .../resources/templates/java/api.mustache | 120 +++++ 4 files changed, 121 insertions(+), 698 deletions(-) delete mode 100644 fineract-client/src/main/resources/java/template/build.gradle.mustache delete mode 100644 fineract-client/src/main/resources/java/template/pom.mustache create mode 100644 fineract-client/src/main/resources/templates/java/api.mustache diff --git a/fineract-client/build.gradle b/fineract-client/build.gradle index 2d9b508d9..7af23cee2 100644 --- a/fineract-client/build.gradle +++ b/fineract-client/build.gradle @@ -46,7 +46,7 @@ task buildJavaSdk(type: org.openapitools.generator.gradle.plugin.tasks.GenerateT skipValidateSpec = true inputSpec = "file:///$swaggerFile" outputDir = "$buildDir/generated/java".toString() - templateDir = "$rootDir/fineract-client/src/main/resources/java/template/" + templateDir = "$projectDir/src/main/resources/templates/java" groupId = 'org.apache.fineract' apiPackage = 'org.apache.fineract.client.services' invokerPackage = 'org.apache.fineract.client' diff --git a/fineract-client/src/main/resources/java/template/build.gradle.mustache b/fineract-client/src/main/resources/java/template/build.gradle.mustache deleted file mode 100644 index e61973267..000000000 --- a/fineract-client/src/main/resources/java/template/build.gradle.mustache +++ /dev/null @@ -1,218 +0,0 @@ -{{! -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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. - */ -}} -apply plugin: 'idea' -apply plugin: 'eclipse' - -group = '{{groupId}}' -version = '{{artifactVersion}}' - -buildscript { -repositories { -maven { url "https://repo1.maven.org/maven2" } -jcenter() -} -dependencies { -classpath 'com.android.tools.build:gradle:2.3.+' -classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' -} -} - -repositories { -jcenter() -} - - -if(hasProperty('target') && target == 'android') { - -apply plugin: 'com.android.library' -apply plugin: 'com.github.dcendents.android-maven' - -android { -compileSdkVersion 25 -buildToolsVersion '25.0.2' -defaultConfig { -minSdkVersion 14 -targetSdkVersion 25 -} -compileOptions { -{{#java8}} - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 -{{/java8}} -{{^java8}} - sourceCompatibility JavaVersion.VERSION_1_7 - targetCompatibility JavaVersion.VERSION_1_7 -{{/java8}} -} - -// Rename the aar correctly -libraryVariants.all { variant -> -variant.outputs.each { output -> -def outputFile = output.outputFile -if (outputFile != null && outputFile.name.endsWith('.aar')) { -def fileName = "${project.name}-${variant.baseName}-${version}.aar" -output.outputFile = new File(outputFile.parent, fileName) -} -} -} - -dependencies { -provided 'javax.annotation:jsr250-api:1.0' -} -} - -afterEvaluate { -android.libraryVariants.all { variant -> -def task = project.tasks.create "jar${variant.name.capitalize()}", Jar -task.description = "Create jar artifact for ${variant.name}" -task.dependsOn variant.javaCompile -task.from variant.javaCompile.destinationDir -task.destinationDir = project.file("${project.buildDir}/outputs/jar") -task.archiveName = "${project.name}-${variant.baseName}-${version}.jar" -artifacts.add('archives', task); -} -} - -task sourcesJar(type: Jar) { -from android.sourceSets.main.java.srcDirs -classifier = 'sources' -} - -artifacts { -archives sourcesJar -} - -} else { - -apply plugin: 'java' -apply plugin: 'maven' - -{{#java8}} - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 -{{/java8}} -{{^java8}} - sourceCompatibility = JavaVersion.VERSION_1_7 - targetCompatibility = JavaVersion.VERSION_1_7 -{{/java8}} - -install { -repositories.mavenInstaller { -pom.artifactId = '{{artifactId}}' -} -} - -task execute(type:JavaExec) { -main = System.getProperty('mainClass') -classpath = sourceSets.main.runtimeClasspath -} -} - -ext { -oltu_version = "1.0.1" -retrofit_version = "2.9.0" -okhttp3_version = "4.9.0" -{{#usePlayWS}} - jackson_version = "2.10.5" - jackson_databind_version = "2.10.5.1" - {{#openApiNullable}} - jackson_databind_nullable_version = "0.2.1" - {{/openApiNullable}} - {{#play24}} - play_version = "2.4.11" - {{/play24}} - {{#play25}} - play_version = "2.5.14" - {{/play25}} - {{#play26}} - play_version = "2.6.7" - {{/play26}} -{{/usePlayWS}} -swagger_annotations_version = "1.5.22" -junit_version = "4.13.1" -{{#useRxJava}} - rx_java_version = "1.3.0" -{{/useRxJava}} -{{#useRxJava2}} - rx_java_version = "2.1.1" -{{/useRxJava2}} -{{#useRxJava3}} - rx_java_version = "3.0.4" -{{/useRxJava3}} -{{#joda}} - jodatime_version = "2.9.9" -{{/joda}} -{{#threetenbp}} - threetenbp_version = "1.4.0" -{{/threetenbp}} -json_fire_version = "1.8.0" -} - -dependencies { -implementation "com.squareup.retrofit2:retrofit:$retrofit_version" -implementation "com.squareup.retrofit2:converter-scalars:$retrofit_version" -implementation "com.squareup.retrofit2:converter-gson:$retrofit_version" -implementation "com.squareup.okhttp3:logging-interceptor:4.9.0" -implementation "com.squareup.okhttp3:okhttp:$okhttp3_version" -{{#useRxJava}} - implementation "com.squareup.retrofit2:adapter-rxjava:$retrofit_version" - implementation "io.reactivex:rxjava:$rx_java_version" -{{/useRxJava}} -{{#useRxJava2}} - implementation 'com.squareup.retrofit2:adapter-rxjava2:2.3.0' - implementation "io.reactivex.rxjava2:rxjava:$rx_java_version" -{{/useRxJava2}} -{{#useRxJava3}} - implementation 'com.github.akarnokd:rxjava3-retrofit-adapter:3.0.0' - implementation "io.reactivex.rxjava3:rxjava:$rx_java_version" -{{/useRxJava3}} -implementation "io.swagger:swagger-annotations:$swagger_annotations_version" -implementation "com.google.code.findbugs:jsr305:3.0.2" -implementation ("org.apache.oltu.oauth2:org.apache.oltu.oauth2.client:$oltu_version"){ -exclude group:'org.apache.oltu.oauth2' , module: 'org.apache.oltu.oauth2.common' -} -implementation "io.gsonfire:gson-fire:$json_fire_version" -{{#joda}} - implementation "joda-time:joda-time:$jodatime_version" -{{/joda}} -{{#threetenbp}} - implementation "org.threeten:threetenbp:$threetenbp_version" -{{/threetenbp}} -{{#usePlayWS}} - {{#play26}} - implementation "com.typesafe.play:play-ahc-ws_2.12:$play_version" - implementation "javax.validation:validation-api:1.1.0.Final" - {{/play26}} - {{^play26}} - implementation "com.typesafe.play:play-java-ws_2.11:$play_version" - {{/play26}} - implementation "com.squareup.retrofit2:converter-jackson:$retrofit_version" - implementation "com.fasterxml.jackson.core:jackson-core:$jackson_version" - implementation "com.fasterxml.jackson.core:jackson-annotations:$jackson_version" - implementation "com.fasterxml.jackson.core:jackson-databind:$jackson_databind_version" - {{#openApiNullable}} - implementation "org.openapitools:jackson-databind-nullable:$jackson_databind_nullable_version" - {{/openApiNullable}} - implementation "com.fasterxml.jackson.datatype:jackson-datatype-{{^java8}}joda{{/java8}}{{#java8}}jsr310{{/java8}}:$jackson_version" -{{/usePlayWS}} -implementation 'javax.annotation:javax.annotation-api:1.3.2' -testImplementation "junit:junit:$junit_version" -} \ No newline at end of file diff --git a/fineract-client/src/main/resources/java/template/pom.mustache b/fineract-client/src/main/resources/java/template/pom.mustache deleted file mode 100644 index f2aa1939f..000000000 --- a/fineract-client/src/main/resources/java/template/pom.mustache +++ /dev/null @@ -1,479 +0,0 @@ -{{! -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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. - */ -}} - - 4.0.0 - {{groupId}} - {{artifactId}} - jar - {{artifactId}} - {{artifactVersion}} - {{artifactUrl}} - {{artifactDescription}} - - {{scmConnection}} - {{scmDeveloperConnection}} - {{scmUrl}} - - {{#parentOverridden}} - - {{{parentGroupId}}} - {{{parentArtifactId}}} - {{{parentVersion}}} - - {{/parentOverridden}} - - - - {{licenseName}} - {{licenseUrl}} - repo - - - - - - {{developerName}} - {{developerEmail}} - {{developerOrganization}} - {{developerOrganizationUrl}} - - - - - - - org.apache.maven.plugins - maven-enforcer-plugin - 3.0.0-M1 - - - enforce-maven - - enforce - - - - - 2.2.0 - - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.12 - - - - loggerPath - conf/log4j.properties - - - -Xms512m -Xmx1500m - methods - pertest - - - - maven-dependency-plugin - - - package - - copy-dependencies - - - ${project.build.directory}/lib - - - - - - - - org.apache.maven.plugins - maven-jar-plugin - 2.2 - - - - jar - test-jar - - - - - - - - - org.codehaus.mojo - build-helper-maven-plugin - 1.10 - - - add_sources - generate-sources - - add-source - - - - src/main/java - - - - - add_test_sources - generate-test-sources - - add-test-source - - - - src/test/java - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.6.1 - - {{#java8}} - 1.8 - 1.8 - {{/java8}} - {{^java8}} - 1.7 - 1.7 - {{/java8}} - - - - org.apache.maven.plugins - maven-javadoc-plugin - 3.1.1 - - none - {{#java8}} - 1.8 - {{/java8}} - {{^java8}} - 1.7 - {{/java8}} - - - - attach-javadocs - - jar - - - - - - org.apache.maven.plugins - maven-source-plugin - 2.2.1 - - - attach-sources - - jar-no-fork - - - - - - - - - - sign-artifacts - - - - org.apache.maven.plugins - maven-gpg-plugin - 1.5 - - - sign-artifacts - verify - - sign - - - - - - - - - - - - io.swagger - swagger-annotations - ${swagger-annotations-version} - - - - com.squareup.okhttp3 - okhttp - ${okhttp3-version} - - - - com.squareup.okhttp3 - logging-interceptor - 3.12.1 - - - - com.google.code.findbugs - jsr305 - 3.0.2 - - - com.squareup.retrofit2 - converter-gson - ${retrofit-version} - - - com.squareup.retrofit2 - retrofit - ${retrofit-version} - - - com.squareup.retrofit2 - converter-scalars - ${retrofit-version} - - - org.apache.oltu.oauth2 - org.apache.oltu.oauth2.client - ${oltu-version} - - - org.apache.oltu.oauth2 - common - - - - - io.gsonfire - gson-fire - ${gson-fire-version} - - {{#joda}} - - joda-time - joda-time - ${jodatime-version} - - {{/joda}} - {{#threetenbp}} - - org.threeten - threetenbp - ${threetenbp-version} - - {{/threetenbp}} - {{#useRxJava}} - - io.reactivex - rxjava - ${rxjava-version} - - - com.squareup.retrofit2 - adapter-rxjava - ${retrofit-version} - - {{/useRxJava}} - {{#useRxJava2}} - - io.reactivex.rxjava2 - rxjava - ${rxjava-version} - - - com.squareup.retrofit2 - adapter-rxjava2 - ${retrofit-version} - - {{/useRxJava2}} - {{#useRxJava3}} - - io.reactivex.rxjava3 - rxjava - ${rxjava-version} - - - com.github.akarnokd - rxjava3-retrofit-adapter - 3.0.0 - - {{/useRxJava3}} - {{#usePlayWS}} - - - com.squareup.retrofit2 - converter-jackson - ${retrofit-version} - - - com.fasterxml.jackson.core - jackson-core - ${jackson-version} - - - com.fasterxml.jackson.core - jackson-annotations - ${jackson-version} - - - com.fasterxml.jackson.core - jackson-databind - ${jackson-version} - - {{#openApiNullable}} - - org.openapitools - jackson-databind-nullable - ${jackson-databind-nullable-version} - - {{/openApiNullable}} - - com.fasterxml.jackson.datatype - jackson-datatype-{{^java8}}joda{{/java8}}{{#java8}}jsr310{{/java8}} - ${jackson-version} - - {{#withXml}} - - - com.fasterxml.jackson.dataformat - jackson-dataformat-xml - ${jackson-version} - - {{/withXml}} - {{#play24}} - - com.typesafe.play - play-java-ws_2.11 - ${play-version} - - {{/play24}} - {{#play25}} - - com.typesafe.play - play-java-ws_2.11 - ${play-version} - - {{/play25}} - {{#play26}} - - com.typesafe.play - play-ahc-ws_2.12 - ${play-version} - - - javax.validation - validation-api - 1.1.0.Final - - {{/play26}} - {{/usePlayWS}} - {{#parcelableModel}} - - - com.google.android - android - 4.1.1.4 - provided - - {{/parcelableModel}} - - javax.annotation - javax.annotation-api - ${javax-annotation-version} - provided - - - - junit - junit - ${junit-version} - test - - - - UTF-8 - {{#java8}}1.8{{/java8}}{{^java8}}1.7{{/java8}} - ${java.version} - ${java.version} - 1.8.3 - 1.5.22 - {{#usePlayWS}} - 2.12.1 - {{#play24}} - 2.4.11 - {{/play24}} - {{#play25}} - 2.5.15 - {{/play25}} - {{#play26}} - 2.6.7 - {{/play26}} - {{#openApiNullable}} - 0.2.1 - {{/openApiNullable}} - {{/usePlayWS}} - 2.9.0 - 4.9.0 - {{#useRxJava}} - 1.3.0 - {{/useRxJava}} - {{#useRxJava2}} - 2.1.1 - {{/useRxJava2}} - {{#useRxJava3}} - 3.0.4 - {{/useRxJava3}} - {{#joda}} - 2.9.9 - {{/joda}} - {{#threetenbp}} - 1.4.0 - {{/threetenbp}} - 1.3.2 - 1.0.1 - 4.13.1 - - \ No newline at end of file diff --git a/fineract-client/src/main/resources/templates/java/api.mustache b/fineract-client/src/main/resources/templates/java/api.mustache new file mode 100644 index 000000000..65915d89f --- /dev/null +++ b/fineract-client/src/main/resources/templates/java/api.mustache @@ -0,0 +1,120 @@ +package {{package}}; + +import {{invokerPackage}}.CollectionFormats.*; + +{{#useRxJava2}} + import io.reactivex.Observable; +{{/useRxJava2}} +{{#useRxJava3}} + import io.reactivex.rxjava3.core.Observable; +{{/useRxJava3}} +{{^returnType}} + {{#useRxJava2}} + import io.reactivex.Completable; + {{/useRxJava2}} + {{#useRxJava3}} + import io.reactivex.rxjava3.core.Completable; + {{/useRxJava3}} +{{/returnType}} +{{#doNotUseRx}} + import retrofit2.Call; +{{/doNotUseRx}} +import retrofit2.http.*; + +import okhttp3.RequestBody; +import okhttp3.ResponseBody; +import okhttp3.MultipartBody; + +{{#imports}}import {{import}}; +{{/imports}} + +{{^fullJavaUtil}} + import java.util.ArrayList; + import java.util.HashMap; + import java.util.List; + import java.util.Map; +{{/fullJavaUtil}} + +{{#operations}} + public interface {{classname}} { + {{#operation}} + /** + * {{summary}} + * {{notes}} + {{#allParams}} + * @param {{paramName}} {{description}}{{#required}} (required){{/required}}{{^required}} (optional{{#defaultValue}}, default to {{.}}{{/defaultValue}}){{/required}} + {{/allParams}} + * @return {{^doNotUseRx}}{{#useRxJava2}}{{#returnType}}Observable<{{#isResponseFile}}ResponseBody{{/isResponseFile}}{{^isResponseFile}}{{returnType}}{{/isResponseFile}}>{{/returnType}}{{^returnType}}Completable{{/returnType}}{{/useRxJava2}}{{#useRxJava3}}{{#returnType}}Observable<{{#isResponseFile}}ResponseBody{{/isResponseFile}}{{^isResponseFile}}{{returnType}}{{/isResponseFile}}>{{/returnType}}{{^returnType}}Completable{{/returnType}}{{/useRxJava3}}{{/doNotUseRx}}{{#doNotUseRx}}Call<{{#isResponseFile}}ResponseBody{{/isResponseFile}}{{^isResponseFile}}{{returnType}}{{^returnType}}Void{{/returnType}}{{/isResponseFile}}>{{/doNotUseRx}} + {{#isDeprecated}} + * @deprecated + {{/isDeprecated}} + {{#externalDocs}} + * {{description}} + * @see {{summary}} Documentation + {{/externalDocs}} + */ + {{#isDeprecated}} + @Deprecated + {{/isDeprecated}} + {{#formParams}} + {{#-first}} + {{#isMultipart}}@retrofit2.http.Multipart{{/isMultipart}}{{^isMultipart}}@retrofit2.http.FormUrlEncoded{{/isMultipart}} + {{/-first}} + {{/formParams}} + {{^formParams}} + {{#prioritizedContentTypes}} + {{#-first}} + @Headers({ + "Content-Type:{{{mediaType}}}" + }) + {{/-first}} + {{/prioritizedContentTypes}} + {{/formParams}} + @{{httpMethod}}("{{{path}}}") + {{^doNotUseRx}}{{#useRxJava2}}{{#returnType}}Observable<{{#isResponseFile}}ResponseBody{{/isResponseFile}}{{^isResponseFile}}{{{returnType}}}{{/isResponseFile}}>{{/returnType}}{{^returnType}}Completable{{/returnType}}{{/useRxJava2}}{{#useRxJava3}}{{#returnType}}Observable<{{#isResponseFile}}ResponseBody{{/isResponseFile}}{{^isResponseFile}}{{{returnType}}}{{/isResponseFile}}>{{/returnType}}{{^returnType}}Completable{{/returnType}}{{/useRxJava3}}{{/doNotUseRx}}{{#doNotUseRx}}Call<{{#isResponseFile}}ResponseBody{{/isResponseFile}}{{^isResponseFile}}{{{returnType}}}{{^returnType}}Void{{/returnType}}{{/isResponseFile}}>{{/doNotUseRx}} {{operationId}}({{^allParams}});{{/allParams}} + {{#allParams}}{{>libraries/retrofit2/queryParams}}{{>libraries/retrofit2/pathParams}}{{>libraries/retrofit2/headerParams}}{{>libraries/retrofit2/bodyParams}}{{>libraries/retrofit2/formParams}}{{^-last}}, {{/-last}}{{#-last}} + );{{/-last}}{{/allParams}} + + {{/operation}} + + {{#operation}} + /** + * {{summary}} + * {{notes}} + {{#allParams}} + * @param {{paramName}} {{description}}{{#required}} (required){{/required}}{{^required}} (optional{{#defaultValue}}, default to {{.}}{{/defaultValue}}){{/required}} + {{/allParams}} + * @return {{^doNotUseRx}}{{#useRxJava2}}{{#returnType}}Observable<{{#isResponseFile}}ResponseBody{{/isResponseFile}}{{^isResponseFile}}{{returnType}}{{/isResponseFile}}>{{/returnType}}{{^returnType}}Completable{{/returnType}}{{/useRxJava2}}{{#useRxJava3}}{{#returnType}}Observable<{{#isResponseFile}}ResponseBody{{/isResponseFile}}{{^isResponseFile}}{{returnType}}{{/isResponseFile}}>{{/returnType}}{{^returnType}}Completable{{/returnType}}{{/useRxJava3}}{{/doNotUseRx}}{{#doNotUseRx}}Call<{{#isResponseFile}}ResponseBody{{/isResponseFile}}{{^isResponseFile}}{{returnType}}{{^returnType}}Void{{/returnType}}{{/isResponseFile}}>{{/doNotUseRx}} + {{#isDeprecated}} + * @deprecated + {{/isDeprecated}} + {{#externalDocs}} + * {{description}} + * @see {{summary}} Documentation + {{/externalDocs}} + */ + {{#isDeprecated}} + @Deprecated + {{/isDeprecated}} + {{#formParams}} + {{#-first}} + {{#isMultipart}}@retrofit2.http.Multipart{{/isMultipart}}{{^isMultipart}}@retrofit2.http.FormUrlEncoded{{/isMultipart}} + {{/-first}} + {{/formParams}} + {{^formParams}} + {{#prioritizedContentTypes}} + {{#-first}} + @Headers({ + "Content-Type:{{{mediaType}}}" + }) + {{/-first}} + {{/prioritizedContentTypes}} + {{/formParams}} + @{{httpMethod}}("{{{path}}}") + {{^doNotUseRx}}{{#useRxJava2}}{{#returnType}}Observable<{{#isResponseFile}}ResponseBody{{/isResponseFile}}{{^isResponseFile}}{{{returnType}}}{{/isResponseFile}}>{{/returnType}}{{^returnType}}Completable{{/returnType}}{{/useRxJava2}}{{#useRxJava3}}{{#returnType}}Observable<{{#isResponseFile}}ResponseBody{{/isResponseFile}}{{^isResponseFile}}{{{returnType}}}{{/isResponseFile}}>{{/returnType}}{{^returnType}}Completable{{/returnType}}{{/useRxJava3}}{{/doNotUseRx}}{{#doNotUseRx}}Call<{{#isResponseFile}}ResponseBody{{/isResponseFile}}{{^isResponseFile}}{{{returnType}}}{{^returnType}}Void{{/returnType}}{{/isResponseFile}}>{{/doNotUseRx}} {{operationId}}({{^allParams}}@HeaderMap Map headers);{{/allParams}} + {{#allParams}}{{>libraries/retrofit2/queryParams}}{{>libraries/retrofit2/pathParams}}{{>libraries/retrofit2/headerParams}}{{>libraries/retrofit2/bodyParams}}{{>libraries/retrofit2/formParams}}{{^-last}}, {{/-last}}{{#-last}} + , @HeaderMap Map headers);{{/-last}}{{/allParams}} + + {{/operation}} + } +{{/operations}} \ No newline at end of file