# Generating an API Client Library source: https://developer.mastercard.com/ob-accept-payments/documentation/testing-and-integration/generating-api-client-library/index.md You can generate a client library from any of the OpenAPI specifications in the [API Reference](https://developer.mastercard.com/ob-accept-payments/documentation/api-reference/index.md). Generate a separate client for each API specification you use. A generated client provides models and methods for calling each endpoint, which reduces the amount of integration code you need to write. This guide uses the Accept Payments API specification and Java as an example. OpenAPI Generator supports other languages and frameworks. Refer to the [Generators List](https://openapi-generator.tech/docs/generators/) for the available options. ## Prerequisites {#prerequisites} Before you begin: * Install Java 11 or later. * Install [OpenAPI Generator](https://openapi-generator.tech/docs/installation). * For this example, download the [Accept Payments API specification](https://static.developer.mastercard.com/content/ob-accept-payments/swagger/apv3%206.yaml) and save it as `accept-payments.yaml`. ## Generate the Client Library {#generate-the-client-library} Run this command from the folder containing `accept-payments.yaml`: ```shell openapi-generator-cli generate \ -i accept-payments.yaml \ -g java \ -o generated-client \ --additional-properties=useOneOfDiscriminatorLookup=true ``` The `useOneOfDiscriminatorLookup=true` option is required because the Accept Payments API uses models with `oneOf` and discriminator mappings. The option enables the generated client to use those mappings when it deserializes the models. ## Correct the `executionMethod` Default {#correct-the-executionmethod-default} Warning: OpenAPI Generator can generate an invalid Java default for `executionMethod`. This issue was reproduced with OpenAPI Generator 7.25.0. Apply the following correction before you build the client. In these generated files: * `CreateAcceptPaymentDanishDomesticCreditTransfer.java` * `CreateAcceptPaymentDanishDomesticCreditTransferDetails.java` Change: ```java private String executionMethod = Standard; ``` To: ```java private String executionMethod = "Standard"; ``` ## Build the Client Library {#build-the-client-library} The generated project includes Maven and Gradle build files. For example, run the Gradle wrapper from the `generated-client` folder. On macOS or Linux: ```shell ./gradlew clean build ``` On Windows: ```powershell .\gradlew.bat clean build ``` ## Add Authentication {#add-authentication} The generated client does not request an access token for you. Follow [Authentication](https://developer.mastercard.com/ob-accept-payments/documentation/api-basics/index.md#authentication) to request an access token with the scopes required for the endpoints you use. Set the Sandbox base URL and access token on the generated `ApiClient`: ```java import org.openapitools.client.ApiClient; import org.openapitools.client.api.AcceptPaymentsApi; ApiClient apiClient = new ApiClient(); apiClient.setBasePath( "https://mtf.api.openbanking.mastercard.eu/accept-payments"); apiClient.setBearerToken(""); AcceptPaymentsApi acceptPaymentsApi = new AcceptPaymentsApi(apiClient); ``` The generated API classes correspond to the endpoint groups in the [API Reference](https://developer.mastercard.com/ob-accept-payments/documentation/api-reference/index.md). Use the methods and models in those classes to make API requests.