diff --git a/README.md b/README.md index 4c93bd0c5..4ed339822 100644 --- a/README.md +++ b/README.md @@ -263,6 +263,14 @@ API clients (Web UIs, Mobile, etc.) * https://github.com/openMF has more related proejcts +Generate Apache Fineract API Client +============ + +Apache Fineract supports client code generation using [Swagger Codegen](https://github.com/swagger-api/swagger-codegen) based on the [OpenAPI Specification Version 3.0.3](https://swagger.io/specification/). + +For more instructions on how to generate the client code, check `docs/developers/swagger/client.md` + + Online Demos ============ diff --git a/docs/developers/swagger/client.md b/docs/developers/swagger/client.md new file mode 100644 index 000000000..c854340be --- /dev/null +++ b/docs/developers/swagger/client.md @@ -0,0 +1,26 @@ +Generate Apache Fineract API Client +============ + +Apache Fineract supports client code generation using [Swagger Codegen](https://github.com/swagger-api/swagger-codegen). Project supports [all clients](https://github.com/swagger-api/swagger-codegen#overview) supported by Swagger Codegen. It uses [OpenAPI Specification Version 3.0.3](https://swagger.io/specification/). + +## Generate API Client + +In root directory of the project: + +- Run `./gradlew build` +- Run `./gradlew generateSwaggerCode` + +The client code will be generated under `build/swagger-code-fineract` + +## Build API Client: + +- Run `cd build/swagger-code-fineract` +- Run `./gradlew build` + +## Customize Code Generator: + +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` +- Customize options +- Build the project again as mentioned in **Generate API Client Code** section \ No newline at end of file diff --git a/fineract-provider/build.gradle b/fineract-provider/build.gradle index ca2c29013..dc85adca3 100644 --- a/fineract-provider/build.gradle +++ b/fineract-provider/build.gradle @@ -56,6 +56,7 @@ buildscript { classpath "net.ltgt.gradle:gradle-errorprone-plugin:1.2.1" classpath "com.diffplug.spotless:spotless-plugin-gradle:5.1.0" classpath "io.swagger.core.v3:swagger-gradle-plugin:2.1.4" + classpath "gradle.plugin.org.hidetake:gradle-swagger-generator-plugin:2.18.1" } } @@ -79,6 +80,7 @@ apply plugin: "com.gorylenko.gradle-git-properties" apply plugin: "net.ltgt.errorprone" apply plugin: "com.diffplug.spotless" apply plugin: "io.swagger.core.v3.swagger-gradle-plugin" +apply plugin: "org.hidetake.swagger.generator" dependencyManagement { imports { @@ -848,3 +850,18 @@ gitProperties { // make sure the generateGitProperties task always executes (even when git.properties is not changed) generateGitProperties.outputs.upToDateWhen { false } + +//This is for swagger code generation +dependencies { + swaggerCodegen 'io.swagger.codegen.v3:swagger-codegen-cli:3.0.20' +} + +swaggerSources { + fineract { + inputFile = file('../build/classes/java/main/static/swagger-ui/fineract.yaml') + code { + language = 'java' + configFile = file('config/swagger/config.json') + } + } +} diff --git a/fineract-provider/config/swagger/config.json b/fineract-provider/config/swagger/config.json new file mode 100644 index 000000000..2a1532874 --- /dev/null +++ b/fineract-provider/config/swagger/config.json @@ -0,0 +1,11 @@ +{ + "groupId": "org.apache.fineract", + "artifactId": "client", + "artifactVersion": "1.4.0", + "invokerPackage": "org.apache.fineract.client", + "modelPackage": "org.apache.fineract.client.models", + "apiPackage": "org.apache.fineract.client.services", + "dateLibrary": "joda", + "hideGenerationTimestamp": "true", + "library": "retrofit2" +}