Skip to content

Commit a88a01c

Browse files
committed
Merge branch 'main' of https://github.com/Bandwidth/java-sdk into SWI-8856
2 parents f1db077 + 7b87e95 commit a88a01c

File tree

59 files changed

+2712
-1190
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+2712
-1190
lines changed

.github/workflows/deploy.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ jobs:
3535
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/v}" >> $GITHUB_ENV
3636

3737
- name: Checkout
38-
uses: actions/checkout@v4
38+
uses: actions/checkout@v5
3939

4040
- name: Set up Apache Maven Central
41-
uses: actions/setup-java@v4
41+
uses: actions/setup-java@v5
4242
with:
4343
distribution: 'adopt'
4444
java-version: 21

.github/workflows/test-pr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,5 @@ jobs:
5858
run: |
5959
mvn -B package --file pom.xml -DskipTests
6060
npm install -g @stoplight/prism-cli
61-
prism mock ./bandwidth.yml & (sleep 3; mvn test -Punit-tests)
61+
prism mock ./bandwidth.yml & (sleep 4; mvn test -Punit-tests)
6262
shell: bash

.github/workflows/test-smoke.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ jobs:
3838
MANTECA_APPLICATION_ID: ${{ secrets.MANTECA_APPLICATION_ID }}
3939
steps:
4040
- name: Checkout
41-
uses: actions/checkout@v4
41+
uses: actions/checkout@v5
4242

4343
- name: Set up JDK
44-
uses: actions/setup-java@v4
44+
uses: actions/setup-java@v5
4545
with:
4646
distribution: zulu
4747
java-version: 21
@@ -70,10 +70,10 @@ jobs:
7070
MANTECA_APPLICATION_ID: ${{ secrets.MANTECA_UP_APPLICATION_ID }}
7171
steps:
7272
- name: Checkout
73-
uses: actions/checkout@v4
73+
uses: actions/checkout@v5
7474

7575
- name: Set up JDK
76-
uses: actions/setup-java@v4
76+
uses: actions/setup-java@v5
7777
with:
7878
distribution: zulu
7979
java-version: 21

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ build
2424

2525
.DS_Store
2626
.idea
27-
.settings
27+
.settings/

.settings/org.eclipse.jdt.core.prefs

Lines changed: 0 additions & 576 deletions
This file was deleted.

.settings/org.eclipse.m2e.core.prefs

Lines changed: 0 additions & 4 deletions
This file was deleted.

custom_templates/libraries/okhttp-gson/anyof_model.mustache

Lines changed: 434 additions & 0 deletions
Large diffs are not rendered by default.

