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