Skip to main content

Generating API Client Code

OpenAPI provides over fifty client generators that can help developers generate client code from any specification file. This document will provide a step-to-step guide for generating an API client library using the Connectivity OpenAPI specification. In this example, a java client will be generated, but you can choose your own programming language here.

Requirements​

  1. Any suitable IDE
  2. Java 1.8+
  3. Maven (3.8.3+)

Locate and download the Specs​

Locate the OpenApi Specification on the top right-hand section in Holidu Developer Hub website for access to the latest versions of all Connectivity API specification files.

Click on the Connectivity API-v2.0 to access the spec content

Create a .json file in the resource folder of your project and copy the content of the selected spec into the created file.

Generate client code​

We will use the openApi codegen maven pluggin. as a code generator in this guide (for information about other generators, visit https://openapi-generator.tech/docs/generators). Simply update the build section of your pom.xml with the code snippet specified below.

<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>${openapi-generator.version}</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/openapi/connectivity_api.json</inputSpec>
<generatorName>java</generatorName>
<configOptions>
<sourceFolder>src/gen/main/java</sourceFolder>
<dateLibrary>java8</dateLibrary>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>

A client API library will be generated during the generate phase of your build process.

For more information about configuration options associated with the openApi codegen maven pluggin visit https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator-maven-plugin/README.md

A compilation error might be thrown when trying to generate the client code. To resolve this, ensure your project contains the following artifacts: com.google.code.gson:gson, io.swagger:swagger-annotations, com.squareup.okhttp3:okhttp-tls, com.squareup.okhttp3:logging-interceptor and io.gsonfire:gson-fire

The generated API client can be located in the target folder.

Find a README.md file in the path indicated below for a comprehensive guide to using this generated API in your projects.