Class ApiClient
-
- All Implemented Interfaces:
@Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") public class ApiClient extends JavaTimeFormatter
-
-
Field Summary
Fields Modifier and Type Field Description public StringbasePathpublic CloseableHttpClienthttpClientpublic ObjectMapperobjectMapperpublic Map<String, Authentication>authenticationspublic intstatusCodepublic Map<String, List<String>>responseHeaderspublic DateFormatdateFormat
-
Method Summary
Modifier and Type Method Description StringgetBasePath()ApiClientsetBasePath(String basePath)Sets the base path. CloseableHttpClientgetHttpClient()ApiClientsetHttpClient(CloseableHttpClient httpClient)Sets the HTTP client. ObjectMappergetObjectMapper()Returns the current object mapper used for JSON serialization/deserialization. ApiClientsetObjectMapper(ObjectMapper objectMapper)Sets the object mapper. Map<String, Authentication>getAuthentications()Get authentications (key: authentication name, value: authentication). intgetStatusCode()Gets the status code of the previous request Map<String, List<String>>getResponseHeaders()Gets the response headers of the previous request DateFormatgetDateFormat()Get the date format used to parse/format date parameters. ApiClientsetDateFormat(DateFormat dateFormat)Set the date format used to parse/format date parameters. static DateFormatbuildDefaultDateFormat()List<ServerConfiguration>getServers()ApiClientsetServers(List<ServerConfiguration> servers)Sets the server. IntegergetServerIndex()ApiClientsetServerIndex(Integer serverIndex)Sets the server index. Map<String, String>getServerVariables()ApiClientsetServerVariables(Map<String, String> serverVariables)Sets the server variables. AuthenticationgetAuthentication(String authName)Get authentication for the given name. StringgetTempFolderPath()The path of temporary folder used to store downloaded files from endpoints with file response. ApiClientsetApiKey(String apiKey)Helper method to set API key value for the first API key authentication. ApiClientsetApiKeyPrefix(String apiKeyPrefix)Helper method to set API key prefix for the first API key authentication. ApiClientsetUserAgent(String userAgent)Set the User-Agent header's value (by adding to the default header map). ApiClientsetTempFolderPath(String tempFolderPath)Set temp folder path ApiClientaddDefaultHeader(String key, String value)Add a default header. ApiClientaddDefaultCookie(String key, String value)Add a default cookie. booleanisDebugging()Check that whether debugging is enabled for this API client. intgetConnectTimeout()Connect timeout (in milliseconds). ApiClientsetConnectTimeout(int connectionTimeout)Set the connect timeout (in milliseconds). DateparseDate(String str)Parse the given string into Date object. StringformatDate(Date date)Format the given Date object into string. StringparameterToString(Object param)Format the given parameter object into string. List<Pair>parameterToPair(String name, Object value)Formats the specified query parameter to a list containing a single Pairobject.List<Pair>parameterToPairs(String collectionFormat, String name, Collection value)Formats the specified collection query parameters to a list of Pairobjects.booleanisJsonMime(String mime)Check if the given MIME is a JSON MIME. StringselectHeaderAccept(Array<String> accepts)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) StringselectHeaderContentType(Array<String> contentTypes)Select the Content-Type header's value from the given array: if JSON exists in the given array, use it; otherwise use the first one of the array. StringescapeString(String str)Escape the given string to be used as URL query value. HttpEntityserialize(Object obj, Map<String, Object> formParams, ContentType contentType)Serialize the given Java object into string according the given Content-Type (only JSON is supported for now). <T> Tdeserialize(CloseableHttpResponse response, TypeReference<T> valueType)Deserialize response body to Java object according to the Content-Type. <T> TinvokeAPI(String path, String method, List<Pair> queryParams, List<Pair> collectionQueryParams, String urlQueryDeepObject, Object body, Map<String, String> headerParams, Map<String, String> cookieParams, Map<String, Object> formParams, String accept, String contentType, Array<String> authNames, TypeReference<T> returnType)Invoke API by sending HTTP request with the given options. ApiClientsetDebugging(boolean debugging)Enable/disable debugging for this API client. -
-
Method Detail
-
getBasePath
String getBasePath()
-
setBasePath
ApiClient setBasePath(String basePath)
Sets the base path.
- Parameters:
basePath- base path- Returns:
API client
-
getHttpClient
CloseableHttpClient getHttpClient()
-
setHttpClient
ApiClient setHttpClient(CloseableHttpClient httpClient)
Sets the HTTP client.
- Parameters:
httpClient- HTTP client- Returns:
API client
-
getObjectMapper
ObjectMapper getObjectMapper()
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
setObjectMapperin order to trigger HTTP client rebuilding.- Returns:
Object mapper
-
setObjectMapper
ApiClient setObjectMapper(ObjectMapper objectMapper)
Sets the object mapper.
- Parameters:
objectMapper- object mapper- Returns:
API client
-
getAuthentications
Map<String, Authentication> getAuthentications()
Get authentications (key: authentication name, value: authentication).
- Returns:
Map of authentication
-
getStatusCode
int getStatusCode()
Gets the status code of the previous request
- Returns:
Status code
-
getResponseHeaders
Map<String, List<String>> getResponseHeaders()
Gets the response headers of the previous request
- Returns:
Response headers
-
getDateFormat
DateFormat getDateFormat()
Get the date format used to parse/format date parameters.
- Returns:
Date format
-
setDateFormat
ApiClient setDateFormat(DateFormat dateFormat)
Set the date format used to parse/format date parameters.
- Parameters:
dateFormat- Date format- Returns:
API client
-
buildDefaultDateFormat
static DateFormat buildDefaultDateFormat()
-
getServers
List<ServerConfiguration> getServers()
-
setServers
ApiClient setServers(List<ServerConfiguration> servers)
Sets the server.
- Parameters:
servers- a list of server configuration- Returns:
API client
-
getServerIndex
Integer getServerIndex()
-
setServerIndex
ApiClient setServerIndex(Integer serverIndex)
Sets the server index.
- Parameters:
serverIndex- server index- Returns:
API client
-
getServerVariables
Map<String, String> getServerVariables()
-
setServerVariables
ApiClient setServerVariables(Map<String, String> serverVariables)
Sets the server variables.
- Parameters:
serverVariables- server variables- Returns:
API client
-
getAuthentication
Authentication getAuthentication(String authName)
Get authentication for the given name.
- Parameters:
authName- The authentication name- Returns:
The authentication, null if not found
-
getTempFolderPath
String getTempFolderPath()
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.- Returns:
Temp folder path
-
setApiKey
ApiClient setApiKey(String apiKey)
Helper method to set API key value for the first API key authentication.
- Parameters:
apiKey- the API key- Returns:
API client
-
setApiKeyPrefix
ApiClient setApiKeyPrefix(String apiKeyPrefix)
Helper method to set API key prefix for the first API key authentication.
- Parameters:
apiKeyPrefix- API key prefix- Returns:
API client
-
setUserAgent
ApiClient setUserAgent(String userAgent)
Set the User-Agent header's value (by adding to the default header map).
- Parameters:
userAgent- User agent- Returns:
API client
-
setTempFolderPath
ApiClient setTempFolderPath(String tempFolderPath)
Set temp folder path
- Parameters:
tempFolderPath- Temp folder path- Returns:
API client
-
addDefaultHeader
ApiClient addDefaultHeader(String key, String value)
Add a default header.
- Parameters:
key- The header's keyvalue- The header's value- Returns:
API client
-
addDefaultCookie
ApiClient addDefaultCookie(String key, String value)
Add a default cookie.
- Parameters:
key- The cookie's keyvalue- The cookie's value- Returns:
API client
-
isDebugging
boolean isDebugging()
Check that whether debugging is enabled for this API client.
- Returns:
True if debugging is on
-
getConnectTimeout
int getConnectTimeout()
Connect timeout (in milliseconds).
- Returns:
Connection timeout
-
setConnectTimeout
ApiClient setConnectTimeout(int connectionTimeout)
Set the connect timeout (in milliseconds). A value of 0 means no timeout, otherwise values must be between 1 and MAX_VALUE.
- Parameters:
connectionTimeout- Connection timeout in milliseconds- Returns:
API client
-
parseDate
Date parseDate(String str)
Parse the given string into Date object.
- Parameters:
str- String- Returns:
Date
-
formatDate
String formatDate(Date date)
Format the given Date object into string.
- Parameters:
date- Date- Returns:
Date in string format
-
parameterToString
String parameterToString(Object param)
Format the given parameter object into string.
- Parameters:
param- Object- Returns:
Object in string format
-
parameterToPair
List<Pair> parameterToPair(String name, Object value)
Formats the specified query parameter to a list containing a single
Pairobject. Note thatvaluemust not be a collection.- Parameters:
name- The name of the parameter.value- The value of the parameter.- Returns:
A list containing a single
Pairobject.
-
parameterToPairs
List<Pair> parameterToPairs(String collectionFormat, String name, Collection value)
Formats the specified collection query parameters to a list of
Pairobjects. Note that the values of each of the returned Pair objects are percent-encoded.- Parameters:
collectionFormat- The collection format of the parameter.name- The name of the parameter.value- The value of the parameter.- Returns:
A list of
Pairobjects.
-
isJsonMime
boolean isJsonMime(String mime)
Check if the given MIME is a JSON MIME. JSON MIME examples: application/json application/json; charset=UTF8 APPLICATION/JSON application/vnd.company+json
- Parameters:
mime- MIME- Returns:
True if MIME type is boolean
-
selectHeaderAccept
String selectHeaderAccept(Array<String> accepts)
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)
- Parameters:
accepts- The accepts array to select from- Returns:
The Accept header to use. If the given array is empty, null will be returned (not to set the Accept header explicitly).
-
selectHeaderContentType
String selectHeaderContentType(Array<String> contentTypes)
Select the Content-Type header's value from the given array: if JSON exists in the given array, use it; otherwise use the first one of the array.
- Parameters:
contentTypes- The Content-Type array to select from- Returns:
The Content-Type header to use. If the given array is empty, or matches "any", JSON will be used.
-
escapeString
String escapeString(String str)
Escape the given string to be used as URL query value.
- Parameters:
str- String- Returns:
Escaped string
-
serialize
HttpEntity serialize(Object obj, Map<String, Object> formParams, ContentType contentType)
Serialize the given Java object into string according the given Content-Type (only JSON is supported for now).
- Parameters:
obj- ObjectformParams- Form parameterscontentType- Content type- Returns:
Object
-
deserialize
<T> T deserialize(CloseableHttpResponse response, TypeReference<T> valueType)
Deserialize response body to Java object according to the Content-Type.
- Parameters:
response- ResponsevalueType- Return type- Returns:
Deserialized object
-
invokeAPI
<T> T invokeAPI(String path, String method, List<Pair> queryParams, List<Pair> collectionQueryParams, String urlQueryDeepObject, Object body, Map<String, String> headerParams, Map<String, String> cookieParams, Map<String, Object> formParams, String accept, String contentType, Array<String> authNames, TypeReference<T> returnType)
Invoke API by sending HTTP request with the given options.
- Parameters:
path- The sub-path of the HTTP URLmethod- The request method, one of "GET", "POST", "PUT", and "DELETE"queryParams- The query parameterscollectionQueryParams- The collection query parametersurlQueryDeepObject- A URL query string for deep object parametersbody- The request body object - if it is not binary, otherwise nullheaderParams- The header parameterscookieParams- The cookie parametersformParams- The form parametersaccept- The request's Accept headercontentType- The request's Content-Type headerauthNames- The authentications to applyreturnType- Return type- Returns:
The response body in type of string
-
setDebugging
ApiClient setDebugging(boolean debugging)
Enable/disable debugging for this API client.
- Parameters:
debugging- To enable (true) or disable (false) debugging- Returns:
API client
-
-
-
-