A client library, or client SDK, gives API consumers language-specific methods for calling an API instead of making direct HTTP requests themselves. It wraps an underlying HTTP client; generated methods and models let consumers work with language objects rather than assemble every request by hand. section 6.2.6 section 9.3
Keep the library aligned with the API contract. When an OpenAPI definition is the source of truth, update it as requirements change, then generate the server stub, client SDK, and API reference from that definition. A code-first workflow can instead generate the OpenAPI definition from application code before creating the SDK and reference. Either route reduces opportunities for independently maintained artifacts to drift; it does not replace testing the running API for conformance. section 6.0 section 6.1 section 6.3
Listing 6.7 Generating the Java API client SDK
openapi-generator-cli generate --input-spec ../product-catalog-v1-1.oas.yaml --generator-name java #1 --output java-client --additional-properties= library=okhttp-gson, #2 invokerPackage=com.acmepetsupplies.client, apiPackage=com.acmepetsupplies.api, modelPackage=com.acmepetsupplies.model, groupId=com.acmepetsupplies, #3 artifactId=acmepetsupplies-java-client #4
This OpenAPI Generator command takes an OpenAPI file, selects the Java generator and an OkHttp-based library, and sets the output directory and package coordinates. Change those inputs and options for the SDK you intend to publish. section 6.2.6
Call the generated Java client
The generated ProductsApi exposes viewProduct(id), which returns a Product through the configured HTTP client. In the sample test, set the base path, Host header, and API key, then call viewProduct with a UUID and print the response. Run mvn test to try the library against the configured endpoint. Because this test prints a response without assertions, it is a usage demonstration, not proof that the API conforms to its definition. section 6.2.6
Generate SDKs in the build stage from a bundled OpenAPI definition using a generator such as OpenAPI Generator CLI, or connect a code-generation service to the deployment pipeline. Store generated packages in a binary artifact repository so teams and applications can obtain them. Generation is only part of delivery: the pipeline also needs to support testing and documentation. section 9.3 section 9.3.2
A well-built SDK can provide authentication helpers and hide sequences such as renewing an expired token before completing a call. Decide whether that experience warrants provider ownership: each supported language brings idiomatic coding, bug-fix, testing, and release work. API changes can require new SDK versions, while consumers may remain on older ones. Providing the definition and documentation for consumer-built clients, or relying on community-maintained SDKs, reduces provider ownership but gives up some control over the integration experience. section 9.3 section 9.3.1 section 9.3.2




