diff --git a/docs-java/features/rest/generate-rest-client.mdx b/docs-java/features/rest/generate-rest-client.mdx index f767a134b23..0aebc7fe081 100644 --- a/docs-java/features/rest/generate-rest-client.mdx +++ b/docs-java/features/rest/generate-rest-client.mdx @@ -30,8 +30,31 @@ However, languages that use non-latin characters, specifically languages that re ::: +Starting from version 5.26.0, the OpenAPI generator supports two HTTP client libraries: **Spring RestTemplate (default)** and **Apache HttpClient 5**. +To use Apache HttpClient, checkout [Declaring Dependencies](#declaring-dependencies) and plugin configuration in section [Choosing the HTTP Client Library](#choosing-the-http-client-library). + +## Declaring Dependencies + The generated Java classes need the following dependency to be present in your project: + + + +```xml + + com.sap.cloud.sdk.datamodel + openapi-core-apache + +``` + +To use the generated client library, either the SAP Cloud SDK BOM should be part of your project's `` section, or the version for the `openapi-core-apache` artifact must be mentioned explicitly here. + + + + ```xml com.sap.cloud.sdk.datamodel @@ -41,10 +64,17 @@ The generated Java classes need the following dependency to be present in your p To use the generated client library, either the SAP Cloud SDK BOM should be part of your project's `` section, or the version for the `openapi-core` artifact must be mentioned explicitly here. + + + ## Generated Java Classes and Usage In this section, we will explain how to use the OpenAPI Generator Maven Plugin. -A sample result can be seen in our [open-source public repository](https://github.com/SAP/cloud-sdk-java/tree/main/datamodel/openapi/openapi-api-sample) with the _SodaStore_ OpenAPI. +A sample result can be seen in our [open-source public repository](https://github.com/SAP/cloud-sdk-java/tree/main/datamodel/openapi/openapi-api-sample) with the _SodaStore_ OpenAPI: + +- [Apache HttpClient sample](https://github.com/SAP/cloud-sdk-java/tree/main/datamodel/openapi/openapi-api-apache-sample) +- [Spring RestTemplate sample](https://github.com/SAP/cloud-sdk-java/tree/main/datamodel/openapi/openapi-api-sample) + Given the `sodastore.json` as input the following service classes get generated: ``` @@ -63,7 +93,50 @@ openapi-api-sample/ The generated API can be used like the following: + + + + ```java +import com.sap.cloud.sdk.services.openapi.apache.apiclient.ApiClient; + +Destination destination; + +// create the service with a destination +SodasApi service = new SodasApi(destination); + +// create an entity object +SodaWithId soda = new SodaWithId().id(0L).name("Cola").brand("SAP-Cola").quantity(100).price(1.5f); + +// execute request for entity update +service.sodasPut(soda); +``` + +Services can be instantiated in different ways: + +```java +new SodasApi( ) +new SodasApi( Destination ) +new SodasApi( new ApiClient() ) +new SodasApi( new ApiClient(Destination) ) +new SodasApi( new ApiClient(ClosableHttpClient) ) +``` + +The [`ApiClient`](https://sap.github.io/cloud-sdk/java-api/v5/com/sap/cloud/sdk/services/openapi/apache/ApiClient.html) allows for versatile customization. +Default service base-path, object mapper and file download location can be assigned. +When using `Destination`, the base-path is extracted automatically from the provided destination. +Alternatively, the `ClosableHttpClient` based constructor can be used for fully customized requests. + + + + + +```java +import com.sap.cloud.sdk.services.openapi.apiclient.ApiClient; + Destination destination; // create the service with a destination @@ -90,6 +163,9 @@ Default service base-path, user-agent and request headers can be assigned. When using `Destination` these parameters are extracted automatically from the provided destination. Alternatively, the `RestTemplate` based constructor can be used for fully customized requests. + + + ## Using the OpenAPI Generator Maven Plugin To use the Maven plugin following XML snippet should be added to the POM file of your project: @@ -100,7 +176,7 @@ To use the Maven plugin following XML snippet should be added to the POM file of openapi-generator-maven-plugin ${sap-cloud-sdk.version} - + generate @@ -111,7 +187,7 @@ To use the Maven plugin following XML snippet should be added to the POM file of ${project.basedir}/sample.yaml ${project.basedir}/openapi - com.mycompany.openapi.sample.api + com.mycompany.openapi.sample.api com.mycompany.openapi.sample.model released