Experimental This is experimental. Don't use it in production. Examples demonstrate that this client is usable. Please submit patches and open issues with your experience. This repo contains java code generated from customized Equinix Metal oas3. The client is generated using the java client support built into the openapi-generator.
-
Jq (https://stedolan.github.io/jq/) : Jq command is used inside makefile to format OAS 3.0 json read from equinix public url.
brew install jq
-
Docker : We can generate metal-java client in two ways (described in later section), first is via utilising swagger codegen image to consume metal OAS 3.0 spec which is provided as option in makefile. To install docker refer : https://docs.docker.com/engine/install/.
-
Building the API client library requires:
- Java 1.7+
- Maven
Build generated client:
cd equinix-openapi-metal
mvn clean package
The following executes list metro sample by consuming local jars produced after building generated metal-java client:
cd ..
java -classpath "equinix-openapi-metal/target/equinix-openapi-metal-1.0.0.jar:equinix-openapi-metal/target/lib/*" examples/ListMetros.java <API KEY TOKEN>
Using openapi generator v3 docker image :
make docker_run
Using openapi generator v3 git repo :
make git_run
Note : Both docker and git pulls latest version of openapi generator.
- Make changes in
spec/oas3.patched.json
. - Create a patch file in metal-java:
cd spec git diff -U10 oas3.patched.json > ../patches/spec.fetched.json/<patchfilename> cd ..
patchfilename
should be in format:<patch_index>-<short_patch_decription_or_identifier>.patch
- Run
make docker_run
to reapply the changes to oas spec. - Before pushing changes, commit
spec/oas3.patched.json
along with the patch file.
Complex workflows requiring multiple granular, autogenerated apis can be implemented as part of Operator classes. These classes are included in the path equinix-openapi-metal/src/main/java/com/equinix/workflow
when building the sdk. An example use case for operator implementation can be for APIs requiring polling logic to fetch updated resource state.
- Follow steps mentioned in section "Generate and build equinix metal java client" to generate and build the sdk in your cloned local.
- Implement operator classes inside
equinix-openapi-metal/src/main/java/com/equinix/workflow
. - Follow steps mentioned in section "Functional tests for complex workflows" to add functional tests for the same.
- After testing and debugging in your local, move the newly added operator classes to
internal/workflow
. - Commit your changes made in
internal/workflow
,.github/workflows
,equinix-functional-tests
and push them to the remote branch. The auto commit git workflow would automatically build and generate the sdk in the remote branch with the newly added workflows. - Post completion of the auto commit workflow in your remote branch, you can do a
git rebase origin/your-branch-name
to sync your local.
- You can implement functional tests for your operator classes inside
equinix-functional-test/src/test/java/com/equinix/test/functional
. Check existing operator test implementations for reference. - Input properties required for the tests can be mentioned in a separate .properties file inside
equinix-functional-test/src/test/resources
. - To run functional tests locally:
- Pre-requisite: Steps 1 and 2 in section "Steps for development" have been followed.
- Open a terminal in
equinix-openapi-metal
and runmvn clean install --file pom.xml
to install the sdk in your local. - Add a run/debug configuration in your IDE. For example in IntelliJ, to run TestDeviceOperator functional tests locally in IntelliJ, add a maven configuration with :
- Configuration name set to
equinix-run-device-functional-tests
- Working directory set to
equinix-functional-test
- Run command set to
clean test -Dtest=com.equinix.test.functional.TestDeviceOperator.java --file pom.xml
- If using environment variables, they can be added in Java options.
- Configuration name set to
- Alternatively, you can do step iii through terminal directly.
- For every new functional test, a separate github workflow .yaml should be defined inside
.github/workflows
. These can be run from Github's actions UI directly. Check existing workflow definitions for reference.