docs/PhoneNumberLookupApi.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public class Example {
146146

147147
### Authorization
148148

149-
[Basic](../README.md#Basic), [OAuth2](../README.md#OAuth2)
149+
[Basic](../README.md#Basic)
150150

151151
### HTTP request headers
152152

@@ -187,10 +187,6 @@ public class Example {
187187
Basic.setUsername("YOUR USERNAME");
188188
Basic.setPassword("YOUR PASSWORD");
189189

190-
// Configure OAuth2 access token for authorization: OAuth2
191-
OAuth OAuth2 = (OAuth) defaultClient.getAuthentication("OAuth2");
192-
OAuth2.setAccessToken("YOUR ACCESS TOKEN");
193-
194190
PhoneNumberLookupApi apiInstance = new PhoneNumberLookupApi(defaultClient);
195191
String accountId = "9900000"; // String |
196192
UUID requestId = UUID.fromString("004223a0-8b17-41b1-bf81-20732adf5590"); // UUID |

openapi-config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ modelPackage: com.bandwidth.sdk.model
1414
library: okhttp-gson
1515
licenseName: MIT
1616
useEnumCaseInsensitive: true
17+
useOneOfDiscriminatorLookup: true
1718
templateDir: custom_templates

src/main/java/com/bandwidth/sdk/ApiClient.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
*/
6767
public class ApiClient {
6868

69+
protected String basePath = "http://localhost";
6970
protected String basePath = "http://localhost";
7071
protected List<ServerConfiguration> servers = new ArrayList<ServerConfiguration>(Arrays.asList(
7172
new ServerConfiguration(
@@ -80,21 +81,36 @@ public class ApiClient {
8081
protected Map<String, String> defaultHeaderMap = new HashMap<String, String>();
8182
protected Map<String, String> defaultCookieMap = new HashMap<String, String>();
8283
protected String tempFolderPath = null;
84+
protected boolean debugging = false;
85+
protected Map<String, String> defaultHeaderMap = new HashMap<String, String>();
86+
protected Map<String, String> defaultCookieMap = new HashMap<String, String>();
87+
protected String tempFolderPath = null;
8388

89+
protected Map<String, Authentication> authentications;
8490
protected Map<String, Authentication> authentications;
8591

92+
protected DateFormat dateFormat;
93+
protected DateFormat datetimeFormat;
94+
protected boolean lenientDatetimeFormat;
95+
protected int dateLength;
8696
protected DateFormat dateFormat;
8797
protected DateFormat datetimeFormat;
8898
protected boolean lenientDatetimeFormat;
8999
protected int dateLength;
90100

101+
protected InputStream sslCaCert;
102+
protected boolean verifyingSsl;
103+
protected KeyManager[] keyManagers;
91104
protected InputStream sslCaCert;
92105
protected boolean verifyingSsl;
93106
protected KeyManager[] keyManagers;
94107

108+
protected OkHttpClient httpClient;
109+
protected JSON json;
95110
protected OkHttpClient httpClient;
96111
protected JSON json;
97112

113+
protected HttpLoggingInterceptor loggingInterceptor;
98114
protected HttpLoggingInterceptor loggingInterceptor;
99115

100116
/**
@@ -199,6 +215,7 @@ protected void initHttpClient() {
199215
initHttpClient(Collections.<Interceptor>emptyList());
200216
}
201217

218+
protected void initHttpClient(List<Interceptor> interceptors) {
202219
protected void initHttpClient(List<Interceptor> interceptors) {
203220
OkHttpClient.Builder builder = new OkHttpClient.Builder();
204221
builder.addNetworkInterceptor(getProgressInterceptor());
@@ -209,6 +226,7 @@ protected void initHttpClient(List<Interceptor> interceptors) {
209226
httpClient = builder.build();
210227
}
211228

229+
protected void init() {
212230
protected void init() {
213231
verifyingSsl = true;
214232

@@ -234,6 +252,8 @@ public String getBasePath() {
234252
*
235253
* @param basePath Base path of the URL (e.g http://localhost)
236254
* @return An instance of ApiClient
255+
* @param basePath Base path of the URL (e.g http://localhost)
256+
* @return An instance of ApiClient
237257
*/
238258
public ApiClient setBasePath(String basePath) {
239259
this.basePath = basePath;
@@ -282,6 +302,7 @@ public OkHttpClient getHttpClient() {
282302
*
283303
* @param newHttpClient An instance of OkHttpClient
284304
* @return ApiClient
305+
* @return ApiClient
285306
* @throws java.lang.NullPointerException when newHttpClient is null
286307
*/
287308
public ApiClient setHttpClient(OkHttpClient newHttpClient) {
@@ -789,6 +810,7 @@ public List<Pair> parameterToPair(String name, Object value) {
789810
* @param value The value of the parameter.
790811
* @return A list of {@code Pair} objects.
791812
*/
813+
public List<Pair> parameterToPairs(String collectionFormat, String name, Collection<?> value) {
792814
public List<Pair> parameterToPairs(String collectionFormat, String name, Collection<?> value) {
793815
List<Pair> params = new ArrayList<Pair>();
794816

@@ -897,6 +919,7 @@ public String collectionPathParameterToString(String collectionFormat, Collectio
897919
*/
898920
public String sanitizeFilename(String filename) {
899921
return filename.replaceFirst("^.*[/\\\\]", "");
922+
return filename.replaceFirst("^.*[/\\\\]", "");
900923
}
901924

902925
/**
@@ -1006,6 +1029,8 @@ public <T> T deserialize(Response response, Type returnType) throws ApiException
10061029
return (T) downloadFileFromResponse(response);
10071030
}
10081031

1032+
ResponseBody respBody = response.body();
1033+
if (respBody == null) {
10091034
ResponseBody respBody = response.body();
10101035
if (respBody == null) {
10111036
return null;
@@ -1016,6 +1041,18 @@ public <T> T deserialize(Response response, Type returnType) throws ApiException
10161041
// ensuring a default content type
10171042
contentType = "application/json";
10181043
}
1044+
try {
1045+
if (isJsonMime(contentType)) {
1046+
return JSON.deserialize(respBody.byteStream(), returnType);
1047+
} else if (returnType.equals(String.class)) {
1048+
String respBodyString = respBody.string();
1049+
if (respBodyString.isEmpty()) {
1050+
return null;
1051+
}
1052+
// Expecting string, return the raw response body.
1053+
return (T) respBodyString;
1054+
} else {
1055+
throw new ApiException(
10191056
try {
10201057
if (isJsonMime(contentType)) {
10211058
return JSON.deserialize(respBody.byteStream(), returnType);
@@ -1033,6 +1070,10 @@ public <T> T deserialize(Response response, Type returnType) throws ApiException
10331070
response.headers().toMultimap(),
10341071
response.body().string());
10351072
}
1073+
} catch (IOException e) {
1074+
throw new ApiException(e);
1075+
response.body().string());
1076+
}
10361077
} catch (IOException e) {
10371078
throw new ApiException(e);
10381079
}
@@ -1363,6 +1404,8 @@ public String buildUrl(String baseUrl, String path, List<Pair> queryParams, List
13631404
throw new ArrayIndexOutOfBoundsException(String.format(
13641405
Locale.ROOT,
13651406
"Invalid index %d when selecting the host settings. Must be less than %d", serverIndex, servers.size()
1407+
Locale.ROOT,
1408+
"Invalid index %d when selecting the host settings. Must be less than %d", serverIndex, servers.size()
13661409
));
13671410
}
13681411
baseURL = servers.get(serverIndex).URL(serverVariables);
@@ -1435,10 +1478,12 @@ public void processHeaderParams(Map<String, String> headerParams, Request.Builde
14351478
public void processCookieParams(Map<String, String> cookieParams, Request.Builder reqBuilder) {
14361479
for (Entry<String, String> param : cookieParams.entrySet()) {
14371480
reqBuilder.addHeader("Cookie", String.format(Locale.ROOT, "%s=%s", param.getKey(), param.getValue()));
1481+
reqBuilder.addHeader("Cookie", String.format(Locale.ROOT, "%s=%s", param.getKey(), param.getValue()));
14381482
}
14391483
for (Entry<String, String> param : defaultCookieMap.entrySet()) {
14401484
if (!cookieParams.containsKey(param.getKey())) {
14411485
reqBuilder.addHeader("Cookie", String.format(Locale.ROOT, "%s=%s", param.getKey(), param.getValue()));
1486+
reqBuilder.addHeader("Cookie", String.format(Locale.ROOT, "%s=%s", param.getKey(), param.getValue()));
14421487
}
14431488
}
14441489
}
@@ -1531,6 +1576,7 @@ public String guessContentTypeFromFile(File file) {
15311576
* @param key The key of the Header element
15321577
* @param file The file to add to the Header
15331578
*/
1579+
protected void addPartToMultiPartBuilder(MultipartBody.Builder mpBuilder, String key, File file) {
15341580
protected void addPartToMultiPartBuilder(MultipartBody.Builder mpBuilder, String key, File file) {
15351581
Headers partHeaders = Headers.of("Content-Disposition", "form-data; name=\"" + key + "\"; filename=\"" + file.getName() + "\"");
15361582
MediaType mediaType = MediaType.parse(guessContentTypeFromFile(file));
@@ -1544,6 +1590,7 @@ protected void addPartToMultiPartBuilder(MultipartBody.Builder mpBuilder, String
15441590
* @param key The key of the Header element
15451591
* @param obj The complex object to add to the Header
15461592
*/
1593+
protected void addPartToMultiPartBuilder(MultipartBody.Builder mpBuilder, String key, Object obj) {
15471594
protected void addPartToMultiPartBuilder(MultipartBody.Builder mpBuilder, String key, Object obj) {
15481595
RequestBody requestBody;
15491596
if (obj instanceof String) {
@@ -1566,6 +1613,7 @@ protected void addPartToMultiPartBuilder(MultipartBody.Builder mpBuilder, String
15661613
* Get network interceptor to add it to the httpClient to track download progress for
15671614
* async requests.
15681615
*/
1616+
protected Interceptor getProgressInterceptor() {
15691617
protected Interceptor getProgressInterceptor() {
15701618
return new Interceptor() {
15711619
@Override
@@ -1587,6 +1635,7 @@ public Response intercept(Interceptor.Chain chain) throws IOException {
15871635
* Apply SSL related settings to httpClient according to the current values of
15881636
* verifyingSsl and sslCaCert.
15891637
*/
1638+
protected void applySslSettings() {
15901639
protected void applySslSettings() {
15911640
try {
15921641
TrustManager[] trustManagers;
@@ -1649,6 +1698,7 @@ public boolean verify(String hostname, SSLSession session) {
16491698
}
16501699
}
16511700

1701+
protected KeyStore newEmptyKeyStore(char[] password) throws GeneralSecurityException {
16521702
protected KeyStore newEmptyKeyStore(char[] password) throws GeneralSecurityException {
16531703
try {
16541704
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
@@ -1666,6 +1716,7 @@ protected KeyStore newEmptyKeyStore(char[] password) throws GeneralSecurityExcep
16661716
* @return The string representation of the HTTP request body
16671717
* @throws com.bandwidth.sdk.ApiException If fail to serialize the request body object into a string
16681718
*/
1719+
protected String requestBodyToString(RequestBody requestBody) throws ApiException {
16691720
protected String requestBodyToString(RequestBody requestBody) throws ApiException {
16701721
if (requestBody != null) {
16711722
try {

0 commit comments

Comments
 (0)