SaFi Bank Space : SaFi How to generate OpenApi client library and test it locally

As we are using OpenApiGenerator, when changes are merged to the main branch, it will automatically generate an open api client for the endpoint and publish it into our repository. But what if we want to do more test before merging into the main branch? You can choose to take to generate the client library locally and test it.

Execute generate command

After all code work have done, you should execute ./gradlew openApiGenerateAndBuild

The output may like follow.

./gradlew openApiGenerateAndBuild                       

.............
.............

BUILD SUCCESSFUL in 13s
13 actionable tasks: 13 executed

BUILD SUCCESSFUL in 15s
2 actionable tasks: 2 executed

Check generate result

The open api client will generated under build/generated/openapi, you can check if source codes are correct, and it also generated a jar file which you can import it locally. Directory structure may like follow.

Publish library file to maven local repository

You can publish the library file you generated into your maven local repository by executing ./gradlew publishToMavenLocal. Output may like follow.

% ./gradlew publishToMavenLocal

BUILD SUCCESSFUL in 2s
2 actionable tasks: 2 executed

Import maven local repository and test

If you already have a previous version downloaded by gradle, you need to remove it under you gradle cached repository directory (ex: ~/.gradle/caches/modules-2/files-2.1/ph.safibank.paynamicsgateway/paynamics-gateway-api-client/1.0-SNAPSHOT) prior to publishing the library file to the maven local repository. It is also advisable to clear the client package under the maven local repository (found in ~/.m2).

Add mavenLocal() as first line to the repositories under build.gradle.kts, inside the project that will use the local client library.

After doing that, reload your gradle project, if configuration are all correct, the local library should take effect.

IMPORTANT!

Remember not to commit build.gradle.kts which you have modified. After testing, remove mavenLocal().

Attachments: