diff --git a/datamodel/openapi/openapi-api-apache-sample/pom.xml b/datamodel/openapi/openapi-api-apache-sample/pom.xml index 0872d59c6..595c907ce 100644 --- a/datamodel/openapi/openapi-api-apache-sample/pom.xml +++ b/datamodel/openapi/openapi-api-apache-sample/pom.xml @@ -8,23 +8,36 @@ openapi-parent 5.26.0-SNAPSHOT - openapi-api-apache-sample - - - 22 - 22 - UTF-8 - - + Data Model - OpenAPI Services - Sample API + Sample generated API classes of the OpenAPI VDM + https://sap.github.io/cloud-sdk/docs/java/getting-started + + SAP SE + https://www.sap.com + + + + The Apache Software License, Version 2.0 + https://www.apache.org/licenses/LICENSE-2.0.txt + + + + + SAP + cloudsdk@sap.com + SAP SE + https://www.sap.com + + com.sap.cloud.sdk.datamodel openapi-core - com.google.guava - guava + com.sap.cloud.sdk.cloudplatform + cloudplatform-connectivity com.fasterxml.jackson.core @@ -41,13 +54,25 @@ com.sap.cloud.sdk.datamodel openapi-generator-maven-plugin + released ${project.basedir}/src/main/java - true true - sample-generation + sample-apache-swagger-v2 + generate-sources + + generate + + + ${project.basedir}/src/main/resources/petstore-swagger2.json + com.sap.cloud.sdk.datamodel.openapi.petstore.api + com.sap.cloud.sdk.datamodel.openapi.petstore.model + + + + sample-apache-openapi-v3 generate @@ -57,19 +82,17 @@ com.sap.cloud.sdk.datamodel.openapi.apache.sample.api com.sap.cloud.sdk.datamodel.openapi.apache.sample.model - true - com.sap.cloud.sdk.services.openapi.apache apache-httpclient false - true - true - true - \. - 3 - + create protected + true true + true + true + true + true diff --git a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/api/OrdersApi.java b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/api/OrdersApi.java index a68fbf053..65602b693 100644 --- a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/api/OrdersApi.java +++ b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/api/OrdersApi.java @@ -1,102 +1,104 @@ /* - * SodaStore API - * API for managing soda products and orders in SodaStore. - * - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ +* Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. +*/ package com.sap.cloud.sdk.datamodel.openapi.apache.sample.api; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.StringJoiner; +import javax.annotation.Nonnull; + import com.fasterxml.jackson.core.type.TypeReference; +import com.sap.cloud.sdk.cloudplatform.connectivity.Destination; import com.sap.cloud.sdk.datamodel.openapi.apache.sample.model.Order; import com.sap.cloud.sdk.services.openapi.apache.ApiClient; -import com.sap.cloud.sdk.services.openapi.apache.ApiException; import com.sap.cloud.sdk.services.openapi.apache.BaseApi; -import com.sap.cloud.sdk.services.openapi.apache.Configuration; import com.sap.cloud.sdk.services.openapi.apache.Pair; +import com.sap.cloud.sdk.services.openapi.core.OpenApiRequestException; +/** + * SodaStore API in version 1.0.0. + * + * API for managing soda products and orders in SodaStore. + */ public class OrdersApi extends BaseApi { + /** + * Instantiates this API class to invoke operations on the SodaStore API + */ public OrdersApi() { - super(Configuration.getDefaultApiClient()); } - public OrdersApi( ApiClient apiClient ) + /** + * Instantiates this API class to invoke operations on the SodaStore API. + * + * @param httpDestination + * The destination that API should be used with + */ + public OrdersApi( @Nonnull final Destination httpDestination ) { - super(apiClient); + super(httpDestination); } /** - * Create a new order + * Instantiates this API class to invoke operations on the SodaStore API based on a given {@link ApiClient}. * - * @param order - * The order details (required) - * @return Order - * @throws ApiException - * if fails to make API call + * @param apiClient + * ApiClient to invoke the API on */ - public Order ordersPost( @javax.annotation.Nonnull Order order ) - throws ApiException + public OrdersApi( @Nonnull final ApiClient apiClient ) { - return this.ordersPost(order, Collections.emptyMap()); + super(apiClient); } /** + *

* Create a new order + *

+ *

+ * 201 - The created order * * @param order - * The order details (required) - * @param additionalHeaders - * additionalHeaders for this call + * The order details * @return Order - * @throws ApiException - * if fails to make API call + * @throws OpenApiRequestException + * if an error occurs while attempting to invoke the API */ - public Order ordersPost( @javax.annotation.Nonnull Order order, Map additionalHeaders ) - throws ApiException + @Nonnull + public Order ordersPost( @Nonnull final Order order ) + throws OpenApiRequestException { - Object localVarPostBody = order; + final Object localVarPostBody = order; // verify the required parameter 'order' is set if( order == null ) { - throw new ApiException(400, "Missing the required parameter 'order' when calling ordersPost"); + throw new OpenApiRequestException("Missing the required parameter 'order' when calling ordersPost") + .statusCode(400); } // create path and map variables - String localVarPath = "/orders"; + final String localVarPath = "/orders"; - StringJoiner localVarQueryStringJoiner = new StringJoiner("&"); + final StringJoiner localVarQueryStringJoiner = new StringJoiner("&"); String localVarQueryParameterBaseName; - List localVarQueryParams = new ArrayList(); - List localVarCollectionQueryParams = new ArrayList(); - Map localVarHeaderParams = new HashMap(); - Map localVarCookieParams = new HashMap(); - Map localVarFormParams = new HashMap(); - - localVarHeaderParams.putAll(additionalHeaders); + final List localVarQueryParams = new ArrayList(); + final List localVarCollectionQueryParams = new ArrayList(); + final Map localVarHeaderParams = new HashMap(); + final Map localVarFormParams = new HashMap(); final String[] localVarAccepts = { "application/json" }; - final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts); + final String localVarAccept = ApiClient.selectHeaderAccept(localVarAccepts); final String[] localVarContentTypes = { "application/json" }; - final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes); - - String[] localVarAuthNames = new String[] { "apiKeyAuth" }; + final String localVarContentType = ApiClient.selectHeaderContentType(localVarContentTypes); - TypeReference localVarReturnType = new TypeReference() + final TypeReference localVarReturnType = new TypeReference() { }; return apiClient @@ -108,55 +110,9 @@ public Order ordersPost( @javax.annotation.Nonnull Order order, Map T invokeAPI( - String url, - String method, - Object request, - TypeReference returnType, - Map additionalHeaders ) - throws ApiException - { - String localVarPath = url.replace(apiClient.getBaseURL(), ""); - StringJoiner localVarQueryStringJoiner = new StringJoiner("&"); - List localVarQueryParams = new ArrayList(); - List localVarCollectionQueryParams = new ArrayList(); - Map localVarHeaderParams = new HashMap(); - Map localVarCookieParams = new HashMap(); - Map localVarFormParams = new HashMap(); - - localVarHeaderParams.putAll(additionalHeaders); - - final String[] localVarAccepts = { "application/json" }; - final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts); - - final String[] localVarContentTypes = { "application/json" }; - final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes); - - String[] localVarAuthNames = new String[] { "apiKeyAuth" }; - - return apiClient - .invokeAPI( - localVarPath, - method, - localVarQueryParams, - localVarCollectionQueryParams, - localVarQueryStringJoiner.toString(), - request, - localVarHeaderParams, - localVarCookieParams, - localVarFormParams, - localVarAccept, - localVarContentType, - localVarAuthNames, - returnType); - } } diff --git a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/api/SodasApi.java b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/api/SodasApi.java index 9a5265ac2..fbd776b6c 100644 --- a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/api/SodasApi.java +++ b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/api/SodasApi.java @@ -1,108 +1,113 @@ /* - * SodaStore API - * API for managing soda products and orders in SodaStore. - * - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ +* Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. +*/ package com.sap.cloud.sdk.datamodel.openapi.apache.sample.api; import java.io.File; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.StringJoiner; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + import com.fasterxml.jackson.core.type.TypeReference; +import com.sap.cloud.sdk.cloudplatform.connectivity.Destination; import com.sap.cloud.sdk.datamodel.openapi.apache.sample.model.Soda; import com.sap.cloud.sdk.datamodel.openapi.apache.sample.model.SodaWithId; import com.sap.cloud.sdk.services.openapi.apache.ApiClient; -import com.sap.cloud.sdk.services.openapi.apache.ApiException; import com.sap.cloud.sdk.services.openapi.apache.BaseApi; -import com.sap.cloud.sdk.services.openapi.apache.Configuration; import com.sap.cloud.sdk.services.openapi.apache.Pair; +import com.sap.cloud.sdk.services.openapi.core.OpenApiRequestException; +/** + * SodaStore API in version 1.0.0. + * + * API for managing soda products and orders in SodaStore. + */ public class SodasApi extends BaseApi { + /** + * Instantiates this API class to invoke operations on the SodaStore API + */ public SodasApi() { - super(Configuration.getDefaultApiClient()); } - public SodasApi( ApiClient apiClient ) + /** + * Instantiates this API class to invoke operations on the SodaStore API. + * + * @param httpDestination + * The destination that API should be used with + */ + public SodasApi( @Nonnull final Destination httpDestination ) { - super(apiClient); + super(httpDestination); } /** - * Download soda product data as binary + * Instantiates this API class to invoke operations on the SodaStore API based on a given {@link ApiClient}. * - * @param id - * ID of the soda product to download (required) - * @return File - * @throws ApiException - * if fails to make API call + * @param apiClient + * ApiClient to invoke the API on */ - public File sodasDownloadIdGet( @javax.annotation.Nonnull Long id ) - throws ApiException + public SodasApi( @Nonnull final ApiClient apiClient ) { - return this.sodasDownloadIdGet(id, Collections.emptyMap()); + super(apiClient); } /** + *

* Download soda product data as binary + *

+ *

+ * 200 - Successful response + *

+ * 404 - Soda product not found * * @param id - * ID of the soda product to download (required) - * @param additionalHeaders - * additionalHeaders for this call + * ID of the soda product to download * @return File - * @throws ApiException - * if fails to make API call + * @throws OpenApiRequestException + * if an error occurs while attempting to invoke the API */ - public File sodasDownloadIdGet( @javax.annotation.Nonnull Long id, Map additionalHeaders ) - throws ApiException + @Nonnull + public File sodasDownloadIdGet( @Nonnull final Long id ) + throws OpenApiRequestException { - Object localVarPostBody = null; + final Object localVarPostBody = null; // verify the required parameter 'id' is set if( id == null ) { - throw new ApiException(400, "Missing the required parameter 'id' when calling sodasDownloadIdGet"); + throw new OpenApiRequestException("Missing the required parameter 'id' when calling sodasDownloadIdGet") + .statusCode(400); } // create path and map variables - String localVarPath = + final String localVarPath = "/sodas/download/{id}" - .replaceAll("\\{" + "id" + "\\}", apiClient.escapeString(apiClient.parameterToString(id))); + .replaceAll("\\{" + "id" + "\\}", ApiClient.escapeString(ApiClient.parameterToString(id))); - StringJoiner localVarQueryStringJoiner = new StringJoiner("&"); + final StringJoiner localVarQueryStringJoiner = new StringJoiner("&"); String localVarQueryParameterBaseName; - List localVarQueryParams = new ArrayList(); - List localVarCollectionQueryParams = new ArrayList(); - Map localVarHeaderParams = new HashMap(); - Map localVarCookieParams = new HashMap(); - Map localVarFormParams = new HashMap(); - - localVarHeaderParams.putAll(additionalHeaders); + final List localVarQueryParams = new ArrayList(); + final List localVarCollectionQueryParams = new ArrayList(); + final Map localVarHeaderParams = new HashMap(); + final Map localVarFormParams = new HashMap(); final String[] localVarAccepts = { "application/octet-stream" }; - final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts); + final String localVarAccept = ApiClient.selectHeaderAccept(localVarAccepts); final String[] localVarContentTypes = { }; - final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes); - - String[] localVarAuthNames = new String[] { "apiKeyAuth", "bearerAuth" }; + final String localVarContentType = ApiClient.selectHeaderContentType(localVarContentTypes); - TypeReference localVarReturnType = new TypeReference() + final TypeReference localVarReturnType = new TypeReference() { }; return apiClient @@ -114,65 +119,48 @@ public File sodasDownloadIdGet( @javax.annotation.Nonnull Long id, Map * Get all soda products + *

+ *

+ * 200 - A list of soda products * * @return List<SodaWithId> - * @throws ApiException - * if fails to make API call + * @throws OpenApiRequestException + * if an error occurs while attempting to invoke the API */ + @Nonnull public List sodasGet() - throws ApiException - { - return this.sodasGet(Collections.emptyMap()); - } - - /** - * Get all soda products - * - * @param additionalHeaders - * additionalHeaders for this call - * @return List<SodaWithId> - * @throws ApiException - * if fails to make API call - */ - public List sodasGet( Map additionalHeaders ) - throws ApiException + throws OpenApiRequestException { - Object localVarPostBody = null; + final Object localVarPostBody = null; // create path and map variables - String localVarPath = "/sodas"; + final String localVarPath = "/sodas"; - StringJoiner localVarQueryStringJoiner = new StringJoiner("&"); + final StringJoiner localVarQueryStringJoiner = new StringJoiner("&"); String localVarQueryParameterBaseName; - List localVarQueryParams = new ArrayList(); - List localVarCollectionQueryParams = new ArrayList(); - Map localVarHeaderParams = new HashMap(); - Map localVarCookieParams = new HashMap(); - Map localVarFormParams = new HashMap(); - - localVarHeaderParams.putAll(additionalHeaders); + final List localVarQueryParams = new ArrayList(); + final List localVarCollectionQueryParams = new ArrayList(); + final Map localVarHeaderParams = new HashMap(); + final Map localVarFormParams = new HashMap(); final String[] localVarAccepts = { "application/json" }; - final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts); + final String localVarAccept = ApiClient.selectHeaderAccept(localVarAccepts); final String[] localVarContentTypes = { }; - final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes); - - String[] localVarAuthNames = new String[] { "apiKeyAuth" }; + final String localVarContentType = ApiClient.selectHeaderContentType(localVarContentTypes); - TypeReference> localVarReturnType = new TypeReference>() + final TypeReference> localVarReturnType = new TypeReference>() { }; return apiClient @@ -184,75 +172,59 @@ public List sodasGet( Map additionalHeaders ) localVarQueryStringJoiner.toString(), localVarPostBody, localVarHeaderParams, - localVarCookieParams, localVarFormParams, localVarAccept, localVarContentType, - localVarAuthNames, localVarReturnType); } /** + *

* Get a specific soda product by ID + *

+ *

+ * 200 - The soda product + *

+ * 404 - Soda product not found * * @param id - * ID of the soda product to retrieve (required) + * ID of the soda product to retrieve * @return SodaWithId - * @throws ApiException - * if fails to make API call + * @throws OpenApiRequestException + * if an error occurs while attempting to invoke the API */ - public SodaWithId sodasIdGet( @javax.annotation.Nonnull Long id ) - throws ApiException + @Nonnull + public SodaWithId sodasIdGet( @Nonnull final Long id ) + throws OpenApiRequestException { - return this.sodasIdGet(id, Collections.emptyMap()); - } - - /** - * Get a specific soda product by ID - * - * @param id - * ID of the soda product to retrieve (required) - * @param additionalHeaders - * additionalHeaders for this call - * @return SodaWithId - * @throws ApiException - * if fails to make API call - */ - public SodaWithId sodasIdGet( @javax.annotation.Nonnull Long id, Map additionalHeaders ) - throws ApiException - { - Object localVarPostBody = null; + final Object localVarPostBody = null; // verify the required parameter 'id' is set if( id == null ) { - throw new ApiException(400, "Missing the required parameter 'id' when calling sodasIdGet"); + throw new OpenApiRequestException("Missing the required parameter 'id' when calling sodasIdGet") + .statusCode(400); } // create path and map variables - String localVarPath = - "/sodas/{id}".replaceAll("\\{" + "id" + "\\}", apiClient.escapeString(apiClient.parameterToString(id))); + final String localVarPath = + "/sodas/{id}".replaceAll("\\{" + "id" + "\\}", ApiClient.escapeString(ApiClient.parameterToString(id))); - StringJoiner localVarQueryStringJoiner = new StringJoiner("&"); + final StringJoiner localVarQueryStringJoiner = new StringJoiner("&"); String localVarQueryParameterBaseName; - List localVarQueryParams = new ArrayList(); - List localVarCollectionQueryParams = new ArrayList(); - Map localVarHeaderParams = new HashMap(); - Map localVarCookieParams = new HashMap(); - Map localVarFormParams = new HashMap(); - - localVarHeaderParams.putAll(additionalHeaders); + final List localVarQueryParams = new ArrayList(); + final List localVarCollectionQueryParams = new ArrayList(); + final Map localVarHeaderParams = new HashMap(); + final Map localVarFormParams = new HashMap(); final String[] localVarAccepts = { "application/json" }; - final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts); + final String localVarAccept = ApiClient.selectHeaderAccept(localVarAccepts); final String[] localVarContentTypes = { }; - final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes); - - String[] localVarAuthNames = new String[] { "apiKeyAuth" }; + final String localVarContentType = ApiClient.selectHeaderContentType(localVarContentTypes); - TypeReference localVarReturnType = new TypeReference() + final TypeReference localVarReturnType = new TypeReference() { }; return apiClient @@ -264,72 +236,58 @@ public SodaWithId sodasIdGet( @javax.annotation.Nonnull Long id, Map * Update a specific soda product by ID + *

+ *

+ * 200 - The updated soda product + *

+ * 204 - Nothing has changed + *

+ * 404 - Soda product not found * * @param sodaWithId - * The updated soda product (required) - * @return Soda - * @throws ApiException - * if fails to make API call - */ - public Soda sodasPut( @javax.annotation.Nonnull SodaWithId sodaWithId ) - throws ApiException - { - return this.sodasPut(sodaWithId, Collections.emptyMap()); - } - - /** - * Update a specific soda product by ID - * - * @param sodaWithId - * The updated soda product (required) - * @param additionalHeaders - * additionalHeaders for this call + * The updated soda product * @return Soda - * @throws ApiException - * if fails to make API call + * @throws OpenApiRequestException + * if an error occurs while attempting to invoke the API */ - public Soda sodasPut( @javax.annotation.Nonnull SodaWithId sodaWithId, Map additionalHeaders ) - throws ApiException + @Nullable + public Soda sodasPut( @Nonnull final SodaWithId sodaWithId ) + throws OpenApiRequestException { - Object localVarPostBody = sodaWithId; + final Object localVarPostBody = sodaWithId; // verify the required parameter 'sodaWithId' is set if( sodaWithId == null ) { - throw new ApiException(400, "Missing the required parameter 'sodaWithId' when calling sodasPut"); + throw new OpenApiRequestException("Missing the required parameter 'sodaWithId' when calling sodasPut") + .statusCode(400); } // create path and map variables - String localVarPath = "/sodas"; + final String localVarPath = "/sodas"; - StringJoiner localVarQueryStringJoiner = new StringJoiner("&"); + final StringJoiner localVarQueryStringJoiner = new StringJoiner("&"); String localVarQueryParameterBaseName; - List localVarQueryParams = new ArrayList(); - List localVarCollectionQueryParams = new ArrayList(); - Map localVarHeaderParams = new HashMap(); - Map localVarCookieParams = new HashMap(); - Map localVarFormParams = new HashMap(); - - localVarHeaderParams.putAll(additionalHeaders); + final List localVarQueryParams = new ArrayList(); + final List localVarCollectionQueryParams = new ArrayList(); + final Map localVarHeaderParams = new HashMap(); + final Map localVarFormParams = new HashMap(); final String[] localVarAccepts = { "application/json" }; - final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts); + final String localVarAccept = ApiClient.selectHeaderAccept(localVarAccepts); final String[] localVarContentTypes = { "application/json" }; - final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes); - - String[] localVarAuthNames = new String[] { "apiKeyAuth" }; + final String localVarContentType = ApiClient.selectHeaderContentType(localVarContentTypes); - TypeReference localVarReturnType = new TypeReference() + final TypeReference localVarReturnType = new TypeReference() { }; return apiClient @@ -341,55 +299,9 @@ public Soda sodasPut( @javax.annotation.Nonnull SodaWithId sodaWithId, Map T invokeAPI( - String url, - String method, - Object request, - TypeReference returnType, - Map additionalHeaders ) - throws ApiException - { - String localVarPath = url.replace(apiClient.getBaseURL(), ""); - StringJoiner localVarQueryStringJoiner = new StringJoiner("&"); - List localVarQueryParams = new ArrayList(); - List localVarCollectionQueryParams = new ArrayList(); - Map localVarHeaderParams = new HashMap(); - Map localVarCookieParams = new HashMap(); - Map localVarFormParams = new HashMap(); - - localVarHeaderParams.putAll(additionalHeaders); - - final String[] localVarAccepts = { "application/json" }; - final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts); - - final String[] localVarContentTypes = { "application/json" }; - final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes); - - String[] localVarAuthNames = new String[] { "apiKeyAuth" }; - - return apiClient - .invokeAPI( - localVarPath, - method, - localVarQueryParams, - localVarCollectionQueryParams, - localVarQueryStringJoiner.toString(), - request, - localVarHeaderParams, - localVarCookieParams, - localVarFormParams, - localVarAccept, - localVarContentType, - localVarAuthNames, - returnType); - } } diff --git a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/AllOf.java b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/AllOf.java index d6462cc87..ced49cf22 100644 --- a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/AllOf.java +++ b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/AllOf.java @@ -28,13 +28,11 @@ import com.fasterxml.jackson.annotation.JsonAnySetter; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.common.annotations.Beta; /** * AllOf */ - -@Beta // CHECKSTYLE:OFF +// CHECKSTYLE:OFF public class AllOf // CHECKSTYLE:ON { diff --git a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/AnyOf.java b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/AnyOf.java index 97f8d677f..f1f51e2d1 100644 --- a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/AnyOf.java +++ b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/AnyOf.java @@ -28,13 +28,11 @@ import com.fasterxml.jackson.annotation.JsonAnySetter; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.common.annotations.Beta; /** * AnyOf */ - -@Beta // CHECKSTYLE:OFF +// CHECKSTYLE:OFF public class AnyOf // CHECKSTYLE:ON { diff --git a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/Bar.java b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/Bar.java index 55111820b..d7b296253 100644 --- a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/Bar.java +++ b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/Bar.java @@ -30,13 +30,11 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonValue; -import com.google.common.annotations.Beta; /** * Bar */ - -@Beta // CHECKSTYLE:OFF +// CHECKSTYLE:OFF public class Bar implements OneOfWithEnumDiscriminator // CHECKSTYLE:ON { diff --git a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/Cola.java b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/Cola.java index 7d5bb90be..4d89ee770 100644 --- a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/Cola.java +++ b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/Cola.java @@ -28,13 +28,11 @@ import com.fasterxml.jackson.annotation.JsonAnySetter; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.common.annotations.Beta; /** * Cola */ - -@Beta // CHECKSTYLE:OFF +// CHECKSTYLE:OFF public class Cola implements OneOf, OneOfWithDiscriminator, OneOfWithDiscriminatorAndMapping // CHECKSTYLE:ON { diff --git a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/ColaBarCode.java b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/ColaBarCode.java index 6ca5fa9dc..eb8bf12c2 100644 --- a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/ColaBarCode.java +++ b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/ColaBarCode.java @@ -20,12 +20,9 @@ import javax.annotation.Nonnull; -import com.google.common.annotations.Beta; - /** * ColaBarCode */ -@Beta public interface ColaBarCode { /** diff --git a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/ColaLogo.java b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/ColaLogo.java index 84624d0e3..3191d9a4a 100644 --- a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/ColaLogo.java +++ b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/ColaLogo.java @@ -19,12 +19,9 @@ import javax.annotation.Nonnull; -import com.google.common.annotations.Beta; - /** * ColaLogo */ -@Beta public interface ColaLogo { /** diff --git a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/Fanta.java b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/Fanta.java index 0215af3cb..aad7447f3 100644 --- a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/Fanta.java +++ b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/Fanta.java @@ -28,13 +28,11 @@ import com.fasterxml.jackson.annotation.JsonAnySetter; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.common.annotations.Beta; /** * Fanta */ - -@Beta // CHECKSTYLE:OFF +// CHECKSTYLE:OFF public class Fanta implements OneOf, OneOfWithDiscriminator, OneOfWithDiscriminatorAndMapping // CHECKSTYLE:ON { diff --git a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/FantaFlavor.java b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/FantaFlavor.java index 143119694..36883f283 100644 --- a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/FantaFlavor.java +++ b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/FantaFlavor.java @@ -21,12 +21,10 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonValue; -import com.google.common.annotations.Beta; /** * FantaFlavor */ -@Beta public interface FantaFlavor { /** diff --git a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/FlavorType.java b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/FlavorType.java index e95740c27..150bb8dc4 100644 --- a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/FlavorType.java +++ b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/FlavorType.java @@ -28,13 +28,11 @@ import com.fasterxml.jackson.annotation.JsonAnySetter; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.common.annotations.Beta; /** * FlavorType */ - -@Beta // CHECKSTYLE:OFF +// CHECKSTYLE:OFF public class FlavorType // CHECKSTYLE:ON { diff --git a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/Foo.java b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/Foo.java index 963d22d89..6c52ebe13 100644 --- a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/Foo.java +++ b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/Foo.java @@ -30,13 +30,11 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonValue; -import com.google.common.annotations.Beta; /** * Foo */ - -@Beta // CHECKSTYLE:OFF +// CHECKSTYLE:OFF public class Foo implements OneOfWithEnumDiscriminator // CHECKSTYLE:ON { diff --git a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/OneOf.java b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/OneOf.java index 491aeb64a..42b50cb7a 100644 --- a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/OneOf.java +++ b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/OneOf.java @@ -17,12 +17,10 @@ import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonTypeInfo; -import com.google.common.annotations.Beta; /** * OneOf */ -@Beta @JsonTypeInfo( use = JsonTypeInfo.Id.DEDUCTION ) @JsonSubTypes( { @JsonSubTypes.Type( value = Cola.class ), @JsonSubTypes.Type( value = Fanta.class ), } ) diff --git a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/OneOfWithDiscriminator.java b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/OneOfWithDiscriminator.java index f71818d41..eefc01778 100644 --- a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/OneOfWithDiscriminator.java +++ b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/OneOfWithDiscriminator.java @@ -17,12 +17,10 @@ import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonTypeInfo; -import com.google.common.annotations.Beta; /** * OneOfWithDiscriminator */ -@Beta @JsonTypeInfo( use = JsonTypeInfo.Id.NAME, property = "sodaType", visible = true ) @JsonSubTypes( { @JsonSubTypes.Type( value = Cola.class, name = "Cola" ), diff --git a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/OneOfWithDiscriminatorAndMapping.java b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/OneOfWithDiscriminatorAndMapping.java index f9742cbd8..8a6ff0271 100644 --- a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/OneOfWithDiscriminatorAndMapping.java +++ b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/OneOfWithDiscriminatorAndMapping.java @@ -17,12 +17,10 @@ import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonTypeInfo; -import com.google.common.annotations.Beta; /** * OneOfWithDiscriminatorAndMapping */ -@Beta @JsonTypeInfo( use = JsonTypeInfo.Id.NAME, property = "sodaType", visible = true ) @JsonSubTypes( { @JsonSubTypes.Type( value = Cola.class, name = "cool_cola" ), diff --git a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/OneOfWithEnumDiscriminator.java b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/OneOfWithEnumDiscriminator.java index c8657f4cb..4414cd99b 100644 --- a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/OneOfWithEnumDiscriminator.java +++ b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/OneOfWithEnumDiscriminator.java @@ -17,12 +17,10 @@ import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonTypeInfo; -import com.google.common.annotations.Beta; /** * OneOfWithEnumDiscriminator */ -@Beta @JsonTypeInfo( use = JsonTypeInfo.Id.NAME, property = "disc", visible = true ) @JsonSubTypes( { @JsonSubTypes.Type( value = Bar.class, name = "disc_bar" ), diff --git a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/Order.java b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/Order.java index dfae11431..87df617d1 100644 --- a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/Order.java +++ b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/Order.java @@ -28,13 +28,11 @@ import com.fasterxml.jackson.annotation.JsonAnySetter; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.common.annotations.Beta; /** * Order */ - -@Beta // CHECKSTYLE:OFF +// CHECKSTYLE:OFF public class Order // CHECKSTYLE:ON { diff --git a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/OrderWithTimestamp.java b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/OrderWithTimestamp.java index 709b90bb9..a36dee610 100644 --- a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/OrderWithTimestamp.java +++ b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/OrderWithTimestamp.java @@ -29,13 +29,11 @@ import com.fasterxml.jackson.annotation.JsonAnySetter; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.common.annotations.Beta; /** * OrderWithTimestamp */ - -@Beta // CHECKSTYLE:OFF +// CHECKSTYLE:OFF public class OrderWithTimestamp // CHECKSTYLE:ON { diff --git a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/Soda.java b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/Soda.java index 3f334cdf3..8898b95c2 100644 --- a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/Soda.java +++ b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/Soda.java @@ -30,13 +30,11 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonValue; -import com.google.common.annotations.Beta; /** * Soda */ - -@Beta // CHECKSTYLE:OFF +// CHECKSTYLE:OFF public class Soda // CHECKSTYLE:ON { diff --git a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/SodaWithId.java b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/SodaWithId.java index efe0b425e..cb5b7a12f 100644 --- a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/SodaWithId.java +++ b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/SodaWithId.java @@ -30,13 +30,11 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonValue; -import com.google.common.annotations.Beta; /** * SodaWithId */ - -@Beta // CHECKSTYLE:OFF +// CHECKSTYLE:OFF public class SodaWithId // CHECKSTYLE:ON { diff --git a/datamodel/openapi/openapi-api-sample/pom.xml b/datamodel/openapi/openapi-api-sample/pom.xml index 1bff0e213..251db764b 100644 --- a/datamodel/openapi/openapi-api-sample/pom.xml +++ b/datamodel/openapi/openapi-api-sample/pom.xml @@ -126,7 +126,6 @@ File=byte[] create - protected true true diff --git a/datamodel/openapi/openapi-core/pom.xml b/datamodel/openapi/openapi-core/pom.xml index 46cacdeab..ce7787da4 100644 --- a/datamodel/openapi/openapi-core/pom.xml +++ b/datamodel/openapi/openapi-core/pom.xml @@ -70,6 +70,10 @@ com.fasterxml.jackson.core jackson-core + + com.google.guava + guava + org.projectlombok diff --git a/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/ApiClient.java b/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/ApiClient.java index e8669d7bb..24682ece6 100644 --- a/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/ApiClient.java +++ b/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/ApiClient.java @@ -12,444 +12,122 @@ package com.sap.cloud.sdk.services.openapi.apache; +import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL; +import static com.fasterxml.jackson.annotation.PropertyAccessor.GETTER; +import static com.fasterxml.jackson.annotation.PropertyAccessor.SETTER; +import static com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES; +import static com.fasterxml.jackson.databind.MapperFeature.DEFAULT_VIEW_INCLUSION; +import static com.fasterxml.jackson.databind.SerializationFeature.WRITE_DATES_AS_TIMESTAMPS; +import static com.sap.cloud.sdk.services.openapi.apache.DefaultApiResponseHandler.isJsonMime; +import static lombok.AccessLevel.PRIVATE; + import java.io.File; import java.io.IOException; import java.io.UnsupportedEncodingException; -import java.lang.reflect.Type; -import java.net.URI; import java.net.URLEncoder; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.nio.charset.UnsupportedCharsetException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.nio.file.StandardCopyOption; -import java.text.DateFormat; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; -import java.util.Collections; import java.util.Date; -import java.util.HashMap; import java.util.List; -import java.util.Locale; import java.util.Map; import java.util.Map.Entry; -import java.util.regex.Matcher; -import java.util.regex.Pattern; +import java.util.Set; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; -import org.apache.hc.client5.http.cookie.BasicCookieStore; -import org.apache.hc.client5.http.cookie.Cookie; import org.apache.hc.client5.http.entity.UrlEncodedFormEntity; import org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder; import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; -import org.apache.hc.client5.http.impl.classic.HttpClients; -import org.apache.hc.client5.http.impl.cookie.BasicClientCookie; import org.apache.hc.client5.http.protocol.HttpClientContext; -import org.apache.hc.core5.http.ClassicHttpResponse; import org.apache.hc.core5.http.ContentType; -import org.apache.hc.core5.http.Header; import org.apache.hc.core5.http.HttpEntity; -import org.apache.hc.core5.http.HttpResponse; -import org.apache.hc.core5.http.HttpStatus; import org.apache.hc.core5.http.NameValuePair; -import org.apache.hc.core5.http.ParseException; import org.apache.hc.core5.http.io.HttpClientResponseHandler; import org.apache.hc.core5.http.io.entity.ByteArrayEntity; -import org.apache.hc.core5.http.io.entity.EntityUtils; import org.apache.hc.core5.http.io.entity.FileEntity; import org.apache.hc.core5.http.io.entity.StringEntity; import org.apache.hc.core5.http.io.support.ClassicRequestBuilder; import org.apache.hc.core5.http.message.BasicNameValuePair; -import com.fasterxml.jackson.annotation.*; +import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; +import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.json.JsonMapper; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; -import com.sap.cloud.sdk.services.openapi.apache.auth.Authentication; - +import com.google.common.annotations.Beta; +import com.sap.cloud.sdk.cloudplatform.connectivity.ApacheHttpClient5Accessor; +import com.sap.cloud.sdk.cloudplatform.connectivity.Destination; +import com.sap.cloud.sdk.services.openapi.apiclient.RFC3339DateFormat; +import com.sap.cloud.sdk.services.openapi.core.OpenApiRequestException; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; +import lombok.Value; +import lombok.With; + +@AllArgsConstructor( access = PRIVATE ) +@EqualsAndHashCode +@ToString public class ApiClient { - protected Map defaultHeaderMap = new HashMap(); - protected Map defaultCookieMap = new HashMap(); - protected String basePath = "http://localhost"; - protected List servers = - new ArrayList( - Arrays - .asList(new ServerConfiguration("", "No description provided", new HashMap()))); - protected Integer serverIndex = 0; - protected Map serverVariables = null; - protected boolean debugging = false; - protected int connectionTimeout = 0; + @Nonnull + private final CloseableHttpClient httpClient; - protected CloseableHttpClient httpClient; - protected ObjectMapper objectMapper; - protected String tempFolderPath = null; + @With + @Getter + @Nonnull + private final String basePath; - protected Map authentications; + @With( onMethod_ = @Beta ) + @Nonnull + private final ObjectMapper objectMapper; - protected ThreadLocal lastStatusCode = new ThreadLocal<>(); - protected ThreadLocal>> lastResponseHeaders = new ThreadLocal<>(); - - protected DateFormat dateFormat; + @With + @Nullable + private final String tempFolderPath; // Methods that can have a request body - protected static List bodyMethods = Arrays.asList("POST", "PUT", "DELETE", "PATCH"); - - public ApiClient( CloseableHttpClient httpClient ) - { - objectMapper = new ObjectMapper(); - objectMapper.setDefaultPropertyInclusion(JsonInclude.Include.NON_NULL); - objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - objectMapper.configure(DeserializationFeature.FAIL_ON_INVALID_SUBTYPE, false); - objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); - objectMapper.enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING); - objectMapper.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING); - objectMapper.registerModule(new JavaTimeModule()); - objectMapper.registerModule(new RFC3339JavaTimeModule()); - objectMapper.setDateFormat(ApiClient.buildDefaultDateFormat()); - - dateFormat = ApiClient.buildDefaultDateFormat(); - - // Set default User-Agent. - setUserAgent("OpenAPI-Generator/0.0.1/java"); - - // Setup authentications (key: authentication name, value: authentication). - authentications = new HashMap(); - // Prevent the authentications from being modified. - authentications = Collections.unmodifiableMap(authentications); - - this.httpClient = httpClient; - } - - public ApiClient() - { - this(HttpClients.createDefault()); - } - - public static DateFormat buildDefaultDateFormat() - { - return new RFC3339DateFormat(); - } - - /** - * Returns the current object mapper used for JSON serialization/deserialization. - *

- * Note: If you make changes to the object mapper, remember to set it back via setObjectMapper in order - * to trigger HTTP client rebuilding. - *

- * - * @return Object mapper - */ - public ObjectMapper getObjectMapper() - { - return objectMapper; - } - - /** - * Sets the object mapper. - * - * @param objectMapper - * object mapper - * @return API client - */ - public ApiClient setObjectMapper( ObjectMapper objectMapper ) - { - this.objectMapper = objectMapper; - return this; - } - - public CloseableHttpClient getHttpClient() - { - return httpClient; - } - - /** - * Sets the HTTP client. - * - * @param httpClient - * HTTP client - * @return API client - */ - public ApiClient setHttpClient( CloseableHttpClient httpClient ) - { - this.httpClient = httpClient; - return this; - } - - public String getBasePath() - { - return basePath; - } - - /** - * Sets the base path. - * - * @param basePath - * base path - * @return API client - */ - public ApiClient setBasePath( String basePath ) - { - this.basePath = basePath; - this.serverIndex = null; - return this; - } - - public List getServers() - { - return servers; - } - - /** - * Sets the server. - * - * @param servers - * a list of server configuration - * @return API client - */ - public ApiClient setServers( List servers ) - { - this.servers = servers; - return this; - } - - public Integer getServerIndex() - { - return serverIndex; - } - - /** - * Sets the server index. - * - * @param serverIndex - * server index - * @return API client - */ - public ApiClient setServerIndex( Integer serverIndex ) - { - this.serverIndex = serverIndex; - return this; - } - - public Map getServerVariables() - { - return serverVariables; - } - - /** - * Sets the server variables. - * - * @param serverVariables - * server variables - * @return API client - */ - public ApiClient setServerVariables( Map serverVariables ) - { - this.serverVariables = serverVariables; - return this; - } - - /** - * Gets the status code of the previous request - * - * @return Status code - */ - @Deprecated - public int getStatusCode() - { - return lastStatusCode.get(); - } - - /** - * Gets the response headers of the previous request - * - * @return Response headers - */ - @Deprecated - public Map> getResponseHeaders() - { - return lastResponseHeaders.get(); - } - - /** - * Get authentications (key: authentication name, value: authentication). - * - * @return Map of authentication - */ - public Map getAuthentications() - { - return authentications; - } - - /** - * Get authentication for the given name. - * - * @param authName - * The authentication name - * @return The authentication, null if not found - */ - public Authentication getAuthentication( String authName ) - { - return authentications.get(authName); - } - - /** - * The path of temporary folder used to store downloaded files from endpoints with file response. The default value - * is null, i.e. using the system's default temporary folder. - * - * @return Temp folder path - */ - public String getTempFolderPath() - { - return tempFolderPath; - } - - /** - * Set the User-Agent header's value (by adding to the default header map). - * - * @param userAgent - * User agent - * @return API client - */ - public final ApiClient setUserAgent( String userAgent ) - { - addDefaultHeader("User-Agent", userAgent); - return this; - } - - /** - * Set temp folder path - * - * @param tempFolderPath - * Temp folder path - * @return API client - */ - public ApiClient setTempFolderPath( String tempFolderPath ) - { - this.tempFolderPath = tempFolderPath; - return this; - } - - /** - * Add a default header. - * - * @param key - * The header's key - * @param value - * The header's value - * @return API client - */ - public final ApiClient addDefaultHeader( String key, String value ) - { - defaultHeaderMap.put(key, value); - return this; - } - - /** - * Add a default cookie. - * - * @param key - * The cookie's key - * @param value - * The cookie's value - * @return API client - */ - public ApiClient addDefaultCookie( String key, String value ) - { - defaultCookieMap.put(key, value); - return this; - } - - /** - * Check that whether debugging is enabled for this API client. - * - * @return True if debugging is on - */ - public boolean isDebugging() - { - return debugging; - } - - /** - * Enable/disable debugging for this API client. - * - * @param debugging - * To enable (true) or disable (false) debugging - * @return API client - */ - public ApiClient setDebugging( boolean debugging ) - { - // TODO: implement debugging mode - this.debugging = debugging; - return this; - } + private static final Set BODY_METHODS = Set.of("POST", "PUT", "DELETE", "PATCH"); + private static final String DEFAULT_BASE_PATH = "http://localhost"; - /** - * Connect timeout (in milliseconds). - * - * @return Connection timeout - */ - public int getConnectTimeout() + public static ApiClient fromHttpClient( @Nonnull final CloseableHttpClient httpClient ) { - return connectionTimeout; + return new ApiClient(httpClient, DEFAULT_BASE_PATH, createDefaultObjectMapper(), null); } - /** - * Set the connect timeout (in milliseconds). A value of 0 means no timeout, otherwise values must be between 1 and - * {@link Integer#MAX_VALUE}. - * - * @param connectionTimeout - * Connection timeout in milliseconds - * @return API client - */ - public ApiClient setConnectTimeout( int connectionTimeout ) + public static ApiClient create( @Nonnull final Destination destination ) { - this.connectionTimeout = connectionTimeout; - return this; - } + return fromHttpClient((CloseableHttpClient) ApacheHttpClient5Accessor.getHttpClient(destination)) + .withBasePath(destination.asHttp().getUri().toString()); - /** - * Get the date format used to parse/format date parameters. - * - * @return Date format - */ - public DateFormat getDateFormat() - { - return dateFormat; } - /** - * Set the date format used to parse/format date parameters. - * - * @param dateFormat - * Date format - * @return API client - */ - public ApiClient setDateFormat( DateFormat dateFormat ) + public static ApiClient create() { - this.dateFormat = dateFormat; - // Also set the date format for model (de)serialization with Date properties. - this.objectMapper.setDateFormat((DateFormat) dateFormat.clone()); - return this; + return fromHttpClient((CloseableHttpClient) ApacheHttpClient5Accessor.getHttpClient()); } - /** - * Parse the given string into Date object. - * - * @param str - * String - * @return Date - */ - public Date parseDate( String str ) + private static ObjectMapper createDefaultObjectMapper() { - try { - return dateFormat.parse(str); - } - catch( java.text.ParseException e ) { - throw new RuntimeException(e); - } + return JsonMapper + .builder() + .addModule(new JavaTimeModule()) + .defaultDateFormat(new RFC3339DateFormat()) + .visibility(GETTER, Visibility.NONE) + .visibility(SETTER, Visibility.NONE) + .defaultPropertyInclusion(JsonInclude.Value.construct(NON_NULL, NON_NULL)) + .disable(FAIL_ON_UNKNOWN_PROPERTIES) + .disable(DEFAULT_VIEW_INCLUSION) + .disable(WRITE_DATES_AS_TIMESTAMPS) + .build(); } /** @@ -459,9 +137,9 @@ public Date parseDate( String str ) * Date * @return Date in string format */ - public String formatDate( Date date ) + private static String formatDate( Date date ) { - return dateFormat.format(date); + return new RFC3339DateFormat().format(date); } /** @@ -471,7 +149,7 @@ public String formatDate( Date date ) * Object * @return Object in string format */ - public String parameterToString( Object param ) + public static String parameterToString( Object param ) { if( param == null ) { return ""; @@ -493,7 +171,7 @@ public String parameterToString( Object param ) /** * Formats the specified query parameter to a list containing a single {@code Pair} object. - * + *

* Note that {@code value} must not be a collection. * * @param name @@ -502,7 +180,7 @@ public String parameterToString( Object param ) * The value of the parameter. * @return A list containing a single {@code Pair} object. */ - public List parameterToPair( String name, Object value ) + public static List parameterToPair( String name, Object value ) { List params = new ArrayList(); @@ -517,7 +195,7 @@ public List parameterToPair( String name, Object value ) /** * Formats the specified collection query parameters to a list of {@code Pair} objects. - * + *

* Note that the values of each of the returned Pair objects are percent-encoded. * * @param collectionFormat @@ -528,7 +206,7 @@ public List parameterToPair( String name, Object value ) * The value of the parameter. * @return A list of {@code Pair} objects. */ - public List parameterToPairs( String collectionFormat, String name, Collection value ) + public static List parameterToPairs( String collectionFormat, String name, Collection value ) { List params = new ArrayList(); @@ -569,20 +247,6 @@ public List parameterToPairs( String collectionFormat, String name, Collec return params; } - /** - * Check if the given MIME is a JSON MIME. JSON MIME examples: application/json application/json; charset=UTF8 - * APPLICATION/JSON application/vnd.company+json - * - * @param mime - * MIME - * @return True if MIME type is boolean - */ - public boolean isJsonMime( String mime ) - { - String jsonMime = "(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$"; - return mime != null && (mime.matches(jsonMime) || mime.equals("*/*")); - } - /** * Select the Accept header's value from the given accepts array: if JSON exists in the given array, use it; * otherwise use all of them (joining into a string) @@ -592,7 +256,7 @@ public boolean isJsonMime( String mime ) * @return The Accept header to use. If the given array is empty, null will be returned (not to set the Accept * header explicitly). */ - public String selectHeaderAccept( String[] accepts ) + public static String selectHeaderAccept( String[] accepts ) { if( accepts.length == 0 ) { return null; @@ -602,7 +266,7 @@ public String selectHeaderAccept( String[] accepts ) return accept; } } - return StringUtil.join(accepts, ","); + return String.join(",", accepts); } /** @@ -613,7 +277,7 @@ public String selectHeaderAccept( String[] accepts ) * The Content-Type array to select from * @return The Content-Type header to use. If the given array is empty, or matches "any", JSON will be used. */ - public String selectHeaderContentType( String[] contentTypes ) + public static String selectHeaderContentType( String[] contentTypes ) { if( contentTypes.length == 0 || contentTypes[0].equals("*/*") ) { return "application/json"; @@ -633,7 +297,7 @@ public String selectHeaderContentType( String[] contentTypes ) * String * @return Escaped string */ - public String escapeString( String str ) + public static String escapeString( String str ) { try { return URLEncoder.encode(str, "utf8").replaceAll("\\+", "%20"); @@ -643,56 +307,20 @@ public String escapeString( String str ) } } - /** - * Transforms response headers into map. - * - * @param headers - * HTTP headers - * @return a map of string array - */ - protected Map> transformResponseHeaders( Header[] headers ) - { - Map> headersMap = new HashMap<>(); - for( Header header : headers ) { - List valuesList = headersMap.get(header.getName()); - if( valuesList != null ) { - valuesList.add(header.getValue()); - } else { - valuesList = new ArrayList<>(); - valuesList.add(header.getValue()); - headersMap.put(header.getName(), valuesList); - } - } - return headersMap; - } - /** * Parse content type object from header value */ - protected ContentType getContentType( String headerValue ) - throws ApiException + private ContentType getContentType( String headerValue ) + throws OpenApiRequestException { try { return ContentType.parse(headerValue); } catch( UnsupportedCharsetException e ) { - throw new ApiException("Could not parse content type " + headerValue); + throw new OpenApiRequestException("Could not parse content type " + headerValue); } } - /** - * Get content type of a response or null if one was not provided - */ - protected String getResponseMimeType( HttpResponse response ) - throws ApiException - { - Header contentTypeHeader = response.getFirstHeader("Content-Type"); - if( contentTypeHeader != null ) { - return getContentType(contentTypeHeader.getValue()).getMimeType(); - } - return null; - } - /** * Serialize the given Java object into string according the given Content-Type (only JSON is supported for now). * @@ -703,11 +331,11 @@ protected String getResponseMimeType( HttpResponse response ) * @param formParams * Form parameters * @return Object - * @throws ApiException + * @throws OpenApiRequestException * API exception */ - public HttpEntity serialize( Object obj, Map formParams, ContentType contentType ) - throws ApiException + private HttpEntity serialize( Object obj, Map formParams, ContentType contentType ) + throws OpenApiRequestException { String mimeType = contentType.getMimeType(); if( isJsonMime(mimeType) ) { @@ -717,7 +345,7 @@ public HttpEntity serialize( Object obj, Map formParams, Content contentType.withCharset(StandardCharsets.UTF_8)); } catch( JsonProcessingException e ) { - throw new ApiException(e); + throw new OpenApiRequestException(e); } } else if( mimeType.equals(ContentType.MULTIPART_FORM_DATA.getMimeType()) ) { MultipartEntityBuilder multiPartBuilder = MultipartEntityBuilder.create(); @@ -756,136 +384,10 @@ public HttpEntity serialize( Object obj, Map formParams, Content } else if( obj instanceof byte[] ) { return new ByteArrayEntity((byte[]) obj, contentType); } - throw new ApiException("Serialization for content type '" + contentType + "' not supported"); + throw new OpenApiRequestException("Serialization for content type '" + contentType + "' not supported"); } } - /** - * Deserialize response body to Java object according to the Content-Type. - * - * @param - * Type - * @param response - * Response - * @param valueType - * Return type - * @return Deserialized object - * @throws ApiException - * API exception - * @throws IOException - * IO exception - */ - @SuppressWarnings( "unchecked" ) - public T deserialize( ClassicHttpResponse response, TypeReference valueType ) - throws ApiException, - IOException, - ParseException - { - if( valueType == null ) { - return null; - } - HttpEntity entity = response.getEntity(); - Type valueRawType = valueType.getType(); - if( valueRawType.equals(byte[].class) ) { - return (T) EntityUtils.toByteArray(entity); - } else if( valueRawType.equals(File.class) ) { - return (T) downloadFileFromResponse(response); - } - String mimeType = getResponseMimeType(response); - if( mimeType == null || isJsonMime(mimeType) ) { - // Assume json if no mime type - // convert input stream to string - String content = EntityUtils.toString(entity); - - if( "".equals(content) ) { // returns null for empty body - return null; - } - - return objectMapper.readValue(content, valueType); - } else if( mimeType.toLowerCase().startsWith("text/") ) { - // convert input stream to string - return (T) EntityUtils.toString(entity); - } else { - Map> responseHeaders = transformResponseHeaders(response.getHeaders()); - throw new ApiException( - "Deserialization for content type '" + mimeType + "' not supported for type '" + valueType + "'", - response.getCode(), - responseHeaders, - EntityUtils.toString(entity)); - } - } - - protected File downloadFileFromResponse( ClassicHttpResponse response ) - throws IOException - { - Header contentDispositionHeader = response.getFirstHeader("Content-Disposition"); - String contentDisposition = contentDispositionHeader == null ? null : contentDispositionHeader.getValue(); - File file = prepareDownloadFile(contentDisposition); - Files.copy(response.getEntity().getContent(), file.toPath(), StandardCopyOption.REPLACE_EXISTING); - return file; - } - - protected File prepareDownloadFile( String contentDisposition ) - throws IOException - { - String filename = null; - if( contentDisposition != null && !"".equals(contentDisposition) ) { - // Get filename from the Content-Disposition header. - Pattern pattern = Pattern.compile("filename=['\"]?([^'\"\\s]+)['\"]?"); - Matcher matcher = pattern.matcher(contentDisposition); - if( matcher.find() ) - filename = matcher.group(1); - } - - String prefix; - String suffix = null; - if( filename == null ) { - prefix = "download-"; - suffix = ""; - } else { - int pos = filename.lastIndexOf('.'); - if( pos == -1 ) { - prefix = filename + "-"; - } else { - prefix = filename.substring(0, pos) + "-"; - suffix = filename.substring(pos); - } - // Files.createTempFile requires the prefix to be at least three characters long - if( prefix.length() < 3 ) - prefix = "download-"; - } - - if( tempFolderPath == null ) - return Files.createTempFile(prefix, suffix).toFile(); - else - return Files.createTempFile(Paths.get(tempFolderPath), prefix, suffix).toFile(); - } - - /** - * Returns the URL of the client as defined by the server (if exists) or the base path. - * - * @return The URL for the client. - */ - public String getBaseURL() - { - String baseURL; - if( serverIndex != null ) { - if( serverIndex < 0 || serverIndex >= servers.size() ) { - throw new ArrayIndexOutOfBoundsException( - String - .format( - Locale.ROOT, - "Invalid index %d when selecting the host settings. Must be less than %d", - serverIndex, - servers.size())); - } - baseURL = servers.get(serverIndex).URL(serverVariables); - } else { - baseURL = basePath; - } - return baseURL; - } - /** * Build full URL by concatenating base URL, the given sub path and query parameters. * @@ -899,14 +401,17 @@ public String getBaseURL() * URL query string of the deep object parameters * @return The full URL */ - protected + private String buildUrl( String path, List queryParams, List collectionQueryParams, String urlQueryDeepObject ) { - String baseURL = getBaseURL(); - final StringBuilder url = new StringBuilder(); - url.append(baseURL).append(path); + if( basePath.endsWith("/") && path != null && path.startsWith("/") ) { + url.append(basePath, 0, basePath.length() - 1); + } else { + url.append(basePath); + } + url.append(path); if( queryParams != null && !queryParams.isEmpty() ) { // support (constant) query string in `path`, e.g. "/posts?draft=1" @@ -951,67 +456,9 @@ public String getBaseURL() return url.toString(); } - protected boolean isSuccessfulStatus( int statusCode ) - { - return statusCode >= 200 && statusCode < 300; - } - - protected boolean isBodyAllowed( String method ) + private static boolean isBodyAllowed( String method ) { - return bodyMethods.contains(method); - } - - protected Cookie buildCookie( String key, String value, URI uri ) - { - BasicClientCookie cookie = new BasicClientCookie(key, value); - cookie.setDomain(uri.getHost()); - cookie.setPath("/"); - return cookie; - } - - /** - * Creates an HttpClientResponseHandler for processing HTTP responses. Wraps checked exceptions (ParseException, - * ApiException) as IOException since the handler interface only allows IOException to be thrown. - * - * @param - * Type - * @param returnType - * Return type - * @return HttpClientResponseHandler instance - */ - protected HttpClientResponseHandler createResponseHandler( TypeReference returnType ) - { - return response -> { - try { - return processResponse(response, returnType); - } - catch( ParseException | ApiException e ) { - // Wrap exceptions as IOException since handler can only throw IOException - throw new IOException("Failed to process response: " + e.getMessage(), e); - } - }; - } - - protected T processResponse( ClassicHttpResponse response, TypeReference returnType ) - throws ApiException, - IOException, - ParseException - { - int statusCode = response.getCode(); - lastStatusCode.set(statusCode); - if( statusCode == HttpStatus.SC_NO_CONTENT ) { - return null; - } - - Map> responseHeaders = transformResponseHeaders(response.getHeaders()); - lastResponseHeaders.set(responseHeaders); - - if( isSuccessfulStatus(statusCode) ) { - return this.deserialize(response, returnType); - } else { - String message = EntityUtils.toString(response.getEntity()); - throw new ApiException(message, statusCode, responseHeaders, message); - } + return BODY_METHODS.contains(method); } /** @@ -1033,22 +480,20 @@ protected T processResponse( ClassicHttpResponse response, TypeReference * The request body object - if it is not binary, otherwise null * @param headerParams * The header parameters - * @param cookieParams - * The cookie parameters * @param formParams * The form parameters * @param accept * The request's Accept header * @param contentType * The request's Content-Type header - * @param authNames - * The authentications to apply * @param returnType * Return type * @return The response body in type of string - * @throws ApiException + * @throws OpenApiRequestException * API exception */ + @Beta + @Nullable public T invokeAPI( String path, String method, @@ -1057,19 +502,16 @@ public T invokeAPI( String urlQueryDeepObject, Object body, Map headerParams, - Map cookieParams, Map formParams, String accept, String contentType, - String[] authNames, TypeReference returnType ) - throws ApiException + throws OpenApiRequestException { if( body != null && !formParams.isEmpty() ) { - throw new ApiException("Cannot have body and form params"); + throw new OpenApiRequestException("Cannot have body and form params"); } - updateParamsForAuth(authNames, queryParams, headerParams, cookieParams); final String url = buildUrl(path, queryParams, collectionQueryParams, urlQueryDeepObject); ClassicRequestBuilder builder = ClassicRequestBuilder.create(method); @@ -1081,24 +523,8 @@ public T invokeAPI( for( Entry keyValue : headerParams.entrySet() ) { builder.addHeader(keyValue.getKey(), keyValue.getValue()); } - for( Map.Entry keyValue : defaultHeaderMap.entrySet() ) { - if( !headerParams.containsKey(keyValue.getKey()) ) { - builder.addHeader(keyValue.getKey(), keyValue.getValue()); - } - } - - BasicCookieStore store = new BasicCookieStore(); - for( Entry keyValue : cookieParams.entrySet() ) { - store.addCookie(buildCookie(keyValue.getKey(), keyValue.getValue(), builder.getUri())); - } - for( Entry keyValue : defaultCookieMap.entrySet() ) { - if( !cookieParams.containsKey(keyValue.getKey()) ) { - store.addCookie(buildCookie(keyValue.getKey(), keyValue.getValue(), builder.getUri())); - } - } HttpClientContext context = HttpClientContext.create(); - context.setCookieStore(store); ContentType contentTypeObj = getContentType(contentType); if( body != null || !formParams.isEmpty() ) { @@ -1106,7 +532,7 @@ public T invokeAPI( // Add entity if we have content and a valid method builder.setEntity(serialize(body, formParams, contentTypeObj)); } else { - throw new ApiException("method " + method + " does not support a request body"); + throw new OpenApiRequestException("method " + method + " does not support a request body"); } } else { // for empty body @@ -1114,37 +540,12 @@ public T invokeAPI( } try { - HttpClientResponseHandler responseHandler = createResponseHandler(returnType); + HttpClientResponseHandler responseHandler = + new DefaultApiResponseHandler<>(objectMapper, tempFolderPath, returnType); return httpClient.execute(builder.build(), context, responseHandler); } catch( IOException e ) { - throw new ApiException(e); - } - } - - /** - * Update query and header parameters based on authentication settings. - * - * @param authNames - * The authentications to apply - * @param queryParams - * Query parameters - * @param headerParams - * Header parameters - * @param cookieParams - * Cookie parameters - */ - protected void updateParamsForAuth( - String[] authNames, - List queryParams, - Map headerParams, - Map cookieParams ) - { - for( String authName : authNames ) { - Authentication auth = authentications.get(authName); - if( auth == null ) - throw new RuntimeException("Authentication undefined: " + authName); - auth.applyToParams(queryParams, headerParams, cookieParams); + throw new OpenApiRequestException(e); } } } diff --git a/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/ApiException.java b/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/ApiException.java deleted file mode 100644 index b8ab4534c..000000000 --- a/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/ApiException.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Prompt Registry API - * Prompt Storage service for Design time & Runtime prompt templates. - * - * The version of the OpenAPI document: 0.0.1 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - -package com.sap.cloud.sdk.services.openapi.apache; - -import java.util.List; -import java.util.Map; - -public class ApiException extends Exception -{ - private static final long serialVersionUID = 1L; - - private int code = 0; - private transient Map> responseHeaders = null; - private String responseBody = null; - - public ApiException() - { - } - - public ApiException( Throwable throwable ) - { - super(throwable); - } - - public ApiException( String message ) - { - super(message); - } - - public ApiException( - String message, - Throwable throwable, - int code, - Map> responseHeaders, - String responseBody ) - { - super(message, throwable); - this.code = code; - this.responseHeaders = responseHeaders; - this.responseBody = responseBody; - } - - public ApiException( String message, int code, Map> responseHeaders, String responseBody ) - { - this(message, (Throwable) null, code, responseHeaders, responseBody); - } - - public ApiException( String message, Throwable throwable, int code, Map> responseHeaders ) - { - this(message, throwable, code, responseHeaders, null); - } - - public ApiException( int code, Map> responseHeaders, String responseBody ) - { - this( - "Response Code: " + code + " Response Body: " + responseBody, - (Throwable) null, - code, - responseHeaders, - responseBody); - } - - public ApiException( int code, String message ) - { - super(message); - this.code = code; - } - - public ApiException( int code, String message, Map> responseHeaders, String responseBody ) - { - this(code, message); - this.responseHeaders = responseHeaders; - this.responseBody = responseBody; - } - - /** - * Get the HTTP status code. - * - * @return HTTP status code - */ - public int getCode() - { - return code; - } - - /** - * Get the HTTP response headers. - * - * @return A map of list of string - */ - public Map> getResponseHeaders() - { - return responseHeaders; - } - - /** - * Get the HTTP response body. - * - * @return Response body in the form of string - */ - public String getResponseBody() - { - return responseBody; - } - - @Override - public String toString() - { - return "ApiException{" - + "code=" - + code - + ", responseHeaders=" - + responseHeaders - + ", responseBody='" - + responseBody - + '\'' - + '}'; - } -} diff --git a/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/BaseApi.java b/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/BaseApi.java index 7203f9e7f..45a4cbb23 100644 --- a/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/BaseApi.java +++ b/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/BaseApi.java @@ -12,170 +12,26 @@ package com.sap.cloud.sdk.services.openapi.apache; -import java.util.Collections; -import java.util.Map; +import javax.annotation.Nonnull; -import com.fasterxml.jackson.core.type.TypeReference; +import com.sap.cloud.sdk.cloudplatform.connectivity.Destination; public abstract class BaseApi { + protected final ApiClient apiClient; - protected ApiClient apiClient; - - public BaseApi() - { - this(Configuration.getDefaultApiClient()); - } - - public BaseApi( ApiClient apiClient ) + protected BaseApi() { - this.apiClient = apiClient; + this(ApiClient.create()); } - public ApiClient getApiClient() + protected BaseApi( @Nonnull final Destination destination ) { - return apiClient; + this(ApiClient.create(destination)); } - public void setApiClient( ApiClient apiClient ) + protected BaseApi( @Nonnull final ApiClient apiClient ) { this.apiClient = apiClient; } - - /** - * Directly invoke the API for the given URL. Useful if the API returns direct links/URLs for subsequent requests. - * - * @param url - * The URL for the request, either full URL or only the path. - * @param method - * The HTTP method for the request. - * @throws ApiException - * if fails to make API call. - */ - public void invokeAPI( String url, String method ) - throws ApiException - { - invokeAPI(url, method, null, null, Collections.emptyMap()); - } - - /** - * Directly invoke the API for the given URL. Useful if the API returns direct links/URLs for subsequent requests. - * - * @param url - * The URL for the request, either full URL or only the path. - * @param method - * The HTTP method for the request. - * @param additionalHeaders - * Additional headers for the request. - * @throws ApiException - * if fails to make API call. - */ - public void invokeAPI( String url, String method, Map additionalHeaders ) - throws ApiException - { - invokeAPI(url, method, null, null, additionalHeaders); - } - - /** - * Directly invoke the API for the given URL. Useful if the API returns direct links/URLs for subsequent requests. - * - * @param url - * The URL for the request, either full URL or only the path. - * @param method - * The HTTP method for the request. - * @param request - * The request object. - * @throws ApiException - * if fails to make API call. - */ - public void invokeAPI( String url, String method, Object request ) - throws ApiException - { - invokeAPI(url, method, request, null, Collections.emptyMap()); - } - - /** - * Directly invoke the API for the given URL. Useful if the API returns direct links/URLs for subsequent requests. - * - * @param url - * The URL for the request, either full URL or only the path. - * @param method - * The HTTP method for the request. - * @param request - * The request object. - * @param additionalHeaders - * Additional headers for the request. - * @throws ApiException - * if fails to make API call. - */ - public void invokeAPI( String url, String method, Object request, Map additionalHeaders ) - throws ApiException - { - invokeAPI(url, method, request, null, additionalHeaders); - } - - /** - * Directly invoke the API for the given URL. Useful if the API returns direct links/URLs for subsequent requests. - * - * @param url - * The URL for the request, either full URL or only the path. - * @param method - * The HTTP method for the request. - * @param returnType - * The return type. - * @return The API response in the specified type. - * @throws ApiException - * if fails to make API call. - */ - public T invokeAPI( String url, String method, TypeReference returnType ) - throws ApiException - { - return invokeAPI(url, method, null, returnType, Collections.emptyMap()); - } - - /** - * Directly invoke the API for the given URL. Useful if the API returns direct links/URLs for subsequent requests. - * - * @param url - * The URL for the request, either full URL or only the path. - * @param method - * The HTTP method for the request. - * @param request - * The request object. - * @param returnType - * The return type. - * @return The API response in the specified type. - * @throws ApiException - * if fails to make API call. - */ - public T invokeAPI( String url, String method, Object request, TypeReference returnType ) - throws ApiException - { - return invokeAPI(url, method, request, returnType, Collections.emptyMap()); - } - - /** - * Directly invoke the API for the given URL. Useful if the API returns direct links/URLs for subsequent requests. - * - * @param url - * The URL for the request, either full URL or only the path. - * @param method - * The HTTP method for the request. - * @param request - * The request object. - * @param returnType - * The return type. - * @param additionalHeaders - * Additional headers for the request. - * @return The API response in the specified type. - * @throws ApiException - * if fails to make API call. - */ - public abstract T invokeAPI( - String url, - String method, - Object request, - TypeReference returnType, - Map additionalHeaders ) - throws ApiException; } diff --git a/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/Configuration.java b/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/Configuration.java deleted file mode 100644 index 8978044d7..000000000 --- a/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/Configuration.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Prompt Registry API - * Prompt Storage service for Design time & Runtime prompt templates. - * - * The version of the OpenAPI document: 0.0.1 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - -package com.sap.cloud.sdk.services.openapi.apache; - -import java.util.Objects; -import java.util.concurrent.atomic.AtomicReference; -import java.util.function.Supplier; - -public class Configuration -{ - public static final String VERSION = "0.0.1"; - - private static final AtomicReference defaultApiClient = new AtomicReference<>(); - private static volatile Supplier apiClientFactory = ApiClient::new; - - /** - * Get the default API client, which would be used when creating API instances without providing an API client. - * - * @return Default API client - */ - public static ApiClient getDefaultApiClient() - { - ApiClient client = defaultApiClient.get(); - if( client == null ) { - client = defaultApiClient.updateAndGet(val -> { - if( val != null ) { // changed by another thread - return val; - } - return apiClientFactory.get(); - }); - } - return client; - } - - /** - * Set the default API client, which would be used when creating API instances without providing an API client. - * - * @param apiClient - * API client - */ - public static void setDefaultApiClient( ApiClient apiClient ) - { - defaultApiClient.set(apiClient); - } - - /** - * set the callback used to create new ApiClient objects - */ - public static void setApiClientFactory( Supplier factory ) - { - apiClientFactory = Objects.requireNonNull(factory); - } - - private Configuration() - { - } -} diff --git a/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/DefaultApiResponseHandler.java b/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/DefaultApiResponseHandler.java new file mode 100644 index 000000000..fac2b4f61 --- /dev/null +++ b/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/DefaultApiResponseHandler.java @@ -0,0 +1,333 @@ +/* + * Prompt Registry API + * Prompt Storage service for Design time & Runtime prompt templates. + * + * The version of the OpenAPI document: 0.0.1 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.cloud.sdk.services.openapi.apache; + +import java.io.File; +import java.io.IOException; +import java.lang.reflect.Type; +import java.nio.charset.UnsupportedCharsetException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.apache.hc.core5.http.ClassicHttpResponse; +import org.apache.hc.core5.http.ContentType; +import org.apache.hc.core5.http.Header; +import org.apache.hc.core5.http.HttpEntity; +import org.apache.hc.core5.http.HttpException; +import org.apache.hc.core5.http.HttpResponse; +import org.apache.hc.core5.http.HttpStatus; +import org.apache.hc.core5.http.ParseException; +import org.apache.hc.core5.http.io.HttpClientResponseHandler; +import org.apache.hc.core5.http.io.entity.EntityUtils; +import org.apache.hc.core5.http.message.StatusLine; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.sap.cloud.sdk.services.openapi.core.OpenApiRequestException; + +/** + * Handles HTTP response processing for API client operations. This class encapsulates response deserialization, error + * handling, and file download functionality. + * + * @param + * The type of object to deserialize the response into + */ +class DefaultApiResponseHandler implements HttpClientResponseHandler +{ + private final ObjectMapper objectMapper; + private final String tempFolderPath; + private final TypeReference returnType; + + /** + * Creates a new response handler with the specified configuration. + * + * @param objectMapper + * The Jackson ObjectMapper for JSON deserialization + * @param tempFolderPath + * The temporary folder path for file downloads (null for system default) + * @param returnType + * The type reference for response deserialization + */ + DefaultApiResponseHandler( ObjectMapper objectMapper, String tempFolderPath, TypeReference returnType ) + { + this.objectMapper = objectMapper; + this.tempFolderPath = tempFolderPath; + this.returnType = returnType; + } + + @Override + public T handleResponse( ClassicHttpResponse response ) + throws HttpException, + IOException + { + try { + return processResponse(response); + } + catch( ParseException | OpenApiRequestException e ) { + // Wrap exceptions as IOException since handler can only throw IOException + throw new IOException("Failed to process response: " + e.getMessage(), e); + } + } + + /** + * Processes the HTTP response and returns the deserialized result. + * + * @param response + * The HTTP response to process + * @return The deserialized response object + * @throws OpenApiRequestException + * if the response indicates an error + * @throws IOException + * if an I/O error occurs + * @throws ParseException + * if response parsing fails + */ + @SuppressWarnings( "unchecked" ) + private T processResponse( ClassicHttpResponse response ) + throws OpenApiRequestException, + IOException, + ParseException + { + int statusCode = response.getCode(); + if( statusCode == HttpStatus.SC_NO_CONTENT ) { + if( returnType.getType().equals(OpenApiResponse.class) ) { + return (T) new OpenApiResponse(statusCode, transformResponseHeaders(response.getHeaders())); + } + return null; + } + + if( isSuccessfulStatus(statusCode) ) { + return deserialize(response); + } else { + Map> responseHeaders = transformResponseHeaders(response.getHeaders()); + String message = new StatusLine(response).toString(); + throw new OpenApiRequestException(message) + .statusCode(statusCode) + .responseHeaders(responseHeaders) + .responseBody(EntityUtils.toString(response.getEntity())); + } + } + + /** + * Deserializes the response body to a Java object according to the Content-Type. + * + * @param response + * The HTTP response to deserialize + * @return The deserialized object + * @throws OpenApiRequestException + * if deserialization fails + * @throws IOException + * if an I/O error occurs + * @throws ParseException + * if response parsing fails + */ + @SuppressWarnings( "unchecked" ) + private T deserialize( ClassicHttpResponse response ) + throws OpenApiRequestException, + IOException, + ParseException + { + if( returnType == null ) { + return null; + } + + final Type valueRawType = returnType.getType(); + if( valueRawType.equals(OpenApiResponse.class) ) { + final int statusCode = response.getCode(); + Map> headers = transformResponseHeaders(response.getHeaders()); + return (T) new OpenApiResponse(statusCode, headers); + } + + HttpEntity entity = response.getEntity(); + if( valueRawType.equals(byte[].class) ) { + return (T) EntityUtils.toByteArray(entity); + } else if( valueRawType.equals(File.class) ) { + return (T) downloadFileFromResponse(response); + } + String mimeType = getResponseMimeType(response); + if( mimeType == null || isJsonMime(mimeType) ) { + // Assume json if no mime type + // convert input stream to string + String content = EntityUtils.toString(entity); + + if( "".equals(content) ) { // returns null for empty body + return null; + } + + return objectMapper.readValue(content, returnType); + } else if( mimeType.toLowerCase().startsWith("text/") ) { + // convert input stream to string + return (T) EntityUtils.toString(entity); + } else { + Map> responseHeaders = transformResponseHeaders(response.getHeaders()); + throw new OpenApiRequestException( + "Deserialization for content type '" + mimeType + "' not supported for type '" + returnType + "'") + .statusCode(response.getCode()) + .responseHeaders(responseHeaders) + .responseBody(EntityUtils.toString(entity)); + } + } + + /** + * Downloads a file from the HTTP response. + * + * @param response + * The HTTP response containing the file + * @return The downloaded file + * @throws IOException + * if an I/O error occurs during download + */ + private File downloadFileFromResponse( ClassicHttpResponse response ) + throws IOException + { + Header contentDispositionHeader = response.getFirstHeader("Content-Disposition"); + String contentDisposition = contentDispositionHeader == null ? null : contentDispositionHeader.getValue(); + File file = prepareDownloadFile(contentDisposition); + Files.copy(response.getEntity().getContent(), file.toPath(), StandardCopyOption.REPLACE_EXISTING); + return file; + } + + /** + * Prepares a temporary file for downloading response content. + * + * @param contentDisposition + * The Content-Disposition header value (may be null) + * @return A temporary file for storing the download + * @throws IOException + * if the temporary file cannot be created + */ + private File prepareDownloadFile( String contentDisposition ) + throws IOException + { + String filename = null; + if( contentDisposition != null && !"".equals(contentDisposition) ) { + // Get filename from the Content-Disposition header. + Pattern pattern = Pattern.compile("filename=['\"]?([^'\"\\s]+)['\"]?"); + Matcher matcher = pattern.matcher(contentDisposition); + if( matcher.find() ) + filename = matcher.group(1); + } + + String prefix; + String suffix = null; + if( filename == null ) { + prefix = "download-"; + suffix = ""; + } else { + int pos = filename.lastIndexOf('.'); + if( pos == -1 ) { + prefix = filename + "-"; + } else { + prefix = filename.substring(0, pos) + "-"; + suffix = filename.substring(pos); + } + // Files.createTempFile requires the prefix to be at least three characters long + if( prefix.length() < 3 ) + prefix = "download-"; + } + + if( tempFolderPath == null ) + return Files.createTempFile(prefix, suffix).toFile(); + else + return Files.createTempFile(Paths.get(tempFolderPath), prefix, suffix).toFile(); + } + + /** + * Gets the MIME type from the response Content-Type header. + * + * @param response + * The HTTP response + * @return The MIME type, or null if not present + * @throws OpenApiRequestException + * if the content type cannot be parsed + */ + private String getResponseMimeType( HttpResponse response ) + throws OpenApiRequestException + { + Header contentTypeHeader = response.getFirstHeader("Content-Type"); + if( contentTypeHeader != null ) { + return parseContentType(contentTypeHeader.getValue()).getMimeType(); + } + return null; + } + + /** + * Parses a Content-Type header value into a ContentType object. + * + * @param headerValue + * The Content-Type header value + * @return The parsed ContentType object + * @throws OpenApiRequestException + * if the content type cannot be parsed + */ + private static ContentType parseContentType( String headerValue ) + throws OpenApiRequestException + { + try { + return ContentType.parse(headerValue); + } + catch( UnsupportedCharsetException e ) { + throw new OpenApiRequestException("Could not parse content type " + headerValue); + } + } + + /** + * Transforms response headers into map. + * + * @param headers + * HTTP headers + * @return a map of string array + */ + private static Map> transformResponseHeaders( Header[] headers ) + { + Map> headersMap = new HashMap<>(); + for( Header header : headers ) { + List valuesList = headersMap.get(header.getName()); + if( valuesList != null ) { + valuesList.add(header.getValue()); + } else { + valuesList = new ArrayList<>(); + valuesList.add(header.getValue()); + headersMap.put(header.getName(), valuesList); + } + } + return headersMap; + } + + private static boolean isSuccessfulStatus( int statusCode ) + { + return statusCode >= 200 && statusCode < 300; + } + + /** + * Check if the given MIME is a JSON MIME. JSON MIME examples: application/json application/json; charset=UTF8 + * APPLICATION/JSON application/vnd.company+json + * + * @param mime + * MIME + * @return True if MIME type is boolean + */ + static boolean isJsonMime( String mime ) + { + String jsonMime = "(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$"; + return mime != null && (mime.matches(jsonMime) || mime.equals("*/*")); + } + +} diff --git a/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/OpenApiResponse.java b/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/OpenApiResponse.java new file mode 100644 index 000000000..f4cc3c35d --- /dev/null +++ b/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/OpenApiResponse.java @@ -0,0 +1,30 @@ +package com.sap.cloud.sdk.services.openapi.apache; + +import java.util.List; +import java.util.Map; + +import javax.annotation.Nonnull; + +import lombok.Getter; + +/** + * Response object for Apache HTTP client OpenAPI calls containing status code and headers + */ +@Getter +public class OpenApiResponse +{ + + private final int statusCode; + + @Nonnull + private final Map> headers; + + /** + * Create a new OpenApiResponse with status code and headers. + */ + OpenApiResponse( final int statusCode, @Nonnull final Map> headers ) + { + this.statusCode = statusCode; + this.headers = Map.copyOf(headers); + } +} diff --git a/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/Pair.java b/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/Pair.java index c7e9a9711..1ab38e5f7 100644 --- a/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/Pair.java +++ b/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/Pair.java @@ -12,29 +12,15 @@ package com.sap.cloud.sdk.services.openapi.apache; -public class Pair -{ - private final String name; - private final String value; - - public Pair( String name, String value ) - { - this.name = isValidString(name) ? name : ""; - this.value = isValidString(value) ? value : ""; - } +import javax.annotation.Nonnull; - public String getName() - { - return this.name; - } +import lombok.Value; - public String getValue() - { - return this.value; - } - - private static boolean isValidString( String arg ) - { - return arg != null; - } +@Value +public class Pair +{ + @Nonnull + String name; + @Nonnull + String value; } diff --git a/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/RFC3339DateFormat.java b/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/RFC3339DateFormat.java deleted file mode 100644 index 8d841d0bd..000000000 --- a/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/RFC3339DateFormat.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Prompt Registry API - * Prompt Storage service for Design time & Runtime prompt templates. - * - * The version of the OpenAPI document: 0.0.1 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - -package com.sap.cloud.sdk.services.openapi.apache; - -import java.text.DateFormat; -import java.text.DecimalFormat; -import java.text.FieldPosition; -import java.text.ParsePosition; -import java.util.Date; -import java.util.GregorianCalendar; -import java.util.TimeZone; - -import com.fasterxml.jackson.databind.util.StdDateFormat; - -public class RFC3339DateFormat extends DateFormat -{ - private static final long serialVersionUID = 1L; - private static final TimeZone TIMEZONE_Z = TimeZone.getTimeZone("UTC"); - - private final StdDateFormat fmt = new StdDateFormat().withTimeZone(TIMEZONE_Z).withColonInTimeZone(true); - - public RFC3339DateFormat() - { - this.calendar = new GregorianCalendar(); - this.numberFormat = new DecimalFormat(); - } - - @Override - public Date parse( String source ) - { - return parse(source, new ParsePosition(0)); - } - - @Override - public Date parse( String source, ParsePosition pos ) - { - return fmt.parse(source, pos); - } - - @Override - public StringBuffer format( Date date, StringBuffer toAppendTo, FieldPosition fieldPosition ) - { - return fmt.format(date, toAppendTo, fieldPosition); - } - - @Override - public Object clone() - { - return super.clone(); - } -} diff --git a/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/RFC3339InstantDeserializer.java b/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/RFC3339InstantDeserializer.java deleted file mode 100644 index ae5560a88..000000000 --- a/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/RFC3339InstantDeserializer.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Prompt Registry API - * Prompt Storage service for Design time & Runtime prompt templates. - * - * The version of the OpenAPI document: 0.0.1 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - -package com.sap.cloud.sdk.services.openapi.apache; - -import java.io.IOException; -import java.time.Instant; -import java.time.OffsetDateTime; -import java.time.ZoneId; -import java.time.ZonedDateTime; -import java.time.format.DateTimeFormatter; -import java.time.temporal.Temporal; -import java.time.temporal.TemporalAccessor; -import java.util.function.BiFunction; -import java.util.function.Function; - -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.datatype.jsr310.JavaTimeFeature; -import com.fasterxml.jackson.datatype.jsr310.deser.InstantDeserializer; - -public class RFC3339InstantDeserializer extends InstantDeserializer -{ - private static final long serialVersionUID = 1L; - private final static boolean DEFAULT_NORMALIZE_ZONE_ID = - JavaTimeFeature.NORMALIZE_DESERIALIZED_ZONE_ID.enabledByDefault(); - private final static boolean DEFAULT_ALWAYS_ALLOW_STRINGIFIED_DATE_TIMESTAMPS = - JavaTimeFeature.ALWAYS_ALLOW_STRINGIFIED_DATE_TIMESTAMPS.enabledByDefault(); - - public static final RFC3339InstantDeserializer INSTANT = - new RFC3339InstantDeserializer<>( - Instant.class, - DateTimeFormatter.ISO_INSTANT, - Instant::from, - a -> Instant.ofEpochMilli(a.value), - a -> Instant.ofEpochSecond(a.integer, a.fraction), - null, - true, // yes, replace zero offset with Z - DEFAULT_NORMALIZE_ZONE_ID, - DEFAULT_ALWAYS_ALLOW_STRINGIFIED_DATE_TIMESTAMPS); - - public static final RFC3339InstantDeserializer OFFSET_DATE_TIME = - new RFC3339InstantDeserializer<>( - OffsetDateTime.class, - DateTimeFormatter.ISO_OFFSET_DATE_TIME, - OffsetDateTime::from, - a -> OffsetDateTime.ofInstant(Instant.ofEpochMilli(a.value), a.zoneId), - a -> OffsetDateTime.ofInstant(Instant.ofEpochSecond(a.integer, a.fraction), a.zoneId), - ( - d, - z ) -> (d.isEqual(OffsetDateTime.MIN) || d.isEqual(OffsetDateTime.MAX) - ? d - : d.withOffsetSameInstant(z.getRules().getOffset(d.toLocalDateTime()))), - true, // yes, replace zero offset with Z - DEFAULT_NORMALIZE_ZONE_ID, - DEFAULT_ALWAYS_ALLOW_STRINGIFIED_DATE_TIMESTAMPS); - - public static final RFC3339InstantDeserializer ZONED_DATE_TIME = - new RFC3339InstantDeserializer<>( - ZonedDateTime.class, - DateTimeFormatter.ISO_ZONED_DATE_TIME, - ZonedDateTime::from, - a -> ZonedDateTime.ofInstant(Instant.ofEpochMilli(a.value), a.zoneId), - a -> ZonedDateTime.ofInstant(Instant.ofEpochSecond(a.integer, a.fraction), a.zoneId), - ZonedDateTime::withZoneSameInstant, - false, // keep zero offset and Z separate since zones explicitly supported - DEFAULT_NORMALIZE_ZONE_ID, - DEFAULT_ALWAYS_ALLOW_STRINGIFIED_DATE_TIMESTAMPS); - - protected RFC3339InstantDeserializer( - Class supportedType, - DateTimeFormatter formatter, - Function parsedToValue, - Function fromMilliseconds, - Function fromNanoseconds, - BiFunction adjust, - boolean replaceZeroOffsetAsZ, - boolean normalizeZoneId, - boolean readNumericStringsAsTimestamp ) - { - super( - supportedType, - formatter, - parsedToValue, - fromMilliseconds, - fromNanoseconds, - adjust, - replaceZeroOffsetAsZ, - normalizeZoneId, - readNumericStringsAsTimestamp); - } - - @Override - protected T _fromString( JsonParser p, DeserializationContext ctxt, String string0 ) - throws IOException - { - return super._fromString(p, ctxt, string0.replace(' ', 'T')); - } -} diff --git a/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/RFC3339JavaTimeModule.java b/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/RFC3339JavaTimeModule.java deleted file mode 100644 index ce882de8c..000000000 --- a/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/RFC3339JavaTimeModule.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Prompt Registry API - * Prompt Storage service for Design time & Runtime prompt templates. - * - * The version of the OpenAPI document: 0.0.1 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - -package com.sap.cloud.sdk.services.openapi.apache; - -import java.time.Instant; -import java.time.OffsetDateTime; -import java.time.ZonedDateTime; - -import com.fasterxml.jackson.databind.module.SimpleModule; - -public class RFC3339JavaTimeModule extends SimpleModule -{ - private static final long serialVersionUID = 1L; - - public RFC3339JavaTimeModule() - { - super("RFC3339JavaTimeModule"); - } - - @Override - public void setupModule( SetupContext context ) - { - super.setupModule(context); - - addDeserializer(Instant.class, RFC3339InstantDeserializer.INSTANT); - addDeserializer(OffsetDateTime.class, RFC3339InstantDeserializer.OFFSET_DATE_TIME); - addDeserializer(ZonedDateTime.class, RFC3339InstantDeserializer.ZONED_DATE_TIME); - } - -} diff --git a/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/ServerConfiguration.java b/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/ServerConfiguration.java deleted file mode 100644 index 3c91ed3b8..000000000 --- a/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/ServerConfiguration.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Prompt Registry API - * Prompt Storage service for Design time & Runtime prompt templates. - * - * The version of the OpenAPI document: 0.0.1 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - -package com.sap.cloud.sdk.services.openapi.apache; - -import java.util.Map; - -/** - * Representing a Server configuration. - */ -public class ServerConfiguration -{ - public String URL; - public String description; - public Map variables; - - /** - * @param URL - * A URL to the target host. - * @param description - * A description of the host designated by the URL. - * @param variables - * A map between a variable name and its value. The value is used for substitution in the server's URL - * template. - */ - public ServerConfiguration( String URL, String description, Map variables ) - { - this.URL = URL; - this.description = description; - this.variables = variables; - } - - /** - * Format URL template using given variables. - * - * @param variables - * A map between a variable name and its value. - * @return Formatted URL. - */ - public String URL( Map variables ) - { - String url = this.URL; - - // go through variables and replace placeholders - for( Map.Entry variable : this.variables.entrySet() ) { - String name = variable.getKey(); - ServerVariable serverVariable = variable.getValue(); - String value = serverVariable.defaultValue; - - if( variables != null && variables.containsKey(name) ) { - value = variables.get(name); - if( serverVariable.enumValues.size() > 0 && !serverVariable.enumValues.contains(value) ) { - throw new IllegalArgumentException( - "The variable " + name + " in the server URL has invalid value " + value + "."); - } - } - url = url.replace("{" + name + "}", value); - } - return url; - } - - /** - * Format URL template using default server variables. - * - * @return Formatted URL. - */ - public String URL() - { - return URL(null); - } -} diff --git a/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/ServerVariable.java b/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/ServerVariable.java deleted file mode 100644 index e2e4a3d06..000000000 --- a/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/ServerVariable.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Prompt Registry API - * Prompt Storage service for Design time & Runtime prompt templates. - * - * The version of the OpenAPI document: 0.0.1 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - -package com.sap.cloud.sdk.services.openapi.apache; - -import java.util.HashSet; - -/** - * Representing a Server Variable for server URL template substitution. - */ -public class ServerVariable -{ - public String description; - public String defaultValue; - public HashSet enumValues = null; - - /** - * @param description - * A description for the server variable. - * @param defaultValue - * The default value to use for substitution. - * @param enumValues - * An enumeration of string values to be used if the substitution options are from a limited set. - */ - public ServerVariable( String description, String defaultValue, HashSet enumValues ) - { - this.description = description; - this.defaultValue = defaultValue; - this.enumValues = enumValues; - } -} diff --git a/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/StringUtil.java b/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/StringUtil.java deleted file mode 100644 index 8fe49ac89..000000000 --- a/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/StringUtil.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Prompt Registry API - * Prompt Storage service for Design time & Runtime prompt templates. - * - * The version of the OpenAPI document: 0.0.1 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - -package com.sap.cloud.sdk.services.openapi.apache; - -import java.util.Collection; -import java.util.Iterator; - -public class StringUtil -{ - /** - * Check if the given array contains the given value (with case-insensitive comparison). - * - * @param array - * The array - * @param value - * The value to search - * @return true if the array contains the value - */ - public static boolean containsIgnoreCase( String[] array, String value ) - { - for( String str : array ) { - if( value == null && str == null ) { - return true; - } - if( value != null && value.equalsIgnoreCase(str) ) { - return true; - } - } - return false; - } - - /** - * Join an array of strings with the given separator. - *

- * Note: This might be replaced by utility method from commons-lang or guava someday if one of those libraries is - * added as dependency. - *

- * - * @param array - * The array of strings - * @param separator - * The separator - * @return the resulting string - */ - public static String join( String[] array, String separator ) - { - int len = array.length; - if( len == 0 ) { - return ""; - } - - StringBuilder out = new StringBuilder(); - out.append(array[0]); - for( int i = 1; i < len; i++ ) { - out.append(separator).append(array[i]); - } - return out.toString(); - } - - /** - * Join a list of strings with the given separator. - * - * @param list - * The list of strings - * @param separator - * The separator - * @return the resulting string - */ - public static String join( Collection list, String separator ) - { - Iterator iterator = list.iterator(); - StringBuilder out = new StringBuilder(); - if( iterator.hasNext() ) { - out.append(iterator.next()); - } - while( iterator.hasNext() ) { - out.append(separator).append(iterator.next()); - } - return out.toString(); - } -} diff --git a/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/auth/ApiKeyAuth.java b/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/auth/ApiKeyAuth.java deleted file mode 100644 index 87f4fe832..000000000 --- a/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/auth/ApiKeyAuth.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Prompt Registry API - * Prompt Storage service for Design time & Runtime prompt templates. - * - * The version of the OpenAPI document: 0.0.1 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - -package com.sap.cloud.sdk.services.openapi.apache.auth; - -import java.util.List; -import java.util.Map; - -import com.sap.cloud.sdk.services.openapi.apache.Pair; - -public class ApiKeyAuth implements Authentication -{ - private final String location; - private final String paramName; - - private String apiKey; - private String apiKeyPrefix; - - public ApiKeyAuth( String location, String paramName ) - { - this.location = location; - this.paramName = paramName; - } - - public String getLocation() - { - return location; - } - - public String getParamName() - { - return paramName; - } - - public String getApiKey() - { - return apiKey; - } - - public void setApiKey( String apiKey ) - { - this.apiKey = apiKey; - } - - public String getApiKeyPrefix() - { - return apiKeyPrefix; - } - - public void setApiKeyPrefix( String apiKeyPrefix ) - { - this.apiKeyPrefix = apiKeyPrefix; - } - - @Override - public - void - applyToParams( List queryParams, Map headerParams, Map cookieParams ) - { - if( apiKey == null ) { - return; - } - String value; - if( apiKeyPrefix != null ) { - value = apiKeyPrefix + " " + apiKey; - } else { - value = apiKey; - } - if( "query".equals(location) ) { - queryParams.add(new Pair(paramName, value)); - } else if( "header".equals(location) ) { - headerParams.put(paramName, value); - } else if( "cookie".equals(location) ) { - cookieParams.put(paramName, value); - } - } -} diff --git a/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/auth/Authentication.java b/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/auth/Authentication.java deleted file mode 100644 index 92d1e48b2..000000000 --- a/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/auth/Authentication.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Prompt Registry API - * Prompt Storage service for Design time & Runtime prompt templates. - * - * The version of the OpenAPI document: 0.0.1 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - -package com.sap.cloud.sdk.services.openapi.apache.auth; - -import java.util.List; -import java.util.Map; - -import com.sap.cloud.sdk.services.openapi.apache.Pair; - -public interface Authentication -{ - /** - * Apply authentication settings to header and query params. - * - * @param queryParams - * List of query parameters - * @param headerParams - * Map of header parameters - * @param cookieParams - * Map of cookie parameters - */ - void applyToParams( List queryParams, Map headerParams, Map cookieParams ); -} diff --git a/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/auth/HttpBasicAuth.java b/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/auth/HttpBasicAuth.java deleted file mode 100644 index fc48507f6..000000000 --- a/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/auth/HttpBasicAuth.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Prompt Registry API - * Prompt Storage service for Design time & Runtime prompt templates. - * - * The version of the OpenAPI document: 0.0.1 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - -package com.sap.cloud.sdk.services.openapi.apache.auth; - -import java.nio.charset.StandardCharsets; -import java.util.Base64; -import java.util.List; -import java.util.Map; - -import com.sap.cloud.sdk.services.openapi.apache.Pair; - -public class HttpBasicAuth implements Authentication -{ - private String username; - private String password; - - public String getUsername() - { - return username; - } - - public void setUsername( String username ) - { - this.username = username; - } - - public String getPassword() - { - return password; - } - - public void setPassword( String password ) - { - this.password = password; - } - - @Override - public - void - applyToParams( List queryParams, Map headerParams, Map cookieParams ) - { - if( username == null && password == null ) { - return; - } - String str = (username == null ? "" : username) + ":" + (password == null ? "" : password); - headerParams - .put("Authorization", "Basic " + Base64.getEncoder().encodeToString(str.getBytes(StandardCharsets.UTF_8))); - } -} diff --git a/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/auth/HttpBearerAuth.java b/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/auth/HttpBearerAuth.java deleted file mode 100644 index 886915d6e..000000000 --- a/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/auth/HttpBearerAuth.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Prompt Registry API - * Prompt Storage service for Design time & Runtime prompt templates. - * - * The version of the OpenAPI document: 0.0.1 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - -package com.sap.cloud.sdk.services.openapi.apache.auth; - -import java.util.List; -import java.util.Map; -import java.util.function.Supplier; - -import com.sap.cloud.sdk.services.openapi.apache.Pair; - -public class HttpBearerAuth implements Authentication -{ - private final String scheme; - private Supplier tokenSupplier; - - public HttpBearerAuth( String scheme ) - { - this.scheme = upperCaseBearer(scheme); - } - - /** - * Gets the token, which together with the scheme, will be sent as the value of the Authorization header. - * - * @return The bearer token - */ - public String getBearerToken() - { - return tokenSupplier.get(); - } - - /** - * Sets the token, which together with the scheme, will be sent as the value of the Authorization header. - * - * @param bearerToken - * The bearer token to send in the Authorization header - */ - public void setBearerToken( String bearerToken ) - { - this.tokenSupplier = () -> bearerToken; - } - - /** - * Sets the supplier of tokens, which together with the scheme, will be sent as the value of the Authorization - * header. - * - * @param tokenSupplier - * The supplier of bearer tokens to send in the Authorization header - */ - public void setBearerToken( Supplier tokenSupplier ) - { - this.tokenSupplier = tokenSupplier; - } - - @Override - public - void - applyToParams( List queryParams, Map headerParams, Map cookieParams ) - { - String bearerToken = tokenSupplier != null ? tokenSupplier.get() : null; - if( bearerToken == null ) { - return; - } - headerParams.put("Authorization", (scheme != null ? scheme + " " : "") + bearerToken); - } - - private static String upperCaseBearer( String scheme ) - { - return "bearer".equalsIgnoreCase(scheme) ? "Bearer" : scheme; - } -} diff --git a/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/core/OpenApiRequestException.java b/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/core/OpenApiRequestException.java index c22e6a505..6237641e1 100644 --- a/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/core/OpenApiRequestException.java +++ b/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/core/OpenApiRequestException.java @@ -1,14 +1,32 @@ package com.sap.cloud.sdk.services.openapi.core; +import java.util.List; +import java.util.Map; + import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import lombok.Getter; +import lombok.Setter; +import lombok.experimental.Accessors; /** * Thrown if an error occurs during the invocation of a OpenAPI service. */ +@Accessors( fluent = true ) +@Getter +@Setter public class OpenApiRequestException extends RuntimeException { private static final long serialVersionUID = -8248392392632616674L; + @Nullable + private Integer statusCode; + @Nullable + private transient Map> responseHeaders; + @Nullable + private transient String responseBody; + /** * Thrown if an error occurs during the invocation of a OpenAPI service. * diff --git a/datamodel/openapi/openapi-generator/src/main/resources/openapi-generator/mustache-templates/libraries/apache-httpclient/api.mustache b/datamodel/openapi/openapi-generator/src/main/resources/openapi-generator/mustache-templates/libraries/apache-httpclient/api.mustache index becb08a14..e6a5a6b92 100644 --- a/datamodel/openapi/openapi-generator/src/main/resources/openapi-generator/mustache-templates/libraries/apache-httpclient/api.mustache +++ b/datamodel/openapi/openapi-generator/src/main/resources/openapi-generator/mustache-templates/libraries/apache-httpclient/api.mustache @@ -1,21 +1,26 @@ -{{>licenseInfo}} +{{#copyrightHeader}} +/* +* {{copyrightHeader}} +*/ +{{/copyrightHeader}} + package {{package}}; import com.fasterxml.jackson.core.type.TypeReference; -import {{invokerPackage}}.ApiException; -import {{invokerPackage}}.ApiClient; -import {{invokerPackage}}.BaseApi; -import {{invokerPackage}}.Configuration; +import com.sap.cloud.sdk.services.openapi.core.OpenApiRequestException; +import com.sap.cloud.sdk.services.openapi.apache.OpenApiResponse; +import com.sap.cloud.sdk.services.openapi.apache.ApiClient; +import com.sap.cloud.sdk.services.openapi.apache.BaseApi; +import com.sap.cloud.sdk.services.openapi.apache.Pair; + {{#models.0}} import {{modelPackage}}.*; {{/models.0}} -import {{invokerPackage}}.Pair; {{#imports}}import {{import}}; {{/imports}} - import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -24,222 +29,158 @@ import java.util.Locale; import java.util.Map; import java.util.StringJoiner; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +{{^aiSdkConstructor}}import com.sap.cloud.sdk.cloudplatform.connectivity.Destination; +{{/aiSdkConstructor}} +{{#aiSdkConstructor}}import com.sap.ai.sdk.core.AiCoreService; +{{/aiSdkConstructor}} + {{#useBeanValidation}} import {{javaxPackage}}.validation.constraints.*; import {{javaxPackage}}.validation.Valid; {{/useBeanValidation}} -{{!>generatedAnnotation}} +/** +* {{appName}} in version {{version}}. +* +* {{#appDescription}}{{{appDescription}}}{{/appDescription}}{{^appDescription}}No description provided.{{/appDescription}} +*/ +{{!>generatedAnnotation}} {{#operations}} - public class {{classname}} extends BaseApi { - - public {{classname}}() { - super(Configuration.getDefaultApiClient()); +public class {{classname}} extends BaseApi { + + {{^aiSdkConstructor}} + /** + * Instantiates this API class to invoke operations on the {{appName}} + */ + public {{classname}}() {} + + /** + * Instantiates this API class to invoke operations on the {{appName}}. + * + * @param httpDestination The destination that API should be used with + */ + public {{classname}}( @Nonnull final Destination httpDestination ) + { + super(httpDestination); } - public {{classname}}(ApiClient apiClient) { + /** + * Instantiates this API class to invoke operations on the {{appName}} based on a given {@link ApiClient}. + * + * @param apiClient + * ApiClient to invoke the API on + */ + public {{classname}}(@Nonnull final ApiClient apiClient) { super(apiClient); } + {{/aiSdkConstructor}} + {{#aiSdkConstructor}} + /** + * Instantiates this API class to invoke operations on the {{appName}} + */ + public {{classname}}() + { + super(new AiCoreService().getApiClient()); + } + + /** + * Instantiates this API class to invoke operations on the {{appName}} + * + * @param aiCoreService The configured connectivity instance to AI Core + */ + public {{classname}}( @Nonnull final AiCoreService aiCoreService ) + { + super(aiCoreService.getApiClient()); + } + {{/aiSdkConstructor}} {{#operation}} - /** - * {{summary}} - * {{notes}} - {{#allParams}} - * @param {{paramName}} {{description}}{{#required}} (required){{/required}}{{^required}} (optional{{^isContainer}}{{#defaultValue}}, default to {{.}}{{/defaultValue}}{{/isContainer}}){{/required}} - {{/allParams}} - {{#returnType}} + {{#hasOptionalParams}} + /** + *

{{summary}} + *

{{notes}} + {{#responses}} + *

{{code}}{{#message}} - {{message}}{{/message}} + {{/responses}} + {{#allParams}} + * @param {{paramName}} {{#required}} (required){{/required}}{{^required}} (optional{{^isContainer}}{{#defaultValue}}, default to {{.}}{{/defaultValue}}{{/isContainer}}){{/required}} + {{#description}} + * {{description}} + {{/description}} + {{^description}} + * The value for the parameter {{paramName}} + {{/description}} + {{/allParams}} + {{#returnType}} * @return {{returnType}} - {{/returnType}} - * @throws ApiException if fails to make API call - {{#isDeprecated}} - * @deprecated - {{/isDeprecated}} - {{#externalDocs}} + {{/returnType}} + {{^returnType}} + * @return An OpenApiResponse containing the status code of the HttpResponse. + {{/returnType}} + * @throws OpenApiRequestException if an error occurs while attempting to invoke the API + {{#externalDocs}} * {{description}} * @see {{summary}} Documentation - {{/externalDocs}} - */ - {{#isDeprecated}} + {{/externalDocs}} + {{#isDeprecated}} + * @deprecated + {{/isDeprecated}} + */ + {{#isDeprecated}} @Deprecated - {{/isDeprecated}} - public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}}{{operationId}}({{#allParams}}{{>nullable_var_annotations}} {{{dataType}}} {{paramName}}{{^-last}}, {{/-last}}{{/allParams}}) throws ApiException { - {{#returnType}}return {{/returnType}}this.{{operationId}}({{#allParams}}{{paramName}}, {{/allParams}}Collections.emptyMap()); - } - + {{/isDeprecated}} + {{#vendorExtensions.x-return-nullable}}@Nullable{{/vendorExtensions.x-return-nullable}}{{^vendorExtensions.x-return-nullable}}@Nonnull{{/vendorExtensions.x-return-nullable}} + public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}OpenApiResponse {{/returnType}}{{#vendorExtensions.x-sap-cloud-sdk-operation-name}}{{vendorExtensions.x-sap-cloud-sdk-operation-name}}{{/vendorExtensions.x-sap-cloud-sdk-operation-name}}{{^vendorExtensions.x-sap-cloud-sdk-operation-name}}{{operationId}}{{/vendorExtensions.x-sap-cloud-sdk-operation-name}}({{#allParams}}{{>nullable_var_annotations}} final {{{dataType}}} {{paramName}}{{^-last}}, {{/-last}}{{/allParams}}) throws OpenApiRequestException { + {{>operationBody}} + } + {{/hasOptionalParams}} /** - * {{summary}} - * {{notes}} - {{#allParams}} - * @param {{paramName}} {{description}}{{#required}} (required){{/required}}{{^required}} (optional{{^isContainer}}{{#defaultValue}}, default to {{.}}{{/defaultValue}}{{/isContainer}}){{/required}} - {{/allParams}} - * @param additionalHeaders additionalHeaders for this call + *

{{summary}} + *

{{notes}} + {{#responses}} + *

{{code}}{{#message}} - {{message}}{{/message}} + {{/responses}} + {{#requiredParams}} + * @param {{paramName}} + {{#description}} + * {{description}} + {{/description}} + {{^description}} + * The value for the parameter {{paramName}} + {{/description}} + {{/requiredParams}} {{#returnType}} - * @return {{returnType}} + * @return {{returnType}} {{/returnType}} - * @throws ApiException if fails to make API call - {{#isDeprecated}} - * @deprecated - {{/isDeprecated}} + {{^returnType}} + * @return An OpenApiResponse containing the status code of the HttpResponse. + {{/returnType}} + * @throws OpenApiRequestException if an error occurs while attempting to invoke the API {{#externalDocs}} * {{description}} * @see {{summary}} Documentation {{/externalDocs}} + {{#isDeprecated}} + * @deprecated + {{/isDeprecated}} */ {{#isDeprecated}} @Deprecated {{/isDeprecated}} - public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}}{{operationId}}({{#allParams}}{{>nullable_var_annotations}} {{{dataType}}} {{paramName}}, {{/allParams}}Map additionalHeaders) throws ApiException { - Object localVarPostBody = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}}; - {{#allParams}}{{#required}} - // verify the required parameter '{{paramName}}' is set - if ({{paramName}} == null) { - throw new ApiException(400, "Missing the required parameter '{{paramName}}' when calling {{operationId}}"); - } - {{/required}}{{/allParams}} - // create path and map variables - String localVarPath = "{{{path}}}"{{#pathParams}} - .replaceAll("\\{" + "{{baseName}}" + "\\}", apiClient.escapeString(apiClient.parameterToString({{{paramName}}}))){{/pathParams}}; - - StringJoiner localVarQueryStringJoiner = new StringJoiner("&"); - String localVarQueryParameterBaseName; - List localVarQueryParams = new ArrayList(); - List localVarCollectionQueryParams = new ArrayList(); - Map localVarHeaderParams = new HashMap(); - Map localVarCookieParams = new HashMap(); - Map localVarFormParams = new HashMap(); - - {{#queryParams}} - {{#isDeepObject}} - localVarQueryParameterBaseName = "{{{baseName}}}"; - {{#isArray}} - for (int i=0; i < {{paramName}}.size(); i++) { - localVarQueryStringJoiner.add({{paramName}}.get(i).toUrlQueryString(String.format(Locale.ROOT, "{{baseName}}[%d]", i))); - } - {{/isArray}} - {{^isArray}} - localVarQueryStringJoiner.add({{paramName}}.toUrlQueryString("{{baseName}}")); - {{/isArray}} - {{/isDeepObject}} - {{^isDeepObject}} - {{#isExplode}} - {{#hasVars}} - {{#vars}} - {{#isArray}} - localVarQueryParams.addAll(apiClient.parameterToPairs("multi", "{{baseName}}", {{paramName}}.{{getter}}())); - {{/isArray}} - {{^isArray}} - localVarQueryParams.addAll(apiClient.parameterToPair("{{baseName}}", {{paramName}}.{{getter}}())); - {{/isArray}} - {{/vars}} - {{/hasVars}} - {{^hasVars}} - {{#isModel}} - localVarQueryStringJoiner.add({{paramName}}.toUrlQueryString()); - {{/isModel}} - {{^isModel}} - {{#collectionFormat}}localVarCollectionQueryParams.addAll(apiClient.parameterToPairs("{{{collectionFormat}}}", {{/collectionFormat}}{{^collectionFormat}}localVarQueryParams.addAll(apiClient.parameterToPair({{/collectionFormat}}"{{baseName}}", {{paramName}})); - {{/isModel}} - {{/hasVars}} - {{/isExplode}} - {{^isExplode}} - {{#collectionFormat}}localVarCollectionQueryParams.addAll(apiClient.parameterToPairs("{{{collectionFormat}}}", {{/collectionFormat}}{{^collectionFormat}}localVarQueryParams.addAll(apiClient.parameterToPair({{/collectionFormat}}"{{baseName}}", {{paramName}})); - {{/isExplode}} - {{/isDeepObject}} - {{/queryParams}} - {{#headerParams}}if ({{paramName}} != null) - localVarHeaderParams.put("{{baseName}}", apiClient.parameterToString({{paramName}})); - {{/headerParams}} - - localVarHeaderParams.putAll(additionalHeaders); - - {{#cookieParams}}if ({{paramName}} != null) - localVarCookieParams.put("{{baseName}}", apiClient.parameterToString({{paramName}})); - {{/cookieParams}} - - {{#formParams}}if ({{paramName}} != null) - localVarFormParams.put("{{baseName}}", {{paramName}}); - {{/formParams}} - - final String[] localVarAccepts = { - {{#produces}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/produces}} - }; - final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts); - - final String[] localVarContentTypes = { - {{#consumes}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/consumes}} - }; - final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes); - - String[] localVarAuthNames = new String[] { {{#authMethods}}"{{name}}"{{^-last}}, {{/-last}}{{/authMethods}} }; - - {{#returnType}} - TypeReference<{{{returnType}}}> localVarReturnType = new TypeReference<{{{returnType}}}>() {}; - return apiClient.invokeAPI( - {{/returnType}} - {{^returnType}} - apiClient.invokeAPI( - {{/returnType}} - localVarPath, - "{{httpMethod}}", - localVarQueryParams, - localVarCollectionQueryParams, - localVarQueryStringJoiner.toString(), - localVarPostBody, - localVarHeaderParams, - localVarCookieParams, - localVarFormParams, - localVarAccept, - localVarContentType, - localVarAuthNames, - {{#returnType}}localVarReturnType{{/returnType}}{{^returnType}}null{{/returnType}} - ); - } - - {{#-last}} - @Override - public T invokeAPI(String url, String method, Object request, TypeReference returnType, Map additionalHeaders) throws ApiException { - String localVarPath = url.replace(apiClient.getBaseURL(), ""); - StringJoiner localVarQueryStringJoiner = new StringJoiner("&"); - List localVarQueryParams = new ArrayList(); - List localVarCollectionQueryParams = new ArrayList(); - Map localVarHeaderParams = new HashMap(); - Map localVarCookieParams = new HashMap(); - Map localVarFormParams = new HashMap(); - - localVarHeaderParams.putAll(additionalHeaders); - - final String[] localVarAccepts = { - {{#produces}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/produces}} - }; - final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts); - - final String[] localVarContentTypes = { - {{#consumes}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/consumes}} - }; - final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes); - - String[] localVarAuthNames = new String[] { {{#authMethods}}"{{name}}"{{^-last}}, {{/-last}}{{/authMethods}} }; - - return apiClient.invokeAPI( - localVarPath, - method, - localVarQueryParams, - localVarCollectionQueryParams, - localVarQueryStringJoiner.toString(), - request, - localVarHeaderParams, - localVarCookieParams, - localVarFormParams, - localVarAccept, - localVarContentType, - localVarAuthNames, - returnType - ); - } - {{/-last}} + {{#vendorExtensions.x-return-nullable}}@Nullable{{/vendorExtensions.x-return-nullable}}{{^vendorExtensions.x-return-nullable}}@Nonnull{{/vendorExtensions.x-return-nullable}} + public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}OpenApiResponse {{/returnType}}{{#vendorExtensions.x-sap-cloud-sdk-operation-name}}{{vendorExtensions.x-sap-cloud-sdk-operation-name}}{{/vendorExtensions.x-sap-cloud-sdk-operation-name}}{{^vendorExtensions.x-sap-cloud-sdk-operation-name}}{{operationId}}{{/vendorExtensions.x-sap-cloud-sdk-operation-name}}({{#requiredParams}}{{>nullable_var_annotations}} final {{{dataType}}} {{paramName}}{{^-last}}, {{/-last}}{{/requiredParams}}) throws OpenApiRequestException { + {{#hasOptionalParams}} + {{#returnType}}return {{/returnType}}{{#vendorExtensions.x-sap-cloud-sdk-operation-name}}{{vendorExtensions.x-sap-cloud-sdk-operation-name}}{{/vendorExtensions.x-sap-cloud-sdk-operation-name}}{{^vendorExtensions.x-sap-cloud-sdk-operation-name}}{{operationId}}{{/vendorExtensions.x-sap-cloud-sdk-operation-name}}({{#hasRequiredParams}}{{#requiredParams}}{{paramName}}{{^-last}}, {{/-last}}{{/requiredParams}}, {{/hasRequiredParams}}{{#optionalParams}}null{{^-last}}, {{/-last}}{{/optionalParams}}); + {{/hasOptionalParams}} + {{^hasOptionalParams}} + {{>operationBody}} + {{/hasOptionalParams}} + } {{/operation}} } {{/operations}} \ No newline at end of file diff --git a/datamodel/openapi/openapi-generator/src/main/resources/openapi-generator/mustache-templates/libraries/apache-httpclient/operationBody.mustache b/datamodel/openapi/openapi-generator/src/main/resources/openapi-generator/mustache-templates/libraries/apache-httpclient/operationBody.mustache new file mode 100644 index 000000000..7f9138e97 --- /dev/null +++ b/datamodel/openapi/openapi-generator/src/main/resources/openapi-generator/mustache-templates/libraries/apache-httpclient/operationBody.mustache @@ -0,0 +1,94 @@ +final Object localVarPostBody = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}}; +{{#allParams}}{{#required}} + // verify the required parameter '{{paramName}}' is set + if ({{paramName}} == null) { + throw new OpenApiRequestException("Missing the required parameter '{{paramName}}' when calling {{#vendorExtensions.x-sap-cloud-sdk-operation-name}}{{vendorExtensions.x-sap-cloud-sdk-operation-name}}{{/vendorExtensions.x-sap-cloud-sdk-operation-name}}{{^vendorExtensions.x-sap-cloud-sdk-operation-name}}{{operationId}}{{/vendorExtensions.x-sap-cloud-sdk-operation-name}}") + .statusCode(400); + } +{{/required}}{{/allParams}} +// create path and map variables +final String localVarPath = "{{{path}}}"{{#pathParams}} + .replaceAll("\\{" + "{{baseName}}" + "\\}", ApiClient.escapeString(ApiClient.parameterToString({{{paramName}}}))){{/pathParams}}; + +final StringJoiner localVarQueryStringJoiner = new StringJoiner("&"); +String localVarQueryParameterBaseName; +final List localVarQueryParams = new ArrayList(); +final List localVarCollectionQueryParams = new ArrayList(); +final Map localVarHeaderParams = new HashMap(); +final Map localVarFormParams = new HashMap(); + + {{#queryParams}} + {{#isDeepObject}} + localVarQueryParameterBaseName = "{{{baseName}}}"; + {{#isArray}} + for (int i=0; i < {{paramName}}.size(); i++) { + localVarQueryStringJoiner.add({{paramName}}.get(i).toUrlQueryString(String.format(Locale.ROOT, "{{baseName}}[%d]", i))); + } + {{/isArray}} + {{^isArray}} + localVarQueryStringJoiner.add({{paramName}}.toUrlQueryString("{{baseName}}")); + {{/isArray}} + {{/isDeepObject}} + {{^isDeepObject}} + {{#isExplode}} + {{#hasVars}} + {{#vars}} + {{#isArray}} + localVarQueryParams.addAll(ApiClient.parameterToPairs("multi", "{{baseName}}", {{paramName}}.{{getter}}())); + {{/isArray}} + {{^isArray}} + localVarQueryParams.addAll(ApiClient.parameterToPair("{{baseName}}", {{paramName}}.{{getter}}())); + {{/isArray}} + {{/vars}} + {{/hasVars}} + {{^hasVars}} + {{#isModel}} + localVarQueryStringJoiner.add({{paramName}}.toUrlQueryString()); + {{/isModel}} + {{^isModel}} + {{#collectionFormat}}localVarCollectionQueryParams.addAll(ApiClient.parameterToPairs("{{{collectionFormat}}}", {{/collectionFormat}}{{^collectionFormat}}localVarQueryParams.addAll(ApiClient.parameterToPair({{/collectionFormat}}"{{baseName}}", {{paramName}})); + {{/isModel}} + {{/hasVars}} + {{/isExplode}} + {{^isExplode}} + {{#collectionFormat}}localVarCollectionQueryParams.addAll(ApiClient.parameterToPairs("{{{collectionFormat}}}", {{/collectionFormat}}{{^collectionFormat}}localVarQueryParams.addAll(ApiClient.parameterToPair({{/collectionFormat}}"{{baseName}}", {{paramName}})); + {{/isExplode}} + {{/isDeepObject}} + {{/queryParams}} + {{#headerParams}}if ({{paramName}} != null) + localVarHeaderParams.put("{{baseName}}", ApiClient.parameterToString({{paramName}})); + {{/headerParams}} + + {{#formParams}}if ({{paramName}} != null) + localVarFormParams.put("{{baseName}}", {{paramName}}); + {{/formParams}} + + final String[] localVarAccepts = { + {{#produces}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/produces}} + }; + final String localVarAccept = ApiClient.selectHeaderAccept(localVarAccepts); + + final String[] localVarContentTypes = { + {{#consumes}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/consumes}} + }; + final String localVarContentType = ApiClient.selectHeaderContentType(localVarContentTypes); + + {{#returnType}} + final TypeReference<{{{returnType}}}> localVarReturnType = new TypeReference<{{{returnType}}}>() {}; + {{/returnType}} + {{^returnType}} + final TypeReference localVarReturnType = new TypeReference() {}; + {{/returnType}} + return apiClient.invokeAPI( + localVarPath, + "{{httpMethod}}", + localVarQueryParams, + localVarCollectionQueryParams, + localVarQueryStringJoiner.toString(), + localVarPostBody, + localVarHeaderParams, + localVarFormParams, + localVarAccept, + localVarContentType, + localVarReturnType + ); diff --git a/datamodel/openapi/openapi-generator/src/main/resources/openapi-generator/mustache-templates/nullable_var_annotations.mustache b/datamodel/openapi/openapi-generator/src/main/resources/openapi-generator/mustache-templates/nullable_var_annotations.mustache new file mode 100644 index 000000000..54ee8cac6 --- /dev/null +++ b/datamodel/openapi/openapi-generator/src/main/resources/openapi-generator/mustache-templates/nullable_var_annotations.mustache @@ -0,0 +1 @@ +{{#required}}{{#isNullable}}@Nullable{{/isNullable}}{{^isNullable}}@Nonnull{{/isNullable}}{{/required}}{{^required}}@Nullable{{/required}} \ No newline at end of file