FINERACT-1207: Clean up fineract-provider/config/swagger following introduction of fineract-client/

This commit is contained in:
Aleksandar Vidakovic
2020-10-19 21:15:50 +03:00
committed by Petri Tuomola
parent db4d2ae006
commit f192b7315b
7 changed files with 6 additions and 615 deletions
+6 -34
View File
@@ -1,46 +1,18 @@
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/).
Apache Fineract supports client code generation using [OpenAPI Generator](https://openapi-generator.tech). It uses [OpenAPI Specification Version 3.0.3](https://swagger.io/specification/).
## Generate API Client
In root directory of the project:
The API client is built as part of the overall Fineract Gradle build. If you want to save (maybe) some time you can try to execute just the following line in root directory of the project:
- Run `./gradlew resolve`
- Run `./gradlew generateSwaggerCode`
- Run `./gradlew :fineract-client:build`
The client code will be generated under `build/swagger-code-fineract`
The client JAR can be found in `fineract-client/build/libs`.
## Build API Client
- Run `cd build/swagger-code-fineract`
- Run `./gradlew build`
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 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
## 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.
Note: Build only `fineract-client` may or may not actually save you some build time. There are still project module dependencies that might trigger a complete build.
## 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.
The `resolve` task in [build.gradle](https://github.com/apache/fineract/blob/develop/fineract-provider/build.gradle#L80) 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. Validation is done automatically by the OpenAPI code generator Gradle plugin. If you still have problems during code generation please use [Swagger OpenAPI Validator](https://validator.swagger.io/) to validate the spec file.