From eae98938ff2822682299fe0e79816af942877c74 Mon Sep 17 00:00:00 2001 From: Brian Date: Tue, 6 Feb 2024 11:07:22 -0500 Subject: [PATCH 1/5] First commit --- custom_templates/ApiClient.mustache | 887 ++++++++++++++++++++++++++++ custom_templates/api.mustache | 123 ++++ pom.xml | 4 +- 3 files changed, 1012 insertions(+), 2 deletions(-) create mode 100644 custom_templates/ApiClient.mustache create mode 100644 custom_templates/api.mustache diff --git a/custom_templates/ApiClient.mustache b/custom_templates/ApiClient.mustache new file mode 100644 index 00000000..ed5012fc --- /dev/null +++ b/custom_templates/ApiClient.mustache @@ -0,0 +1,887 @@ +{{>licenseInfo}} +package {{invokerPackage}}; + +import com.fasterxml.jackson.annotation.*; +import com.fasterxml.jackson.databind.*; +{{#joda}} +import com.fasterxml.jackson.datatype.joda.JodaModule; +{{/joda}} +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import java.time.OffsetDateTime; +import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider; + +import com.sun.jersey.api.client.Client; +import com.sun.jersey.api.client.ClientResponse; +import com.sun.jersey.api.client.GenericType; +import com.sun.jersey.api.client.config.DefaultClientConfig; +import com.sun.jersey.api.client.filter.GZIPContentEncodingFilter; +import com.sun.jersey.api.client.filter.LoggingFilter; +import com.sun.jersey.api.client.WebResource.Builder; + +import com.sun.jersey.multipart.FormDataMultiPart; +import com.sun.jersey.multipart.file.FileDataBodyPart; + +import {{javaxPackage}}.ws.rs.core.Cookie; +import {{javaxPackage}}.ws.rs.core.Response.Status.Family; +import {{javaxPackage}}.ws.rs.core.MediaType; + +import java.util.Collection; +import java.util.Collections; +import java.util.Map; +import java.util.Map.Entry; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Arrays; +import java.util.ArrayList; +import java.util.Date; +import java.util.TimeZone; + +import java.net.URLEncoder; + +import java.io.File; +import java.io.UnsupportedEncodingException; + +import java.text.DateFormat; + +import {{invokerPackage}}.auth.Authentication; +{{#hasHttpBasicMethods}} +import {{invokerPackage}}.auth.HttpBasicAuth; +{{/hasHttpBasicMethods}} +{{#hasHttpBearerMethods}} +import {{invokerPackage}}.auth.HttpBearerAuth; +{{/hasHttpBearerMethods}} +{{#hasApiKeyMethods}} +import {{invokerPackage}}.auth.ApiKeyAuth; +{{/hasApiKeyMethods}} +{{#hasOAuthMethods}} +import {{invokerPackage}}.auth.OAuth; +{{/hasOAuthMethods}} + +{{>generatedAnnotation}} +public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} { + private Map defaultHeaderMap = new HashMap(); + private Map defaultCookieMap = new HashMap(); + private String basePath = "{{{basePath}}}"; + protected List servers = new ArrayList({{#servers}}{{#-first}}Arrays.asList( +{{/-first}} new ServerConfiguration( + "{{{url}}}", + "{{{description}}}{{^description}}No description provided{{/description}}", + new HashMap(){{#variables}}{{#-first}} {{ +{{/-first}} put("{{{name}}}", new ServerVariable( + "{{{description}}}{{^description}}No description provided{{/description}}", + "{{{defaultValue}}}", + new HashSet( + {{#enumValues}} + {{#-first}} + Arrays.asList( + {{/-first}} + "{{{.}}}"{{^-last}},{{/-last}} + {{#-last}} + ) + {{/-last}} + {{/enumValues}} + ) + )); + {{#-last}} + }}{{/-last}}{{/variables}} + ){{^-last}},{{/-last}} + {{#-last}} + ){{/-last}}{{/servers}}); + protected Integer serverIndex = 0; + protected Map serverVariables = null; + private boolean debugging = false; + private int connectionTimeout = 0; + + private Client httpClient; + private ObjectMapper objectMapper; + + private Map authentications; + + private int statusCode; + private Map> responseHeaders; + + private DateFormat dateFormat; + + public ApiClient() { + objectMapper = new ObjectMapper(); + objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); + objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + objectMapper.configure(DeserializationFeature.FAIL_ON_INVALID_SUBTYPE, false); + objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); + objectMapper.enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING); + objectMapper.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING); + {{#joda}} + objectMapper.registerModule(new JodaModule()); + {{/joda}} + objectMapper.registerModule(new JavaTimeModule()); + objectMapper.setDateFormat(ApiClient.buildDefaultDateFormat()); + + dateFormat = ApiClient.buildDefaultDateFormat(); + + // Set default User-Agent. + setUserAgent("{{{httpUserAgent}}}{{^httpUserAgent}}OpenAPI-Generator/{{{artifactVersion}}}/java{{/httpUserAgent}}"); + + // Setup authentications (key: authentication name, value: authentication). + authentications = new HashMap();{{#authMethods}}{{#isBasic}}{{#isBasicBasic}} + authentications.put("{{name}}", new HttpBasicAuth());{{/isBasicBasic}}{{#isBasicBearer}} + authentications.put("{{name}}", new HttpBearerAuth("{{scheme}}"));{{/isBasicBearer}}{{/isBasic}}{{#isApiKey}} + authentications.put("{{name}}", new ApiKeyAuth({{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{^isKeyInHeader}}"query"{{/isKeyInHeader}}, "{{keyParamName}}"));{{/isApiKey}}{{#isOAuth}} + authentications.put("{{name}}", new OAuth());{{/isOAuth}}{{/authMethods}} + // Prevent the authentications from being modified. + authentications = Collections.unmodifiableMap(authentications); + + rebuildHttpClient(); + } + + public static DateFormat buildDefaultDateFormat() { + return new RFC3339DateFormat(); + } + + /** + * Build the Client used to make HTTP requests with the latest settings, + * i.e. objectMapper and debugging. + * TODO: better to use the Builder Pattern? + * @return API client + */ + public ApiClient rebuildHttpClient() { + // Add the JSON serialization support to Jersey + JacksonJsonProvider jsonProvider = new JacksonJsonProvider(objectMapper); + DefaultClientConfig conf = new DefaultClientConfig(); + conf.getSingletons().add(jsonProvider); + Client client = Client.create(conf); + client.addFilter(new GZIPContentEncodingFilter({{#useGzipFeature}}true{{/useGzipFeature}}{{^useGzipFeature}}false{{/useGzipFeature}})); + if (debugging) { + client.addFilter(new LoggingFilter()); + } + this.httpClient = client; + return this; + } + + /** + * Returns the current object mapper used for JSON serialization/deserialization. + *

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

+ * @return Object mapper + */ + public ObjectMapper getObjectMapper() { + return objectMapper; + } + + public ApiClient setObjectMapper(ObjectMapper objectMapper) { + this.objectMapper = objectMapper; + // Need to rebuild the Client as it depends on object mapper. + rebuildHttpClient(); + return this; + } + + public Client getHttpClient() { + return httpClient; + } + + public ApiClient setHttpClient(Client httpClient) { + this.httpClient = httpClient; + return this; + } + + public String getBasePath() { + return basePath; + } + + public ApiClient setBasePath(String basePath) { + this.basePath = basePath; + this.serverIndex = null; + return this; + } + + public List getServers() { + return servers; + } + + public ApiClient setServers(List servers) { + this.servers = servers; + return this; + } + + public Integer getServerIndex() { + return serverIndex; + } + + public ApiClient setServerIndex(Integer serverIndex) { + this.serverIndex = serverIndex; + return this; + } + + public Map getServerVariables() { + return serverVariables; + } + + public ApiClient setServerVariables(Map serverVariables) { + this.serverVariables = serverVariables; + return this; + } + + /** + * Gets the status code of the previous request + * @return Status code + */ + public int getStatusCode() { + return statusCode; + } + + /** + * Gets the response headers of the previous request + * @return Response headers + */ + public Map> getResponseHeaders() { + return responseHeaders; + } + + /** + * Get authentications (key: authentication name, value: authentication). + * @return Map of authentication + */ + public Map getAuthentications() { + return authentications; + } + + /** + * Get authentication for the given name. + * + * @param authName The authentication name + * @return The authentication, null if not found + */ + public Authentication getAuthentication(String authName) { + return authentications.get(authName); + } + + {{#hasHttpBearerMethods}} + /** + * Helper method to set access token for the first Bearer authentication. + * @param bearerToken Bearer token + * @return API client + */ + public void setBearerToken(String bearerToken) { + for (Authentication auth : authentications.values()) { + if (auth instanceof HttpBearerAuth) { + ((HttpBearerAuth) auth).setBearerToken(bearerToken); + return; + } + } + throw new RuntimeException("No Bearer authentication configured!"); + } + + {{/hasHttpBearerMethods}} + + {{#hasHttpBasicMethods}} + /** + * Helper method to set username for the first HTTP basic authentication. + * @param username Username + */ + public void setUsername(String username) { + for (Authentication auth : authentications.values()) { + if (auth instanceof HttpBasicAuth) { + ((HttpBasicAuth) auth).setUsername(username); + return; + } + } + throw new RuntimeException("No HTTP basic authentication configured!"); + } + + /** + * Helper method to set password for the first HTTP basic authentication. + * @param password Password + */ + public void setPassword(String password) { + for (Authentication auth : authentications.values()) { + if (auth instanceof HttpBasicAuth) { + ((HttpBasicAuth) auth).setPassword(password); + return; + } + } + throw new RuntimeException("No HTTP basic authentication configured!"); + } + + {{/hasHttpBasicMethods}} + + {{#hasApiKeyMethods}} + /** + * Helper method to set API key value for the first API key authentication. + * @param apiKey the API key + */ + public void setApiKey(String apiKey) { + for (Authentication auth : authentications.values()) { + if (auth instanceof ApiKeyAuth) { + ((ApiKeyAuth) auth).setApiKey(apiKey); + return; + } + } + throw new RuntimeException("No API key authentication configured!"); + } + + /** + * Helper method to set API key prefix for the first API key authentication. + * @param apiKeyPrefix API key prefix + */ + public void setApiKeyPrefix(String apiKeyPrefix) { + for (Authentication auth : authentications.values()) { + if (auth instanceof ApiKeyAuth) { + ((ApiKeyAuth) auth).setApiKeyPrefix(apiKeyPrefix); + return; + } + } + throw new RuntimeException("No API key authentication configured!"); + } + + {{/hasApiKeyMethods}} + + {{#hasOAuthMethods}} + /** + * Helper method to set access token for the first OAuth2 authentication. + * @param accessToken Access token + */ + public void setAccessToken(String accessToken) { + for (Authentication auth : authentications.values()) { + if (auth instanceof OAuth) { + ((OAuth) auth).setAccessToken(accessToken); + return; + } + } + throw new RuntimeException("No OAuth2 authentication configured!"); + } + + {{/hasOAuthMethods}} + + /** + * Set the User-Agent header's value (by adding to the default header map). + * @param userAgent User agent + * @return API client + */ + public ApiClient setUserAgent(String userAgent) { + addDefaultHeader("User-Agent", userAgent); + return this; + } + + /** + * Add a default header. + * + * @param key The header's key + * @param value The header's value + * @return API client + */ + public ApiClient addDefaultHeader(String key, String value) { + defaultHeaderMap.put(key, value); + return this; + } + + /** + * Add a default cookie. + * + * @param key The cookie's key + * @param value The cookie's value + * @return API client + */ + public ApiClient addDefaultCookie(String key, String value) { + defaultCookieMap.put(key, value); + return this; + } + + /** + * Check that whether debugging is enabled for this API client. + * @return True if debugging is on + */ + public boolean isDebugging() { + return debugging; + } + + /** + * Enable/disable debugging for this API client. + * + * @param debugging To enable (true) or disable (false) debugging + * @return API client + */ + public ApiClient setDebugging(boolean debugging) { + this.debugging = debugging; + // Need to rebuild the Client as it depends on the value of debugging. + rebuildHttpClient(); + return this; + } + + /** + * Connect timeout (in milliseconds). + * @return Connection timeout + */ + public int getConnectTimeout() { + return connectionTimeout; + } + + /** + * 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) { + this.connectionTimeout = connectionTimeout; + httpClient.setConnectTimeout(connectionTimeout); + return this; + } + + /** + * 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) { + this.dateFormat = dateFormat; + // Also set the date format for model (de)serialization with Date properties. + this.objectMapper.setDateFormat((DateFormat) dateFormat.clone()); + // Need to rebuild the Client as objectMapper changes. + rebuildHttpClient(); + return this; + } + + /** + * Parse the given string into Date object. + * @param str String + * @return Date + */ + public Date parseDate(String str) { + try { + return dateFormat.parse(str); + } catch (java.text.ParseException e) { + throw new RuntimeException(e); + } + } + + /** + * Format the given Date object into string. + * @param date Date + * @return Date in string format + */ + public String formatDate(Date date) { + return dateFormat.format(date); + } + + /** + * Format the given parameter object into string. + * @param param Object + * @return Object in string format + */ + public String parameterToString(Object param) { + if (param == null) { + return ""; + } else if (param instanceof Date) { + return formatDate((Date) param); + } {{#jsr310}}else if (param instanceof OffsetDateTime) { + return formatOffsetDateTime((OffsetDateTime) param); + } {{/jsr310}}else if (param instanceof Collection) { + StringBuilder b = new StringBuilder(); + for(Object o : (Collection)param) { + if(b.length() > 0) { + b.append(','); + } + b.append(String.valueOf(o)); + } + return b.toString(); + } else { + return String.valueOf(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 The name of the parameter. + * @param value The value of the parameter. + * @return A list containing a single {@code Pair} object. + */ + public List parameterToPair(String name, Object value) { + List params = new ArrayList(); + + // preconditions + if (name == null || name.isEmpty() || value == null || value instanceof Collection) return params; + + params.add(new Pair(name, parameterToString(value))); + return params; + } + + /** + * 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 The collection format of the parameter. + * @param name The name of the parameter. + * @param value The value of the parameter. + * @return A list of {@code Pair} objects. + */ + public List parameterToPairs(String collectionFormat, String name, Collection value) { + List params = new ArrayList(); + + // preconditions + if (name == null || name.isEmpty() || value == null) { + return params; + } + + // create the params based on the collection format + if ("multi".equals(collectionFormat)) { + for (Object item : value) { + params.add(new Pair(name, escapeString(parameterToString(item)))); + } + return params; + } + + // collectionFormat is assumed to be "csv" by default + String delimiter = ","; + + // escape all delimiters except commas, which are URI reserved + // characters + if ("ssv".equals(collectionFormat)) { + delimiter = escapeString(" "); + } else if ("tsv".equals(collectionFormat)) { + delimiter = escapeString("\t"); + } else if ("pipes".equals(collectionFormat)) { + delimiter = escapeString("|"); + } + + StringBuilder sb = new StringBuilder() ; + for (Object item : value) { + sb.append(delimiter); + sb.append(escapeString(parameterToString(item))); + } + + params.add(new Pair(name, sb.substring(delimiter.length()))); + + 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) + * + * @param accepts The accepts array to select from + * @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) { + if (accepts.length == 0) { + return null; + } + for (String accept : accepts) { + if (isJsonMime(accept)) { + return accept; + } + } + return StringUtil.join(accepts, ","); + } + + /** + * 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. + * + * @param contentTypes 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) { + if (contentTypes.length == 0 || contentTypes[0].equals("*/*")) { + return "application/json"; + } + for (String contentType : contentTypes) { + if (isJsonMime(contentType)) { + return contentType; + } + } + return contentTypes[0]; + } + + /** + * Escape the given string to be used as URL query value. + * @param str String + * @return Escaped string + */ + public String escapeString(String str) { + try { + return URLEncoder.encode(str, "utf8").replaceAll("\\+", "%20"); + } catch (UnsupportedEncodingException e) { + return str; + } + } + + /** + * Serialize the given Java object into string according the given + * Content-Type (only JSON is supported for now). + * @param obj Object + * @param contentType Content type + * @param formParams Form parameters + * @return Object + * @throws ApiException API exception + */ + public Object serialize(Object obj, String contentType, Map formParams) throws ApiException { + if (contentType.startsWith("multipart/form-data")) { + FormDataMultiPart mp = new FormDataMultiPart(); + for (Entry param: formParams.entrySet()) { + if( param.getValue() instanceof List && !( ( List ) param.getValue() ).isEmpty() + && ( ( List ) param.getValue() ).get( 0 ) instanceof File ) { + @SuppressWarnings( "unchecked" ) + List files = ( List ) param.getValue(); + for( File file : files ) { + mp.bodyPart( new FileDataBodyPart( param.getKey(), file, MediaType.APPLICATION_OCTET_STREAM_TYPE ) ); + } + } else if (param.getValue() instanceof File) { + File file = (File) param.getValue(); + mp.bodyPart(new FileDataBodyPart(param.getKey(), file, MediaType.APPLICATION_OCTET_STREAM_TYPE)); + } else { + mp.field(param.getKey(), parameterToString(param.getValue()), MediaType.MULTIPART_FORM_DATA_TYPE); + } + } + return mp; + } else if (contentType.startsWith("application/x-www-form-urlencoded")) { + return this.getXWWWFormUrlencodedParams(formParams); + } else { + // We let Jersey attempt to serialize the body + return obj; + } + } + + /** + * Build full URL by concatenating base path, the given sub path and query parameters. + * + * @param path The sub path + * @param queryParams The query parameters + * @param collectionQueryParams The collection query parameters + * @return The full URL + */ + private String buildUrl(String path, List queryParams, List collectionQueryParams) { + String baseURL; + if (serverIndex != null) { + if (serverIndex < 0 || serverIndex >= servers.size()) { + throw new ArrayIndexOutOfBoundsException(String.format( + "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; + } + + final StringBuilder url = new StringBuilder(); + url.append(baseURL).append(path); + + if (queryParams != null && !queryParams.isEmpty()) { + // support (constant) query string in `path`, e.g. "/posts?draft=1" + String prefix = path.contains("?") ? "&" : "?"; + for (Pair param : queryParams) { + if (param.getValue() != null) { + if (prefix != null) { + url.append(prefix); + prefix = null; + } else { + url.append("&"); + } + String value = parameterToString(param.getValue()); + url.append(escapeString(param.getName())).append("=").append(escapeString(value)); + } + } + } + + if (collectionQueryParams != null && !collectionQueryParams.isEmpty()) { + String prefix = url.toString().contains("?") ? "&" : "?"; + for (Pair param : collectionQueryParams) { + if (param.getValue() != null) { + if (prefix != null) { + url.append(prefix); + prefix = null; + } else { + url.append("&"); + } + String value = parameterToString(param.getValue()); + // collection query parameter value already escaped as part of parameterToPairs + url.append(escapeString(param.getName())).append("=").append(value); + } + } + } + + return url.toString(); + } + + private ClientResponse getAPIResponse(String path, String method, List queryParams, List collectionQueryParams, Object body, Map headerParams, Map cookieParams, Map formParams, String accept, String contentType, String[] authNames) throws ApiException { + if (body != null && !formParams.isEmpty()) { + throw new ApiException(500, "Cannot have body and form params"); + } + + updateParamsForAuth(authNames, queryParams, headerParams, cookieParams); + + final String url = buildUrl(path, queryParams, collectionQueryParams); + Builder builder; + if (accept == null) { + builder = httpClient.resource(url).getRequestBuilder(); + } else { + builder = httpClient.resource(url).accept(accept); + } + + for (Entry keyValue : headerParams.entrySet()) { + builder = builder.header(keyValue.getKey(), keyValue.getValue()); + } + for (Map.Entry keyValue : defaultHeaderMap.entrySet()) { + if (!headerParams.containsKey(keyValue.getKey())) { + builder = builder.header(keyValue.getKey(), keyValue.getValue()); + } + } + + for (Entry keyValue : cookieParams.entrySet()) { + builder = builder.cookie(new Cookie(keyValue.getKey(), keyValue.getValue())); + } + for (Map.Entry keyValue : defaultCookieMap.entrySet()) { + if (!cookieParams.containsKey(keyValue.getKey())) { + builder = builder.cookie(new Cookie(keyValue.getKey(), keyValue.getValue())); + } + } + + ClientResponse response = null; + + if ("GET".equals(method)) { + response = (ClientResponse) builder.get(ClientResponse.class); + } else if ("POST".equals(method)) { + response = builder.type(contentType).post(ClientResponse.class, serialize(body, contentType, formParams)); + } else if ("PUT".equals(method)) { + response = builder.type(contentType).put(ClientResponse.class, serialize(body, contentType, formParams)); + } else if ("DELETE".equals(method)) { + response = builder.type(contentType).delete(ClientResponse.class, serialize(body, contentType, formParams)); + } else if ("PATCH".equals(method)) { + response = builder.type(contentType).header("X-HTTP-Method-Override", "PATCH").post(ClientResponse.class, serialize(body, contentType, formParams)); + } else if ("HEAD".equals(method)) { + response = builder.head(); + } else { + throw new ApiException(500, "unknown method type " + method); + } + return response; + } + + /** + * Invoke API by sending HTTP request with the given options. + * + * @param Type + * @param path The sub-path of the HTTP URL + * @param method The request method, one of "GET", "POST", "PUT", and "DELETE" + * @param queryParams The query parameters + * @param collectionQueryParams The collection query parameters + * @param body 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 API exception + */ + public T invokeAPI(String path, String method, List queryParams, List collectionQueryParams, Object body, Map headerParams, Map cookieParams, Map formParams, String accept, String contentType, String[] authNames, GenericType returnType) throws ApiException { + + ClientResponse response = getAPIResponse(path, method, queryParams, collectionQueryParams, body, headerParams, cookieParams, formParams, accept, contentType, authNames); + + statusCode = response.getStatusInfo().getStatusCode(); + responseHeaders = response.getHeaders(); + + if(response.getStatusInfo().getStatusCode() == ClientResponse.Status.NO_CONTENT.getStatusCode()) { + return null; + } else if (response.getStatusInfo().getFamily() == Family.SUCCESSFUL) { + if (returnType == null) + return null; + else + return response.getEntity(returnType); + } else { + String message = "error"; + String respBody = null; + if (response.hasEntity()) { + try { + respBody = response.getEntity(String.class); + message = respBody; + } catch (RuntimeException e) { + // e.printStackTrace(); + } + } + throw new ApiException( + response.getStatusInfo().getStatusCode(), + message, + response.getHeaders(), + respBody); + } + } + + /** + * 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 + */ + private 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); + } + } + + /** + * Encode the given form parameters as request body. + * @param formParams Form parameters + * @return HTTP form encoded parameters + */ + private String getXWWWFormUrlencodedParams(Map formParams) { + StringBuilder formParamBuilder = new StringBuilder(); + + for (Entry param : formParams.entrySet()) { + String valueStr = parameterToString(param.getValue()); + try { + formParamBuilder.append(URLEncoder.encode(param.getKey(), "utf8")) + .append("=") + .append(URLEncoder.encode(valueStr, "utf8")); + formParamBuilder.append("&"); + } catch (UnsupportedEncodingException e) { + // move on to next + } + } + + String encodedFormParams = formParamBuilder.toString(); + if (encodedFormParams.endsWith("&")) { + encodedFormParams = encodedFormParams.substring(0, encodedFormParams.length() - 1); + } + + return encodedFormParams; + } +} diff --git a/custom_templates/api.mustache b/custom_templates/api.mustache new file mode 100644 index 00000000..43428e2b --- /dev/null +++ b/custom_templates/api.mustache @@ -0,0 +1,123 @@ +{{>licenseInfo}} +package {{package}}; + +import com.sun.jersey.api.client.GenericType; + +import {{invokerPackage}}.ApiException; +import {{invokerPackage}}.ApiClient; +import {{invokerPackage}}.Configuration; +import {{modelPackage}}.*; +import {{invokerPackage}}.Pair; + +{{#imports}}import {{import}}; +{{/imports}} + + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +{{>generatedAnnotation}} +{{#operations}} +public class {{classname}} { + private ApiClient apiClient; + + public {{classname}}() { + this(Configuration.getDefaultApiClient()); + } + + public {{classname}}(ApiClient apiClient) { + this.apiClient = apiClient; + } + + public ApiClient getApiClient() { + return apiClient; + } + + public void setApiClient(ApiClient apiClient) { + this.apiClient = apiClient; + } + + {{#operation}} + /** + * {{summary}} + * {{notes}} + {{#allParams}} + * @param {{paramName}} {{description}}{{#required}} (required){{/required}}{{^required}} (optional{{^isContainer}}{{#defaultValue}}, default to {{.}}{{/defaultValue}}){{/isContainer}}{{/required}} + {{/allParams}} + {{#returnType}} + * @return {{.}} + {{/returnType}} + * @throws ApiException if fails to make API call + {{#isDeprecated}} + * @deprecated + {{/isDeprecated}} + {{#externalDocs}} + * {{description}} + * @see {{summary}} Documentation + {{/externalDocs}} + */ + {{#isDeprecated}} + @Deprecated + {{/isDeprecated}} + public {{#returnType}}{{{.}}} {{/returnType}}{{^returnType}}void {{/returnType}}{{operationId}}({{#allParams}}{{{dataType}}} {{paramName}}{{^-last}}, {{/-last}}{{/allParams}}) 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({{{paramName}}}.toString())){{/pathParams}}; + + // query params + List localVarQueryParams = new ArrayList(); + List localVarCollectionQueryParams = new ArrayList(); + Map localVarHeaderParams = new HashMap(); + Map localVarCookieParams = new HashMap(); + Map localVarFormParams = new HashMap(); + + {{#queryParams}} + {{#collectionFormat}}localVarCollectionQueryParams.addAll(apiClient.parameterToPairs("{{{.}}}", {{/collectionFormat}}{{^collectionFormat}}localVarQueryParams.addAll(apiClient.parameterToPair({{/collectionFormat}}"{{baseName}}", {{paramName}})); + {{/queryParams}} + + {{#headerParams}}if ({{paramName}} != null) + localVarHeaderParams.put("{{baseName}}", apiClient.parameterToString({{paramName}})); + {{/headerParams}} + + {{#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}} + }; + + if (contentType == null) { + final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes); + } + + String[] localVarAuthNames = new String[] { {{#authMethods}}"{{name}}"{{^-last}}, {{/-last}}{{/authMethods}} }; + + {{#returnType}} + GenericType<{{{returnType}}}> localVarReturnType = new GenericType<{{{returnType}}}>() {}; + return apiClient.invokeAPI(localVarPath, "{{httpMethod}}", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarCookieParams, localVarFormParams, localVarAccept, localVarContentType, localVarAuthNames, localVarReturnType); + {{/returnType}}{{^returnType}} + apiClient.invokeAPI(localVarPath, "{{httpMethod}}", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarCookieParams, localVarFormParams, localVarAccept, localVarContentType, localVarAuthNames, null); + {{/returnType}} + } + {{/operation}} +} +{{/operations}} diff --git a/pom.xml b/pom.xml index 42bf2633..dc3cb00d 100644 --- a/pom.xml +++ b/pom.xml @@ -292,7 +292,7 @@ org.projectlombok lombok - 1.18.24 + 1.18.30 provided @@ -419,7 +419,7 @@ org.projectlombok lombok - 1.18.24 + 1.18.30 provided From 378ca2782eca2a98edeeaa378882477b568c7a34 Mon Sep 17 00:00:00 2001 From: Brian Date: Tue, 6 Feb 2024 11:07:40 -0500 Subject: [PATCH 2/5] Second commit --- custom_templates/ApiClient.mustache | 887 ------------------ openapi-config.yml | 3 +- pom.xml | 2 +- .../java/com/bandwidth/sdk/api/MediaApi.java | 10 +- .../com/bandwidth/sdk/api/MediaApiTest.java | 3 +- 5 files changed, 11 insertions(+), 894 deletions(-) delete mode 100644 custom_templates/ApiClient.mustache diff --git a/custom_templates/ApiClient.mustache b/custom_templates/ApiClient.mustache deleted file mode 100644 index ed5012fc..00000000 --- a/custom_templates/ApiClient.mustache +++ /dev/null @@ -1,887 +0,0 @@ -{{>licenseInfo}} -package {{invokerPackage}}; - -import com.fasterxml.jackson.annotation.*; -import com.fasterxml.jackson.databind.*; -{{#joda}} -import com.fasterxml.jackson.datatype.joda.JodaModule; -{{/joda}} -import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; -import java.time.OffsetDateTime; -import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider; - -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.ClientResponse; -import com.sun.jersey.api.client.GenericType; -import com.sun.jersey.api.client.config.DefaultClientConfig; -import com.sun.jersey.api.client.filter.GZIPContentEncodingFilter; -import com.sun.jersey.api.client.filter.LoggingFilter; -import com.sun.jersey.api.client.WebResource.Builder; - -import com.sun.jersey.multipart.FormDataMultiPart; -import com.sun.jersey.multipart.file.FileDataBodyPart; - -import {{javaxPackage}}.ws.rs.core.Cookie; -import {{javaxPackage}}.ws.rs.core.Response.Status.Family; -import {{javaxPackage}}.ws.rs.core.MediaType; - -import java.util.Collection; -import java.util.Collections; -import java.util.Map; -import java.util.Map.Entry; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Arrays; -import java.util.ArrayList; -import java.util.Date; -import java.util.TimeZone; - -import java.net.URLEncoder; - -import java.io.File; -import java.io.UnsupportedEncodingException; - -import java.text.DateFormat; - -import {{invokerPackage}}.auth.Authentication; -{{#hasHttpBasicMethods}} -import {{invokerPackage}}.auth.HttpBasicAuth; -{{/hasHttpBasicMethods}} -{{#hasHttpBearerMethods}} -import {{invokerPackage}}.auth.HttpBearerAuth; -{{/hasHttpBearerMethods}} -{{#hasApiKeyMethods}} -import {{invokerPackage}}.auth.ApiKeyAuth; -{{/hasApiKeyMethods}} -{{#hasOAuthMethods}} -import {{invokerPackage}}.auth.OAuth; -{{/hasOAuthMethods}} - -{{>generatedAnnotation}} -public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} { - private Map defaultHeaderMap = new HashMap(); - private Map defaultCookieMap = new HashMap(); - private String basePath = "{{{basePath}}}"; - protected List servers = new ArrayList({{#servers}}{{#-first}}Arrays.asList( -{{/-first}} new ServerConfiguration( - "{{{url}}}", - "{{{description}}}{{^description}}No description provided{{/description}}", - new HashMap(){{#variables}}{{#-first}} {{ -{{/-first}} put("{{{name}}}", new ServerVariable( - "{{{description}}}{{^description}}No description provided{{/description}}", - "{{{defaultValue}}}", - new HashSet( - {{#enumValues}} - {{#-first}} - Arrays.asList( - {{/-first}} - "{{{.}}}"{{^-last}},{{/-last}} - {{#-last}} - ) - {{/-last}} - {{/enumValues}} - ) - )); - {{#-last}} - }}{{/-last}}{{/variables}} - ){{^-last}},{{/-last}} - {{#-last}} - ){{/-last}}{{/servers}}); - protected Integer serverIndex = 0; - protected Map serverVariables = null; - private boolean debugging = false; - private int connectionTimeout = 0; - - private Client httpClient; - private ObjectMapper objectMapper; - - private Map authentications; - - private int statusCode; - private Map> responseHeaders; - - private DateFormat dateFormat; - - public ApiClient() { - objectMapper = new ObjectMapper(); - objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); - objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - objectMapper.configure(DeserializationFeature.FAIL_ON_INVALID_SUBTYPE, false); - objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); - objectMapper.enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING); - objectMapper.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING); - {{#joda}} - objectMapper.registerModule(new JodaModule()); - {{/joda}} - objectMapper.registerModule(new JavaTimeModule()); - objectMapper.setDateFormat(ApiClient.buildDefaultDateFormat()); - - dateFormat = ApiClient.buildDefaultDateFormat(); - - // Set default User-Agent. - setUserAgent("{{{httpUserAgent}}}{{^httpUserAgent}}OpenAPI-Generator/{{{artifactVersion}}}/java{{/httpUserAgent}}"); - - // Setup authentications (key: authentication name, value: authentication). - authentications = new HashMap();{{#authMethods}}{{#isBasic}}{{#isBasicBasic}} - authentications.put("{{name}}", new HttpBasicAuth());{{/isBasicBasic}}{{#isBasicBearer}} - authentications.put("{{name}}", new HttpBearerAuth("{{scheme}}"));{{/isBasicBearer}}{{/isBasic}}{{#isApiKey}} - authentications.put("{{name}}", new ApiKeyAuth({{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{^isKeyInHeader}}"query"{{/isKeyInHeader}}, "{{keyParamName}}"));{{/isApiKey}}{{#isOAuth}} - authentications.put("{{name}}", new OAuth());{{/isOAuth}}{{/authMethods}} - // Prevent the authentications from being modified. - authentications = Collections.unmodifiableMap(authentications); - - rebuildHttpClient(); - } - - public static DateFormat buildDefaultDateFormat() { - return new RFC3339DateFormat(); - } - - /** - * Build the Client used to make HTTP requests with the latest settings, - * i.e. objectMapper and debugging. - * TODO: better to use the Builder Pattern? - * @return API client - */ - public ApiClient rebuildHttpClient() { - // Add the JSON serialization support to Jersey - JacksonJsonProvider jsonProvider = new JacksonJsonProvider(objectMapper); - DefaultClientConfig conf = new DefaultClientConfig(); - conf.getSingletons().add(jsonProvider); - Client client = Client.create(conf); - client.addFilter(new GZIPContentEncodingFilter({{#useGzipFeature}}true{{/useGzipFeature}}{{^useGzipFeature}}false{{/useGzipFeature}})); - if (debugging) { - client.addFilter(new LoggingFilter()); - } - this.httpClient = client; - return this; - } - - /** - * Returns the current object mapper used for JSON serialization/deserialization. - *

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

- * @return Object mapper - */ - public ObjectMapper getObjectMapper() { - return objectMapper; - } - - public ApiClient setObjectMapper(ObjectMapper objectMapper) { - this.objectMapper = objectMapper; - // Need to rebuild the Client as it depends on object mapper. - rebuildHttpClient(); - return this; - } - - public Client getHttpClient() { - return httpClient; - } - - public ApiClient setHttpClient(Client httpClient) { - this.httpClient = httpClient; - return this; - } - - public String getBasePath() { - return basePath; - } - - public ApiClient setBasePath(String basePath) { - this.basePath = basePath; - this.serverIndex = null; - return this; - } - - public List getServers() { - return servers; - } - - public ApiClient setServers(List servers) { - this.servers = servers; - return this; - } - - public Integer getServerIndex() { - return serverIndex; - } - - public ApiClient setServerIndex(Integer serverIndex) { - this.serverIndex = serverIndex; - return this; - } - - public Map getServerVariables() { - return serverVariables; - } - - public ApiClient setServerVariables(Map serverVariables) { - this.serverVariables = serverVariables; - return this; - } - - /** - * Gets the status code of the previous request - * @return Status code - */ - public int getStatusCode() { - return statusCode; - } - - /** - * Gets the response headers of the previous request - * @return Response headers - */ - public Map> getResponseHeaders() { - return responseHeaders; - } - - /** - * Get authentications (key: authentication name, value: authentication). - * @return Map of authentication - */ - public Map getAuthentications() { - return authentications; - } - - /** - * Get authentication for the given name. - * - * @param authName The authentication name - * @return The authentication, null if not found - */ - public Authentication getAuthentication(String authName) { - return authentications.get(authName); - } - - {{#hasHttpBearerMethods}} - /** - * Helper method to set access token for the first Bearer authentication. - * @param bearerToken Bearer token - * @return API client - */ - public void setBearerToken(String bearerToken) { - for (Authentication auth : authentications.values()) { - if (auth instanceof HttpBearerAuth) { - ((HttpBearerAuth) auth).setBearerToken(bearerToken); - return; - } - } - throw new RuntimeException("No Bearer authentication configured!"); - } - - {{/hasHttpBearerMethods}} - - {{#hasHttpBasicMethods}} - /** - * Helper method to set username for the first HTTP basic authentication. - * @param username Username - */ - public void setUsername(String username) { - for (Authentication auth : authentications.values()) { - if (auth instanceof HttpBasicAuth) { - ((HttpBasicAuth) auth).setUsername(username); - return; - } - } - throw new RuntimeException("No HTTP basic authentication configured!"); - } - - /** - * Helper method to set password for the first HTTP basic authentication. - * @param password Password - */ - public void setPassword(String password) { - for (Authentication auth : authentications.values()) { - if (auth instanceof HttpBasicAuth) { - ((HttpBasicAuth) auth).setPassword(password); - return; - } - } - throw new RuntimeException("No HTTP basic authentication configured!"); - } - - {{/hasHttpBasicMethods}} - - {{#hasApiKeyMethods}} - /** - * Helper method to set API key value for the first API key authentication. - * @param apiKey the API key - */ - public void setApiKey(String apiKey) { - for (Authentication auth : authentications.values()) { - if (auth instanceof ApiKeyAuth) { - ((ApiKeyAuth) auth).setApiKey(apiKey); - return; - } - } - throw new RuntimeException("No API key authentication configured!"); - } - - /** - * Helper method to set API key prefix for the first API key authentication. - * @param apiKeyPrefix API key prefix - */ - public void setApiKeyPrefix(String apiKeyPrefix) { - for (Authentication auth : authentications.values()) { - if (auth instanceof ApiKeyAuth) { - ((ApiKeyAuth) auth).setApiKeyPrefix(apiKeyPrefix); - return; - } - } - throw new RuntimeException("No API key authentication configured!"); - } - - {{/hasApiKeyMethods}} - - {{#hasOAuthMethods}} - /** - * Helper method to set access token for the first OAuth2 authentication. - * @param accessToken Access token - */ - public void setAccessToken(String accessToken) { - for (Authentication auth : authentications.values()) { - if (auth instanceof OAuth) { - ((OAuth) auth).setAccessToken(accessToken); - return; - } - } - throw new RuntimeException("No OAuth2 authentication configured!"); - } - - {{/hasOAuthMethods}} - - /** - * Set the User-Agent header's value (by adding to the default header map). - * @param userAgent User agent - * @return API client - */ - public ApiClient setUserAgent(String userAgent) { - addDefaultHeader("User-Agent", userAgent); - return this; - } - - /** - * Add a default header. - * - * @param key The header's key - * @param value The header's value - * @return API client - */ - public ApiClient addDefaultHeader(String key, String value) { - defaultHeaderMap.put(key, value); - return this; - } - - /** - * Add a default cookie. - * - * @param key The cookie's key - * @param value The cookie's value - * @return API client - */ - public ApiClient addDefaultCookie(String key, String value) { - defaultCookieMap.put(key, value); - return this; - } - - /** - * Check that whether debugging is enabled for this API client. - * @return True if debugging is on - */ - public boolean isDebugging() { - return debugging; - } - - /** - * Enable/disable debugging for this API client. - * - * @param debugging To enable (true) or disable (false) debugging - * @return API client - */ - public ApiClient setDebugging(boolean debugging) { - this.debugging = debugging; - // Need to rebuild the Client as it depends on the value of debugging. - rebuildHttpClient(); - return this; - } - - /** - * Connect timeout (in milliseconds). - * @return Connection timeout - */ - public int getConnectTimeout() { - return connectionTimeout; - } - - /** - * 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) { - this.connectionTimeout = connectionTimeout; - httpClient.setConnectTimeout(connectionTimeout); - return this; - } - - /** - * 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) { - this.dateFormat = dateFormat; - // Also set the date format for model (de)serialization with Date properties. - this.objectMapper.setDateFormat((DateFormat) dateFormat.clone()); - // Need to rebuild the Client as objectMapper changes. - rebuildHttpClient(); - return this; - } - - /** - * Parse the given string into Date object. - * @param str String - * @return Date - */ - public Date parseDate(String str) { - try { - return dateFormat.parse(str); - } catch (java.text.ParseException e) { - throw new RuntimeException(e); - } - } - - /** - * Format the given Date object into string. - * @param date Date - * @return Date in string format - */ - public String formatDate(Date date) { - return dateFormat.format(date); - } - - /** - * Format the given parameter object into string. - * @param param Object - * @return Object in string format - */ - public String parameterToString(Object param) { - if (param == null) { - return ""; - } else if (param instanceof Date) { - return formatDate((Date) param); - } {{#jsr310}}else if (param instanceof OffsetDateTime) { - return formatOffsetDateTime((OffsetDateTime) param); - } {{/jsr310}}else if (param instanceof Collection) { - StringBuilder b = new StringBuilder(); - for(Object o : (Collection)param) { - if(b.length() > 0) { - b.append(','); - } - b.append(String.valueOf(o)); - } - return b.toString(); - } else { - return String.valueOf(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 The name of the parameter. - * @param value The value of the parameter. - * @return A list containing a single {@code Pair} object. - */ - public List parameterToPair(String name, Object value) { - List params = new ArrayList(); - - // preconditions - if (name == null || name.isEmpty() || value == null || value instanceof Collection) return params; - - params.add(new Pair(name, parameterToString(value))); - return params; - } - - /** - * 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 The collection format of the parameter. - * @param name The name of the parameter. - * @param value The value of the parameter. - * @return A list of {@code Pair} objects. - */ - public List parameterToPairs(String collectionFormat, String name, Collection value) { - List params = new ArrayList(); - - // preconditions - if (name == null || name.isEmpty() || value == null) { - return params; - } - - // create the params based on the collection format - if ("multi".equals(collectionFormat)) { - for (Object item : value) { - params.add(new Pair(name, escapeString(parameterToString(item)))); - } - return params; - } - - // collectionFormat is assumed to be "csv" by default - String delimiter = ","; - - // escape all delimiters except commas, which are URI reserved - // characters - if ("ssv".equals(collectionFormat)) { - delimiter = escapeString(" "); - } else if ("tsv".equals(collectionFormat)) { - delimiter = escapeString("\t"); - } else if ("pipes".equals(collectionFormat)) { - delimiter = escapeString("|"); - } - - StringBuilder sb = new StringBuilder() ; - for (Object item : value) { - sb.append(delimiter); - sb.append(escapeString(parameterToString(item))); - } - - params.add(new Pair(name, sb.substring(delimiter.length()))); - - 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) - * - * @param accepts The accepts array to select from - * @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) { - if (accepts.length == 0) { - return null; - } - for (String accept : accepts) { - if (isJsonMime(accept)) { - return accept; - } - } - return StringUtil.join(accepts, ","); - } - - /** - * 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. - * - * @param contentTypes 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) { - if (contentTypes.length == 0 || contentTypes[0].equals("*/*")) { - return "application/json"; - } - for (String contentType : contentTypes) { - if (isJsonMime(contentType)) { - return contentType; - } - } - return contentTypes[0]; - } - - /** - * Escape the given string to be used as URL query value. - * @param str String - * @return Escaped string - */ - public String escapeString(String str) { - try { - return URLEncoder.encode(str, "utf8").replaceAll("\\+", "%20"); - } catch (UnsupportedEncodingException e) { - return str; - } - } - - /** - * Serialize the given Java object into string according the given - * Content-Type (only JSON is supported for now). - * @param obj Object - * @param contentType Content type - * @param formParams Form parameters - * @return Object - * @throws ApiException API exception - */ - public Object serialize(Object obj, String contentType, Map formParams) throws ApiException { - if (contentType.startsWith("multipart/form-data")) { - FormDataMultiPart mp = new FormDataMultiPart(); - for (Entry param: formParams.entrySet()) { - if( param.getValue() instanceof List && !( ( List ) param.getValue() ).isEmpty() - && ( ( List ) param.getValue() ).get( 0 ) instanceof File ) { - @SuppressWarnings( "unchecked" ) - List files = ( List ) param.getValue(); - for( File file : files ) { - mp.bodyPart( new FileDataBodyPart( param.getKey(), file, MediaType.APPLICATION_OCTET_STREAM_TYPE ) ); - } - } else if (param.getValue() instanceof File) { - File file = (File) param.getValue(); - mp.bodyPart(new FileDataBodyPart(param.getKey(), file, MediaType.APPLICATION_OCTET_STREAM_TYPE)); - } else { - mp.field(param.getKey(), parameterToString(param.getValue()), MediaType.MULTIPART_FORM_DATA_TYPE); - } - } - return mp; - } else if (contentType.startsWith("application/x-www-form-urlencoded")) { - return this.getXWWWFormUrlencodedParams(formParams); - } else { - // We let Jersey attempt to serialize the body - return obj; - } - } - - /** - * Build full URL by concatenating base path, the given sub path and query parameters. - * - * @param path The sub path - * @param queryParams The query parameters - * @param collectionQueryParams The collection query parameters - * @return The full URL - */ - private String buildUrl(String path, List queryParams, List collectionQueryParams) { - String baseURL; - if (serverIndex != null) { - if (serverIndex < 0 || serverIndex >= servers.size()) { - throw new ArrayIndexOutOfBoundsException(String.format( - "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; - } - - final StringBuilder url = new StringBuilder(); - url.append(baseURL).append(path); - - if (queryParams != null && !queryParams.isEmpty()) { - // support (constant) query string in `path`, e.g. "/posts?draft=1" - String prefix = path.contains("?") ? "&" : "?"; - for (Pair param : queryParams) { - if (param.getValue() != null) { - if (prefix != null) { - url.append(prefix); - prefix = null; - } else { - url.append("&"); - } - String value = parameterToString(param.getValue()); - url.append(escapeString(param.getName())).append("=").append(escapeString(value)); - } - } - } - - if (collectionQueryParams != null && !collectionQueryParams.isEmpty()) { - String prefix = url.toString().contains("?") ? "&" : "?"; - for (Pair param : collectionQueryParams) { - if (param.getValue() != null) { - if (prefix != null) { - url.append(prefix); - prefix = null; - } else { - url.append("&"); - } - String value = parameterToString(param.getValue()); - // collection query parameter value already escaped as part of parameterToPairs - url.append(escapeString(param.getName())).append("=").append(value); - } - } - } - - return url.toString(); - } - - private ClientResponse getAPIResponse(String path, String method, List queryParams, List collectionQueryParams, Object body, Map headerParams, Map cookieParams, Map formParams, String accept, String contentType, String[] authNames) throws ApiException { - if (body != null && !formParams.isEmpty()) { - throw new ApiException(500, "Cannot have body and form params"); - } - - updateParamsForAuth(authNames, queryParams, headerParams, cookieParams); - - final String url = buildUrl(path, queryParams, collectionQueryParams); - Builder builder; - if (accept == null) { - builder = httpClient.resource(url).getRequestBuilder(); - } else { - builder = httpClient.resource(url).accept(accept); - } - - for (Entry keyValue : headerParams.entrySet()) { - builder = builder.header(keyValue.getKey(), keyValue.getValue()); - } - for (Map.Entry keyValue : defaultHeaderMap.entrySet()) { - if (!headerParams.containsKey(keyValue.getKey())) { - builder = builder.header(keyValue.getKey(), keyValue.getValue()); - } - } - - for (Entry keyValue : cookieParams.entrySet()) { - builder = builder.cookie(new Cookie(keyValue.getKey(), keyValue.getValue())); - } - for (Map.Entry keyValue : defaultCookieMap.entrySet()) { - if (!cookieParams.containsKey(keyValue.getKey())) { - builder = builder.cookie(new Cookie(keyValue.getKey(), keyValue.getValue())); - } - } - - ClientResponse response = null; - - if ("GET".equals(method)) { - response = (ClientResponse) builder.get(ClientResponse.class); - } else if ("POST".equals(method)) { - response = builder.type(contentType).post(ClientResponse.class, serialize(body, contentType, formParams)); - } else if ("PUT".equals(method)) { - response = builder.type(contentType).put(ClientResponse.class, serialize(body, contentType, formParams)); - } else if ("DELETE".equals(method)) { - response = builder.type(contentType).delete(ClientResponse.class, serialize(body, contentType, formParams)); - } else if ("PATCH".equals(method)) { - response = builder.type(contentType).header("X-HTTP-Method-Override", "PATCH").post(ClientResponse.class, serialize(body, contentType, formParams)); - } else if ("HEAD".equals(method)) { - response = builder.head(); - } else { - throw new ApiException(500, "unknown method type " + method); - } - return response; - } - - /** - * Invoke API by sending HTTP request with the given options. - * - * @param Type - * @param path The sub-path of the HTTP URL - * @param method The request method, one of "GET", "POST", "PUT", and "DELETE" - * @param queryParams The query parameters - * @param collectionQueryParams The collection query parameters - * @param body 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 API exception - */ - public T invokeAPI(String path, String method, List queryParams, List collectionQueryParams, Object body, Map headerParams, Map cookieParams, Map formParams, String accept, String contentType, String[] authNames, GenericType returnType) throws ApiException { - - ClientResponse response = getAPIResponse(path, method, queryParams, collectionQueryParams, body, headerParams, cookieParams, formParams, accept, contentType, authNames); - - statusCode = response.getStatusInfo().getStatusCode(); - responseHeaders = response.getHeaders(); - - if(response.getStatusInfo().getStatusCode() == ClientResponse.Status.NO_CONTENT.getStatusCode()) { - return null; - } else if (response.getStatusInfo().getFamily() == Family.SUCCESSFUL) { - if (returnType == null) - return null; - else - return response.getEntity(returnType); - } else { - String message = "error"; - String respBody = null; - if (response.hasEntity()) { - try { - respBody = response.getEntity(String.class); - message = respBody; - } catch (RuntimeException e) { - // e.printStackTrace(); - } - } - throw new ApiException( - response.getStatusInfo().getStatusCode(), - message, - response.getHeaders(), - respBody); - } - } - - /** - * 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 - */ - private 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); - } - } - - /** - * Encode the given form parameters as request body. - * @param formParams Form parameters - * @return HTTP form encoded parameters - */ - private String getXWWWFormUrlencodedParams(Map formParams) { - StringBuilder formParamBuilder = new StringBuilder(); - - for (Entry param : formParams.entrySet()) { - String valueStr = parameterToString(param.getValue()); - try { - formParamBuilder.append(URLEncoder.encode(param.getKey(), "utf8")) - .append("=") - .append(URLEncoder.encode(valueStr, "utf8")); - formParamBuilder.append("&"); - } catch (UnsupportedEncodingException e) { - // move on to next - } - } - - String encodedFormParams = formParamBuilder.toString(); - if (encodedFormParams.endsWith("&")) { - encodedFormParams = encodedFormParams.substring(0, encodedFormParams.length() - 1); - } - - return encodedFormParams; - } -} diff --git a/openapi-config.yml b/openapi-config.yml index 22d7bf8e..8302967b 100644 --- a/openapi-config.yml +++ b/openapi-config.yml @@ -1,11 +1,12 @@ artifactId: bandwidth-sdk -artifactVersion: 9.0.0 +artifactVersion: 9.1.1 artifactDescription: The official client SDK for Bandwidth's Voice, Messaging, MFA, and WebRTC APIs artifactUrl: https://github.com/Bandwidth/java-sdk developerEmail: dx@bandwidth.com developerOrganization: Bandwidth disallowAdditionalPropertiesIfNotPresent: false hideGenerationTimestamp: true +caseInsensitiveResponseHeaders: true groupId: com.bandwidth.sdk invokerPackage: com.bandwidth.sdk apiPackage: com.bandwidth.sdk.api diff --git a/pom.xml b/pom.xml index dc3cb00d..976c99f3 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ bandwidth-sdk jar bandwidth-sdk - 9.0.0 + 9.1.1 https://github.com/Bandwidth/java-sdk The official client SDK for Bandwidth's Voice, Messaging, MFA, and WebRTC APIs diff --git a/src/main/java/com/bandwidth/sdk/api/MediaApi.java b/src/main/java/com/bandwidth/sdk/api/MediaApi.java index 33b0008a..3b721ccc 100644 --- a/src/main/java/com/bandwidth/sdk/api/MediaApi.java +++ b/src/main/java/com/bandwidth/sdk/api/MediaApi.java @@ -677,10 +677,12 @@ public okhttp3.Call uploadMediaCall(String accountId, String mediaId, File body, "video/webm", "video/x-ms-wmv" }; - final String localVarContentType = localVarApiClient.selectHeaderContentType(localVarContentTypes); - if (localVarContentType != null) { - localVarHeaderParams.put("Content-Type", localVarContentType); - } + if (contentType == null) { + final String localVarContentType = localVarApiClient.selectHeaderContentType(localVarContentTypes); + if (localVarContentType != null) { + localVarHeaderParams.put("Content-Type", localVarContentType); + } + } String[] localVarAuthNames = new String[] { "Basic" }; return localVarApiClient.buildCall(basePath, localVarPath, "PUT", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarCookieParams, localVarFormParams, localVarAuthNames, _callback); diff --git a/src/test/java/com/bandwidth/sdk/api/MediaApiTest.java b/src/test/java/com/bandwidth/sdk/api/MediaApiTest.java index 710a81a2..0dedfc4d 100644 --- a/src/test/java/com/bandwidth/sdk/api/MediaApiTest.java +++ b/src/test/java/com/bandwidth/sdk/api/MediaApiTest.java @@ -27,7 +27,7 @@ public class MediaApiTest { ApiClient defaultClient = Configuration.getDefaultApiClient(); HttpBasicAuth Basic = (HttpBasicAuth) defaultClient.getAuthentication("Basic"); - private final MediaApi api = new MediaApi(defaultClient); + private final MediaApi api = new MediaApi(defaultClient.setDebugging(true)); private static String mediaPath = "src/test/java/com/bandwidth/sdk/fixtures/"; private static String mediaFile = "java_cat.jpeg"; @@ -53,6 +53,7 @@ public void uploadMedia() throws ApiException { contentType, cacheControl); + assertThat(response.getStatusCode(), is(204)); } From 3790b39e1d30f73704dab13a40c72a7a9c486e14 Mon Sep 17 00:00:00 2001 From: Brian Date: Thu, 8 Feb 2024 16:51:48 -0500 Subject: [PATCH 3/5] Mustach template --- custom_templates/api.mustache | 2 +- openapi-config.yml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/custom_templates/api.mustache b/custom_templates/api.mustache index 43428e2b..f23f701f 100644 --- a/custom_templates/api.mustache +++ b/custom_templates/api.mustache @@ -106,7 +106,7 @@ public class {{classname}} { }; if (contentType == null) { - final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes); + final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes); } String[] localVarAuthNames = new String[] { {{#authMethods}}"{{name}}"{{^-last}}, {{/-last}}{{/authMethods}} }; diff --git a/openapi-config.yml b/openapi-config.yml index 8302967b..456703fa 100644 --- a/openapi-config.yml +++ b/openapi-config.yml @@ -13,3 +13,4 @@ apiPackage: com.bandwidth.sdk.api modelPackage: com.bandwidth.sdk.model library: okhttp-gson licenseName: MIT +templateDir: custom_templates From 301b4111f3e74a408c64e0d0ff26118759deb4e7 Mon Sep 17 00:00:00 2001 From: Brian Date: Thu, 8 Feb 2024 16:56:32 -0500 Subject: [PATCH 4/5] Tests --- src/test/java/com/bandwidth/sdk/api/MediaApiTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/test/java/com/bandwidth/sdk/api/MediaApiTest.java b/src/test/java/com/bandwidth/sdk/api/MediaApiTest.java index 0dedfc4d..710a81a2 100644 --- a/src/test/java/com/bandwidth/sdk/api/MediaApiTest.java +++ b/src/test/java/com/bandwidth/sdk/api/MediaApiTest.java @@ -27,7 +27,7 @@ public class MediaApiTest { ApiClient defaultClient = Configuration.getDefaultApiClient(); HttpBasicAuth Basic = (HttpBasicAuth) defaultClient.getAuthentication("Basic"); - private final MediaApi api = new MediaApi(defaultClient.setDebugging(true)); + private final MediaApi api = new MediaApi(defaultClient); private static String mediaPath = "src/test/java/com/bandwidth/sdk/fixtures/"; private static String mediaFile = "java_cat.jpeg"; @@ -53,7 +53,6 @@ public void uploadMedia() throws ApiException { contentType, cacheControl); - assertThat(response.getStatusCode(), is(204)); } From 22b77aecbabf3a4dd8a1d2279a3fe980b140b6fe Mon Sep 17 00:00:00 2001 From: Brian Date: Thu, 8 Feb 2024 18:21:02 -0500 Subject: [PATCH 5/5] Removing custom template for now --- README.md | 6 +- build.gradle | 2 +- build.sbt | 2 +- custom_templates/api.mustache | 123 ------------------ openapi-config.yml | 2 - pom.xml | 5 + .../java/com/bandwidth/sdk/ApiClient.java | 2 +- .../java/com/bandwidth/sdk/Configuration.java | 2 +- .../java/com/bandwidth/sdk/api/MediaApi.java | 12 +- 9 files changed, 18 insertions(+), 138 deletions(-) delete mode 100644 custom_templates/api.mustache diff --git a/README.md b/README.md index 6e724b1f..78682df6 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ Add this dependency to your project's POM: com.bandwidth.sdk bandwidth-sdk - 9.0.0 + 9.1.1 compile ``` @@ -56,7 +56,7 @@ Add this dependency to your project's build file: } dependencies { - implementation "com.bandwidth.sdk:bandwidth-sdk:9.0.0" + implementation "com.bandwidth.sdk:bandwidth-sdk:9.1.1" } ``` @@ -70,7 +70,7 @@ mvn clean package Then manually install the following JARs: -* `target/bandwidth-sdk-9.0.0.jar` +* `target/bandwidth-sdk-9.1.1.jar` * `target/lib/*.jar` ## Getting Started diff --git a/build.gradle b/build.gradle index f00a66d6..a1bb6174 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ apply plugin: 'java' apply plugin: 'com.diffplug.spotless' group = 'com.bandwidth.sdk' -version = '9.0.0' +version = '9.1.1' buildscript { repositories { diff --git a/build.sbt b/build.sbt index b836076c..922f61f0 100644 --- a/build.sbt +++ b/build.sbt @@ -2,7 +2,7 @@ lazy val root = (project in file(".")). settings( organization := "com.bandwidth.sdk", name := "bandwidth-sdk", - version := "9.0.0", + version := "9.1.1", scalaVersion := "2.11.4", scalacOptions ++= Seq("-feature"), javacOptions in compile ++= Seq("-Xlint:deprecation"), diff --git a/custom_templates/api.mustache b/custom_templates/api.mustache deleted file mode 100644 index f23f701f..00000000 --- a/custom_templates/api.mustache +++ /dev/null @@ -1,123 +0,0 @@ -{{>licenseInfo}} -package {{package}}; - -import com.sun.jersey.api.client.GenericType; - -import {{invokerPackage}}.ApiException; -import {{invokerPackage}}.ApiClient; -import {{invokerPackage}}.Configuration; -import {{modelPackage}}.*; -import {{invokerPackage}}.Pair; - -{{#imports}}import {{import}}; -{{/imports}} - - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -{{>generatedAnnotation}} -{{#operations}} -public class {{classname}} { - private ApiClient apiClient; - - public {{classname}}() { - this(Configuration.getDefaultApiClient()); - } - - public {{classname}}(ApiClient apiClient) { - this.apiClient = apiClient; - } - - public ApiClient getApiClient() { - return apiClient; - } - - public void setApiClient(ApiClient apiClient) { - this.apiClient = apiClient; - } - - {{#operation}} - /** - * {{summary}} - * {{notes}} - {{#allParams}} - * @param {{paramName}} {{description}}{{#required}} (required){{/required}}{{^required}} (optional{{^isContainer}}{{#defaultValue}}, default to {{.}}{{/defaultValue}}){{/isContainer}}{{/required}} - {{/allParams}} - {{#returnType}} - * @return {{.}} - {{/returnType}} - * @throws ApiException if fails to make API call - {{#isDeprecated}} - * @deprecated - {{/isDeprecated}} - {{#externalDocs}} - * {{description}} - * @see {{summary}} Documentation - {{/externalDocs}} - */ - {{#isDeprecated}} - @Deprecated - {{/isDeprecated}} - public {{#returnType}}{{{.}}} {{/returnType}}{{^returnType}}void {{/returnType}}{{operationId}}({{#allParams}}{{{dataType}}} {{paramName}}{{^-last}}, {{/-last}}{{/allParams}}) 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({{{paramName}}}.toString())){{/pathParams}}; - - // query params - List localVarQueryParams = new ArrayList(); - List localVarCollectionQueryParams = new ArrayList(); - Map localVarHeaderParams = new HashMap(); - Map localVarCookieParams = new HashMap(); - Map localVarFormParams = new HashMap(); - - {{#queryParams}} - {{#collectionFormat}}localVarCollectionQueryParams.addAll(apiClient.parameterToPairs("{{{.}}}", {{/collectionFormat}}{{^collectionFormat}}localVarQueryParams.addAll(apiClient.parameterToPair({{/collectionFormat}}"{{baseName}}", {{paramName}})); - {{/queryParams}} - - {{#headerParams}}if ({{paramName}} != null) - localVarHeaderParams.put("{{baseName}}", apiClient.parameterToString({{paramName}})); - {{/headerParams}} - - {{#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}} - }; - - if (contentType == null) { - final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes); - } - - String[] localVarAuthNames = new String[] { {{#authMethods}}"{{name}}"{{^-last}}, {{/-last}}{{/authMethods}} }; - - {{#returnType}} - GenericType<{{{returnType}}}> localVarReturnType = new GenericType<{{{returnType}}}>() {}; - return apiClient.invokeAPI(localVarPath, "{{httpMethod}}", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarCookieParams, localVarFormParams, localVarAccept, localVarContentType, localVarAuthNames, localVarReturnType); - {{/returnType}}{{^returnType}} - apiClient.invokeAPI(localVarPath, "{{httpMethod}}", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarCookieParams, localVarFormParams, localVarAccept, localVarContentType, localVarAuthNames, null); - {{/returnType}} - } - {{/operation}} -} -{{/operations}} diff --git a/openapi-config.yml b/openapi-config.yml index 456703fa..a54c05fe 100644 --- a/openapi-config.yml +++ b/openapi-config.yml @@ -6,11 +6,9 @@ developerEmail: dx@bandwidth.com developerOrganization: Bandwidth disallowAdditionalPropertiesIfNotPresent: false hideGenerationTimestamp: true -caseInsensitiveResponseHeaders: true groupId: com.bandwidth.sdk invokerPackage: com.bandwidth.sdk apiPackage: com.bandwidth.sdk.api modelPackage: com.bandwidth.sdk.model library: okhttp-gson licenseName: MIT -templateDir: custom_templates diff --git a/pom.xml b/pom.xml index 976c99f3..e4630b3c 100644 --- a/pom.xml +++ b/pom.xml @@ -326,6 +326,11 @@ logging-interceptor ${okhttp-version}
+ + com.sun.jersey + jersey-client + 1.19.4 + com.google.code.gson gson diff --git a/src/main/java/com/bandwidth/sdk/ApiClient.java b/src/main/java/com/bandwidth/sdk/ApiClient.java index 7cce6ad1..7a60f90e 100644 --- a/src/main/java/com/bandwidth/sdk/ApiClient.java +++ b/src/main/java/com/bandwidth/sdk/ApiClient.java @@ -140,7 +140,7 @@ private void init() { json = new JSON(); // Set default User-Agent. - setUserAgent("OpenAPI-Generator/9.0.0/java"); + setUserAgent("OpenAPI-Generator/9.1.1/java"); authentications = new HashMap(); } diff --git a/src/main/java/com/bandwidth/sdk/Configuration.java b/src/main/java/com/bandwidth/sdk/Configuration.java index f4cf608f..1d13dbdc 100644 --- a/src/main/java/com/bandwidth/sdk/Configuration.java +++ b/src/main/java/com/bandwidth/sdk/Configuration.java @@ -15,7 +15,7 @@ @javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") public class Configuration { - public static final String VERSION = "9.0.0"; + public static final String VERSION = "9.1.1"; private static ApiClient defaultApiClient = new ApiClient(); diff --git a/src/main/java/com/bandwidth/sdk/api/MediaApi.java b/src/main/java/com/bandwidth/sdk/api/MediaApi.java index 3b721ccc..b1075f58 100644 --- a/src/main/java/com/bandwidth/sdk/api/MediaApi.java +++ b/src/main/java/com/bandwidth/sdk/api/MediaApi.java @@ -677,12 +677,12 @@ public okhttp3.Call uploadMediaCall(String accountId, String mediaId, File body, "video/webm", "video/x-ms-wmv" }; - if (contentType == null) { - final String localVarContentType = localVarApiClient.selectHeaderContentType(localVarContentTypes); - if (localVarContentType != null) { - localVarHeaderParams.put("Content-Type", localVarContentType); - } - } + if (contentType == null) { + final String localVarContentType = localVarApiClient.selectHeaderContentType(localVarContentTypes); + if (localVarContentType != null) { + localVarHeaderParams.put("Content-Type", localVarContentType); + } + }; String[] localVarAuthNames = new String[] { "Basic" }; return localVarApiClient.buildCall(basePath, localVarPath, "PUT", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarCookieParams, localVarFormParams, localVarAuthNames, _callback);