You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by al...@apache.org on 2020/08/26 21:30:38 UTC

[fineract] branch 1.4.0 updated: FINERACT-1101 Added Mustache templates to Swagger Codegen

This is an automated email from the ASF dual-hosted git repository.

aleks pushed a commit to branch 1.4.0
in repository https://gitbox.apache.org/repos/asf/fineract.git


The following commit(s) were added to refs/heads/1.4.0 by this push:
     new b217982  FINERACT-1101 Added Mustache templates to Swagger Codegen
     new bb10ee9  Merge pull request #1285 from Grandolf49/fineract-1101-backport
b217982 is described below

commit b217982ea08bc344b8d143b073c2364664c380ac
Author: Chinmay Kulkarni <30...@users.noreply.github.com>
AuthorDate: Wed Aug 26 15:41:20 2020 +0530

    FINERACT-1101 Added Mustache templates to Swagger Codegen
---
 .gitignore                                         |   1 +
 docs/developers/swagger/client.md                  |  30 +-
 fineract-provider/build.gradle                     |   4 +-
 .../config/swagger/config.json.template            |   1 +
 .../templates/gradle-wrapper.properties.mustache   |   6 +
 .../config/swagger/templates/pom.mustache          | 355 +++++++++++++++++++++
 6 files changed, 391 insertions(+), 6 deletions(-)

diff --git a/.gitignore b/.gitignore
index f84a22d..a7cbdec 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,6 +12,7 @@ build
 *.iws
 *.DS_Store
 .idea
+.vscode
 catalina.base_IS_UNDEFINED/
 keystore.jks
 bin/
diff --git a/docs/developers/swagger/client.md b/docs/developers/swagger/client.md
index c854340..c5897e2 100644
--- a/docs/developers/swagger/client.md
+++ b/docs/developers/swagger/client.md
@@ -7,20 +7,40 @@ Apache Fineract supports client code generation using [Swagger Codegen](https://
 
 In root directory of the project:
 
-- Run `./gradlew build`
+- Run `./gradlew resolve`
 - Run `./gradlew generateSwaggerCode`
 
 The client code will be generated under `build/swagger-code-fineract`
 
-## Build API Client:
+## Build API Client
 
 - Run `cd build/swagger-code-fineract`
 - Run `./gradlew build`
 
-## Customize Code Generator:
+Alternatively, if you have Maven installed on your system, you can also do:
+
+- Run `cd build/swagger-code-fineract`
+- Run `mvn clean package`
+
+## Customize Generated Code
 
 Swagger Codegen provides several options to customize the generated code. [Here](https://openapi-generator.tech/docs/generators/java/) are the options available for customization.
 
-- Open `fineract-provider/config/swagger/config.json`
+- Open the [config.json.template](https://github.com/apache/fineract/blob/develop/fineract-provider/config/swagger/config.json.template) file
 - Customize options
-- Build the project again as mentioned in **Generate API Client Code** section
\ No newline at end of file
+- Build the project again as mentioned in **Generate API Client Code** section
+  
+## Customize using Mustache Templates
+
+Swagger Codegen uses Mustache Templates for generating the client library. For additional customizations you can add/edit custom templates inside the `fineract-provider/config/swagger/templates` folder. 
+
+Make sure you are following the supported templates. Otherwise, the generated code will not build correctly.
+
+- [Java Mustache Templates](https://github.com/swagger-api/swagger-codegen/tree/master/modules/swagger-codegen/src/main/resources/Java)
+- [Retrofit2 Mustache Templates](https://github.com/swagger-api/swagger-codegen/tree/master/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2)
+
+If you need to add templates for a specific library, you need to follow the same directory structure as present in the links above.
+
+## Validate OpenAPI Spec File
+
+The `resolve` task in [build.gradle](https://github.com/apache/fineract/blob/develop/fineract-provider/build.gradle#L212) file will generate the OpenAPI Spec File for the project. To make sure Swagger Codegen generates a correct library, it is important for the OpenAPI Spec file to be valid. Use [Swagger OpenAPI Validator](https://validator.swagger.io/) to validate the spec file.
\ No newline at end of file
diff --git a/fineract-provider/build.gradle b/fineract-provider/build.gradle
index bf7cfd5..ca10794 100644
--- a/fineract-provider/build.gradle
+++ b/fineract-provider/build.gradle
@@ -323,6 +323,7 @@ rat {
         '**/.gitignore',
         '**/.gitkeep',
         '**/*.iml',
+        '**/config/swagger/templates/**',
         // Notice files
         '**/NOTICE_RELEASE',
         '**/NOTICE_SOURCE',
@@ -872,7 +873,7 @@ generateGitProperties.outputs.upToDateWhen { false }
 // This is for swagger code generation
 // https://github.com/int128/gradle-swagger-generator-plugin
 dependencies {
-    swaggerCodegen 'io.swagger.codegen.v3:swagger-codegen-cli:3.0.18'
+    swaggerCodegen 'io.swagger.codegen.v3:swagger-codegen-cli:3.0.21'
 }
 
 task prepareConfigJson(dependsOn: 'generateGitProperties') {
@@ -892,6 +893,7 @@ swaggerSources {
         code {
             language = 'java'
             configFile = file('config/swagger/config.json')
+            templateDir = file('config/swagger/templates')
         }
     }
 }
diff --git a/fineract-provider/config/swagger/config.json.template b/fineract-provider/config/swagger/config.json.template
index 1b9f4cb..8506fa1 100644
--- a/fineract-provider/config/swagger/config.json.template
+++ b/fineract-provider/config/swagger/config.json.template
@@ -5,6 +5,7 @@
    "invokerPackage": "org.apache.fineract.client",
    "modelPackage": "org.apache.fineract.client.models",
    "apiPackage": "org.apache.fineract.client.services",
+   "artifactDescription": "A Java and Retrofit2 based client library for Apache Fineract Platform",
    "dateLibrary": "java8",
    "hideGenerationTimestamp": "true",
    "library": "retrofit2"
diff --git a/fineract-provider/config/swagger/templates/gradle-wrapper.properties.mustache b/fineract-provider/config/swagger/templates/gradle-wrapper.properties.mustache
new file mode 100644
index 0000000..d58f904
--- /dev/null
+++ b/fineract-provider/config/swagger/templates/gradle-wrapper.properties.mustache
@@ -0,0 +1,6 @@
+#Tue May 17 23:08:05 CST 2016
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-6.6-bin.zip
\ No newline at end of file
diff --git a/fineract-provider/config/swagger/templates/pom.mustache b/fineract-provider/config/swagger/templates/pom.mustache
new file mode 100644
index 0000000..cbfb942
--- /dev/null
+++ b/fineract-provider/config/swagger/templates/pom.mustache
@@ -0,0 +1,355 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <groupId>{{groupId}}</groupId>
+    <artifactId>{{artifactId}}</artifactId>
+    <packaging>jar</packaging>
+    <name>{{artifactId}}</name>
+    <version>{{artifactVersion}}</version>
+    <url>{{artifactUrl}}</url>
+    <description>{{artifactDescription}}</description>
+    <scm>
+        <connection>{{scmConnection}}</connection>
+        <developerConnection>{{scmDeveloperConnection}}</developerConnection>
+        <url>{{scmUrl}}</url>
+    </scm>
+
+    <licenses>
+        <license>
+            <name>{{licenseName}}</name>
+            <url>{{licenseUrl}}</url>
+            <distribution>repo</distribution>
+        </license>
+    </licenses>
+
+    <developers>
+        <developer>
+            <name>{{developerName}}</name>
+            <email>{{developerEmail}}</email>
+            <organization>{{developerOrganization}}</organization>
+            <organizationUrl>{{developerOrganizationUrl}}</organizationUrl>
+        </developer>
+    </developers>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-enforcer-plugin</artifactId>
+                <version>3.0.0-M1</version>
+                <executions>
+                    <execution>
+                        <id>enforce-maven</id>
+                        <goals>
+                            <goal>enforce</goal>
+                        </goals>
+                        <configuration>
+                            <rules>
+                                <requireMavenVersion>
+                                    <version>2.2.0</version>
+                                </requireMavenVersion>
+                            </rules>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <version>2.12</version>
+                <configuration>
+                    <systemProperties>
+                        <property>
+                            <name>loggerPath</name>
+                            <value>conf/log4j.properties</value>
+                        </property>
+                    </systemProperties>
+                    <argLine>-Xms512m -Xmx1500m</argLine>
+                    <parallel>methods</parallel>
+                    <forkMode>pertest</forkMode>
+                </configuration>
+            </plugin>
+            <plugin>
+                <artifactId>maven-dependency-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>copy-dependencies</goal>
+                        </goals>
+                        <configuration>
+                            <outputDirectory>${project.build.directory}/lib</outputDirectory>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+
+            <!-- attach test jar -->
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-jar-plugin</artifactId>
+                <version>2.2</version>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>jar</goal>
+                            <goal>test-jar</goal>
+                        </goals>
+                    </execution>
+                </executions>
+                <configuration>
+                </configuration>
+            </plugin>
+
+            <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>build-helper-maven-plugin</artifactId>
+                <version>1.10</version>
+                <executions>
+                    <execution>
+                        <id>add_sources</id>
+                        <phase>generate-sources</phase>
+                        <goals>
+                            <goal>add-source</goal>
+                        </goals>
+                        <configuration>
+                            <sources>
+                                <source>
+                                src/main/java</source>
+                            </sources>
+                        </configuration>
+                    </execution>
+                    <execution>
+                        <id>add_test_sources</id>
+                        <phase>generate-test-sources</phase>
+                        <goals>
+                            <goal>add-test-source</goal>
+                        </goals>
+                        <configuration>
+                            <sources>
+                                <source>
+                                src/test/java</source>
+                            </sources>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-javadoc-plugin</artifactId>
+                <version>3.2.0</version>
+                <executions>
+                    <execution>
+                        <id>attach-javadocs</id>
+                        <goals>
+                            <goal>jar</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-source-plugin</artifactId>
+                <version>2.2.1</version>
+                <executions>
+                    <execution>
+                        <id>attach-sources</id>
+                        <goals>
+                            <goal>jar-no-fork</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+
+    <profiles>
+        <profile>
+            <id>sign-artifacts</id>
+            <build>
+                <plugins>
+                    <plugin>
+                        <groupId>org.apache.maven.plugins</groupId>
+                        <artifactId>maven-gpg-plugin</artifactId>
+                        <version>1.5</version>
+                        <executions>
+                            <execution>
+                                <id>sign-artifacts</id>
+                                <phase>verify</phase>
+                                <goals>
+                                    <goal>sign</goal>
+                                </goals>
+                            </execution>
+                        </executions>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+    </profiles>
+
+    <dependencies>
+        <dependency>
+            <groupId>io.swagger.core.v3</groupId>
+            <artifactId>swagger-annotations</artifactId>
+            <version>${swagger-core-version}</version>
+        </dependency>
+        <dependency>
+            <groupId>com.squareup.retrofit2</groupId>
+            <artifactId>converter-gson</artifactId>
+            <version>${retrofit-version}</version>
+        </dependency>
+        <dependency>
+            <groupId>com.squareup.retrofit2</groupId>
+            <artifactId>retrofit</artifactId>
+            <version>${retrofit-version}</version>
+        </dependency>
+        <dependency>
+            <groupId>com.squareup.retrofit2</groupId>
+            <artifactId>converter-scalars</artifactId>
+            <version>${retrofit-version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.oltu.oauth2</groupId>
+            <artifactId>org.apache.oltu.oauth2.client</artifactId>
+            <version>${oltu-version}</version>
+        </dependency>
+        <dependency>
+            <groupId>io.gsonfire</groupId>
+            <artifactId>gson-fire</artifactId>
+            <version>${gson-fire-version}</version>
+        </dependency>
+        {{#joda}}
+            <dependency>
+                <groupId>joda-time</groupId>
+                <artifactId>joda-time</artifactId>
+                <version>${jodatime-version}</version>
+            </dependency>
+        {{/joda}}
+        {{#threetenbp}}
+            <dependency>
+                <groupId>org.threeten</groupId>
+                <artifactId>threetenbp</artifactId>
+                <version>${threetenbp-version}</version>
+            </dependency>
+        {{/threetenbp}}
+        {{#useRxJava}}
+            <dependency>
+                <groupId>io.reactivex</groupId>
+                <artifactId>rxjava</artifactId>
+                <version>${rxjava-version}</version>
+            </dependency>
+            <dependency>
+                <groupId>com.squareup.retrofit2</groupId>
+                <artifactId>adapter-rxjava</artifactId>
+                <version>${retrofit-version}</version>
+            </dependency>
+        {{/useRxJava}}
+        {{#useRxJava2}}
+            <dependency>
+                <groupId>io.reactivex.rxjava2</groupId>
+                <artifactId>rxjava</artifactId>
+                <version>${rxjava-version}</version>
+            </dependency>
+            <dependency>
+                <groupId>com.squareup.retrofit2</groupId>
+                <artifactId>adapter-rxjava2</artifactId>
+                <version>${retrofit-version}</version>
+            </dependency>
+        {{/useRxJava2}}
+
+        {{#usePlayWS}}
+            <!-- JSON processing: jackson -->
+            <dependency>
+                <groupId>com.squareup.retrofit2</groupId>
+                <artifactId>converter-jackson</artifactId>
+                <version>${retrofit-version}</version>
+            </dependency>
+            <dependency>
+                <groupId>com.fasterxml.jackson.core</groupId>
+                <artifactId>jackson-core</artifactId>
+                <version>${jackson-version}</version>
+            </dependency>
+            <dependency>
+                <groupId>com.fasterxml.jackson.core</groupId>
+                <artifactId>jackson-annotations</artifactId>
+                <version>${jackson-version}</version>
+            </dependency>
+            <dependency>
+                <groupId>com.fasterxml.jackson.core</groupId>
+                <artifactId>jackson-databind</artifactId>
+                <version>${jackson-version}</version>
+            </dependency>
+            <dependency>
+                <groupId>com.fasterxml.jackson.datatype</groupId>
+                <artifactId>jackson-datatype-{{^java8}}joda{{/java8}}{{#java8}}jsr310{{/java8}}</artifactId>
+                <version>${jackson-version}</version>
+            </dependency>
+            {{#withXml}}
+
+                <!-- XML processing: Jackson -->
+                <dependency>
+                    <groupId>com.fasterxml.jackson.dataformat</groupId>
+                    <artifactId>jackson-dataformat-xml</artifactId>
+                    <version>${jackson-version}</version>
+                </dependency>
+
+            {{/withXml}}
+            <dependency>
+                <groupId>com.typesafe.play</groupId>
+                <artifactId>play-java-ws_2.11</artifactId>
+                <version>${play-version}</version>
+            </dependency>
+        {{/usePlayWS}}
+
+        {{#parcelableModel}}
+            <!-- Needed for Parcelable support-->
+            <dependency>
+                <groupId>com.google.android</groupId>
+                <artifactId>android</artifactId>
+                <version>4.1.1.4</version>
+                <scope>provided</scope>
+            </dependency>
+        {{/parcelableModel}}
+
+        <!-- test dependencies -->
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>${junit-version}</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+    <properties>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        <java.version>{{#java8}}1.8{{/java8}}{{^java8}}1.7{{/java8}}</java.version>
+        <maven.compiler.source>${java.version}</maven.compiler.source>
+        <maven.compiler.target>${java.version}</maven.compiler.target>
+        <gson-fire-version>1.8.0</gson-fire-version>
+        <swagger-core-version>2.0.0</swagger-core-version>
+        {{#usePlayWS}}
+            {{#play24}}
+                <jackson-version>2.10.1</jackson-version>
+                <play-version>2.4.11</play-version>
+            {{/play24}}
+            {{#play25}}
+                <jackson-version>2.10.1</jackson-version>
+                <play-version>2.5.15</play-version>
+            {{/play25}}
+        {{/usePlayWS}}
+        <retrofit-version>2.3.0</retrofit-version>
+        {{#useRxJava}}
+            <rxjava-version>1.3.0</rxjava-version>
+        {{/useRxJava}}
+        {{#useRxJava2}}
+            <rxjava-version>2.1.1</rxjava-version>
+        {{/useRxJava2}}
+        {{#joda}}
+            <jodatime-version>2.9.9</jodatime-version>
+        {{/joda}}
+        {{#threetenbp}}
+            <threetenbp-version>1.3.5</threetenbp-version>
+        {{/threetenbp}}
+        <oltu-version>1.0.2</oltu-version>
+        <junit-version>4.12</junit-version>
+    </properties>
+</project>
\ No newline at end of file