@@ -64,9 +64,9 @@ import okhttp3.MediaType.Companion.toMediaType
64
64
private var baseUrl: String = defaultBasePath,
65
65
private val okHttpClientBuilder: OkHttpClient.Builder? = null,
66
66
{ {^kotlinx_serialization} }
67
- private val serializerBuilder: { {#gson} }GsonBuilder{ {/gson} }{ {#moshi} }Moshi.Builder{ {/moshi} }{ {#jackson} }ObjectMapper{ {/jackson} } = Serializer.{ {#gson} }gsonBuilder{ {/gson} }{ {#moshi} }moshiBuilder{ {/moshi} }{ {#jackson} }jacksonObjectMapper{ {/jackson} },
67
+ private val serializerBuilder: { {#gson} }GsonBuilder{ {/gson} }{ {#moshi} }Moshi.Builder{ {/moshi} }{ {#jackson} }ObjectMapper{ {/jackson} } = { {#generateOneOfAnyOfWrappers } } { {#gson } }registerTypeAdapterFactoryForAllModels( { {/gson } } { {/generateOneOfAnyOfWrappers } } Serializer.{ {#gson} }gsonBuilder{ {/gson} } { {#generateOneOfAnyOfWrappers } } { {#gson } }) { {/gson } } { {/generateOneOfAnyOfWrappers } }{ {#moshi} }moshiBuilder{ {/moshi} }{ {#jackson} }jacksonObjectMapper{ {/jackson} },
68
68
{ {/kotlinx_serialization} }
69
- private val callFactory : Call.Factory? = null,
69
+ private val callFactory: Call.Factory? = null,
70
70
private val callAdapterFactories: List<CallAdapter .Factory > = listOf(
71
71
{ {#useRxJava} }
72
72
RxJavaCallAdapterFactory.create(),
@@ -148,7 +148,7 @@ import okhttp3.MediaType.Companion.toMediaType
148
148
addAuthorization(authName, auth)
149
149
}
150
150
}
151
- { {#generateOneOfAnyOfWrappers} }
151
+ { {#generateOneOfAnyOfWrappers} }
152
152
{ {^kotlinx_serialization} }
153
153
{ {#gson} }
154
154
{ {#models} }
@@ -162,7 +162,7 @@ import okhttp3.MediaType.Companion.toMediaType
162
162
{ {/models} }
163
163
{ {/gson} }
164
164
{ {/kotlinx_serialization} }
165
- { {/generateOneOfAnyOfWrappers} }
165
+ { {/generateOneOfAnyOfWrappers} }
166
166
}
167
167
168
168
{ {#authMethods} }
@@ -177,21 +177,6 @@ import okhttp3.MediaType.Companion.toMediaType
177
177
password: String
178
178
) : this(baseUrl, okHttpClientBuilder, { {^kotlinx_serialization} }serializerBuilder, { {/kotlinx_serialization} }arrayOf(authName)) {
179
179
setCredentials(username, password)
180
- {{#generateOneOfAnyOfWrappers} }
181
- { {^kotlinx_serialization} }
182
- { {#gson} }
183
- { {#models} }
184
- { {#model} }
185
- { {^isEnum} }
186
- { {^hasChildren} }
187
- serializerBuilder.registerTypeAdapterFactory({ {modelPackage} }.{ {{classname} }}.CustomTypeAdapterFactory())
188
- { {/hasChildren} }
189
- { {/isEnum} }
190
- { {/model} }
191
- { {/models} }
192
- { {/gson} }
193
- { {/kotlinx_serialization} }
194
- { {/generateOneOfAnyOfWrappers} }
195
180
}
196
181
197
182
{ {/isBasicBasic} }
@@ -204,21 +189,6 @@ import okhttp3.MediaType.Companion.toMediaType
204
189
bearerToken: String
205
190
) : this(baseUrl, okHttpClientBuilder, { {^kotlinx_serialization} }serializerBuilder, { {/kotlinx_serialization} }arrayOf(authName)) {
206
191
setBearerToken(bearerToken)
207
- {{#generateOneOfAnyOfWrappers} }
208
- { {^kotlinx_serialization} }
209
- { {#gson} }
210
- { {#models} }
211
- { {#model} }
212
- { {^isEnum} }
213
- { {^hasChildren} }
214
- serializerBuilder.registerTypeAdapterFactory({ {modelPackage} }.{ {{classname} }}.CustomTypeAdapterFactory())
215
- { {/hasChildren} }
216
- { {/isEnum} }
217
- { {/model} }
218
- { {/models} }
219
- { {/gson} }
220
- { {/kotlinx_serialization} }
221
- { {/generateOneOfAnyOfWrappers} }
222
192
}
223
193
224
194
{ {/isBasicBearer} }
@@ -240,21 +210,6 @@ import okhttp3.MediaType.Companion.toMediaType
240
210
?.setClientSecret(secret)
241
211
?.setUsername(username)
242
212
?.setPassword(password)
243
- {{#generateOneOfAnyOfWrappers} }
244
- { {^kotlinx_serialization} }
245
- { {#gson} }
246
- { {#models} }
247
- { {#model} }
248
- { {^isEnum} }
249
- { {^hasChildren} }
250
- serializerBuilder.registerTypeAdapterFactory({ {modelPackage} }.{ {{classname} }}.CustomTypeAdapterFactory())
251
- { {/hasChildren} }
252
- { {/isEnum} }
253
- { {/model} }
254
- { {/models} }
255
- { {/gson} }
256
- { {/kotlinx_serialization} }
257
- { {/generateOneOfAnyOfWrappers} }
258
213
}
259
214
260
215
{ {/hasOAuthMethods} }
@@ -298,9 +253,9 @@ import okhttp3.MediaType.Companion.toMediaType
298
253
{ {/hasAuthMethods} }
299
254
{ {#hasOAuthMethods} }
300
255
/**
301
- * Helper method to configure the token endpoint of the first oauth found in the apiAuthorizations (there should be only one)
302
- * @return Token request builder
303
- */
256
+ * Helper method to configure the token endpoint of the first oauth found in the apiAuthorizations (there should be only one)
257
+ * @return Token request builder
258
+ */
304
259
fun getTokenEndPoint(): TokenRequestBuilder? {
305
260
var result: TokenRequestBuilder? = null
306
261
apiAuthorizations.values.runOnFirst< Interceptor, OAuth> {
@@ -310,9 +265,9 @@ import okhttp3.MediaType.Companion.toMediaType
310
265
}
311
266
312
267
/**
313
- * Helper method to configure authorization endpoint of the first oauth found in the apiAuthorizations (there should be only one)
314
- * @return Authentication request builder
315
- */
268
+ * Helper method to configure authorization endpoint of the first oauth found in the apiAuthorizations (there should be only one)
269
+ * @return Authentication request builder
270
+ */
316
271
fun getAuthorizationEndPoint(): AuthenticationRequestBuilder? {
317
272
var result: AuthenticationRequestBuilder? = null
318
273
apiAuthorizations.values.runOnFirst< Interceptor, OAuth> {
@@ -322,10 +277,10 @@ import okhttp3.MediaType.Companion.toMediaType
322
277
}
323
278
324
279
/**
325
- * Helper method to pre-set the oauth access token of the first oauth found in the apiAuthorizations (there should be only one)
326
- * @param accessToken Access token
327
- * @return ApiClient
328
- */
280
+ * Helper method to pre-set the oauth access token of the first oauth found in the apiAuthorizations (there should be only one)
281
+ * @param accessToken Access token
282
+ * @return ApiClient
283
+ */
329
284
fun setAccessToken(accessToken: String): ApiClient {
330
285
apiAuthorizations.values.runOnFirst< Interceptor, OAuth> {
331
286
setAccessToken(accessToken)
@@ -334,12 +289,12 @@ import okhttp3.MediaType.Companion.toMediaType
334
289
}
335
290
336
291
/**
337
- * Helper method to configure the oauth accessCode/implicit flow parameters
338
- * @param clientId Client ID
339
- * @param clientSecret Client secret
340
- * @param redirectURI Redirect URI
341
- * @return ApiClient
342
- */
292
+ * Helper method to configure the oauth accessCode/implicit flow parameters
293
+ * @param clientId Client ID
294
+ * @param clientSecret Client secret
295
+ * @param redirectURI Redirect URI
296
+ * @return ApiClient
297
+ */
343
298
fun configureAuthorizationFlow(clientId: String, clientSecret: String, redirectURI: String): ApiClient {
344
299
apiAuthorizations.values.runOnFirst< Interceptor, OAuth> {
345
300
tokenRequestBuilder
@@ -354,10 +309,10 @@ import okhttp3.MediaType.Companion.toMediaType
354
309
}
355
310
356
311
/**
357
- * Configures a listener which is notified when a new access token is received.
358
- * @param accessTokenListener Access token listener
359
- * @return ApiClient
360
- */
312
+ * Configures a listener which is notified when a new access token is received.
313
+ * @param accessTokenListener Access token listener
314
+ * @return ApiClient
315
+ */
361
316
fun registerAccessTokenListener(accessTokenListener: AccessTokenListener): ApiClient {
362
317
apiAuthorizations.values.runOnFirst< Interceptor, OAuth> {
363
318
registerAccessTokenListener(accessTokenListener)
@@ -391,6 +346,20 @@ import okhttp3.MediaType.Companion.toMediaType
391
346
return retrofitBuilder.callFactory(usedCallFactory).build().create(serviceClass)
392
347
}
393
348
349
+ { {#generateOneOfAnyOfWrappers} }
350
+ { {^kotlinx_serialization} }
351
+ { {#gson} }
352
+ /**
353
+ * Gets the serializer builder.
354
+ * @return serial builder
355
+ */
356
+ fun getSerializerBuilder(): GsonBuilder {
357
+ return serializerBuilder
358
+ }
359
+
360
+ { {/gson} }
361
+ { {/kotlinx_serialization} }
362
+ { {/generateOneOfAnyOfWrappers} }
394
363
private fun normalizeBaseUrl() {
395
364
if (! baseUrl.endsWith(" /" )) {
396
365
baseUrl += " /"
@@ -399,7 +368,7 @@ import okhttp3.MediaType.Companion.toMediaType
399
368
400
369
private inline fun <T , reified U > Iterable<T >.runOnFirst(callback: U.() -> Unit) {
401
370
for (element in this) {
402
- if (element is U) {
371
+ if (element is U) {
403
372
callback.invoke(element)
404
373
break
405
374
}
@@ -416,3 +385,28 @@ import okhttp3.MediaType.Companion.toMediaType
416
385
}
417
386
}
418
387
}
388
+ { {#generateOneOfAnyOfWrappers} }
389
+ { {^kotlinx_serialization} }
390
+ { {#gson} }
391
+
392
+ /**
393
+ * Registers all models with the type adapter factory.
394
+ *
395
+ * @param gsonBuilder gson builder
396
+ * @return GSON builder
397
+ */
398
+ fun registerTypeAdapterFactoryForAllModels(gsonBuilder: GsonBuilder): GsonBuilder {
399
+ {{#models} }
400
+ { {#model} }
401
+ { {^isEnum} }
402
+ { {^hasChildren} }
403
+ gsonBuilder.registerTypeAdapterFactory({ {modelPackage} }.{ {{classname} }}.CustomTypeAdapterFactory())
404
+ { {/hasChildren} }
405
+ { {/isEnum} }
406
+ { {/model} }
407
+ { {/models} }
408
+ return gsonBuilder
409
+ }
410
+ { {/gson} }
411
+ { {/kotlinx_serialization} }
412
+ { {/generateOneOfAnyOfWrappers} }
0 commit comments