@team-supercharge/oasg 17.1.0 → 18.0.0-temp-chore-fix-tanstack-query-version.2eaaff54
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +260 -47
- package/bin/oasg +23 -4
- package/bin/save-lock.js +101 -0
- package/bin/target-version.js +84 -0
- package/config.schema.yml +15 -0
- package/package.json +1 -1
- package/targets/android/generate.sh +2 -2
- package/targets/android/generator-config.json +2 -1
- package/targets/android/publish.sh +1 -1
- package/targets/android/templates/build.gradle.mustache +63 -46
- package/targets/angular/generate.sh +35 -9
- package/targets/angular/publish.sh +1 -1
- package/targets/apple-swift/generate.sh +1 -1
- package/targets/apple-swift/publish.sh +1 -1
- package/targets/common.sh +3 -1
- package/targets/contract-testing/generate.sh +1 -1
- package/targets/contract-testing/publish.sh +1 -1
- package/targets/dependency-lock-utils.sh +290 -0
- package/targets/feign/generate.sh +1 -1
- package/targets/feign/publish.sh +1 -1
- package/targets/feign-kotlin/generate.sh +1 -1
- package/targets/feign-kotlin/publish.sh +1 -1
- package/targets/flutter/generate.sh +1 -1
- package/targets/flutter/publish.sh +1 -1
- package/targets/ios/generate.sh +1 -1
- package/targets/ios/publish.sh +1 -1
- package/targets/kmp/generate.sh +1 -1
- package/targets/kmp/publish.sh +1 -1
- package/targets/kmp/templates/build.gradle.kts.mustache +17 -13
- package/targets/kmp/templates/libraries/multiplatform/api.mustache +2 -0
- package/targets/msw/generate.sh +25 -0
- package/targets/msw/generator-config.json +28 -0
- package/targets/msw/templates/apis.index.mustache +9 -0
- package/targets/msw/templates/apis.mustache +178 -0
- package/targets/msw/templates/config.mustache +23 -0
- package/targets/msw/templates/index.mustache +11 -0
- package/targets/msw/templates/modelEnum.mustache +1 -0
- package/targets/msw/templates/modelGeneric.mustache +7 -0
- package/targets/msw/templates/package.mustache +35 -0
- package/targets/msw/templates/prettierrc.mustache +6 -0
- package/targets/msw/templates/tsconfig.mustache +18 -0
- package/targets/msw/templates/utils.mustache +15 -0
- package/targets/nestjs/generate.sh +36 -4
- package/targets/nestjs/publish.sh +1 -1
- package/targets/nestjs/templates/api.service.mustache +8 -14
- package/targets/plain-java/generate.sh +1 -1
- package/targets/plain-java/publish.sh +1 -1
- package/targets/python/generate.sh +1 -1
- package/targets/python/publish.sh +1 -1
- package/targets/python-fastapi/generate.sh +1 -1
- package/targets/python-fastapi/publish.sh +1 -1
- package/targets/python-fastapi-raw-request/generate.sh +1 -1
- package/targets/python-fastapi-raw-request/publish.sh +1 -1
- package/targets/python-legacy/generate.sh +1 -1
- package/targets/python-legacy/publish.sh +1 -1
- package/targets/react/generate.sh +17 -5
- package/targets/react/publish.sh +1 -1
- package/targets/react/templates/hook.mustache +172 -51
- package/targets/react/templates/package.mustache +1 -1
- package/targets/react/templates/use-api.hook.mustache +2 -0
- package/targets/spring/generate.sh +1 -1
- package/targets/spring/publish.sh +1 -1
- package/targets/spring-kotlin/generate.sh +1 -1
- package/targets/spring-kotlin/publish.sh +1 -1
- package/targets/stubby/generate.sh +1 -1
- package/targets/stubby/publish.sh +1 -1
- package/targets/typescript-axios/generate.sh +16 -5
- package/targets/typescript-axios/publish.sh +1 -1
- package/targets/typescript-fetch/generate.sh +17 -5
- package/targets/typescript-fetch/publish.sh +1 -1
- package/targets/android/templates/libraries/jvm-retrofit2/api.mustache +0 -157
- package/targets/android/templates/libraries/jvm-retrofit2/infrastructure/ApiClient.kt.mustache +0 -354
package/targets/android/templates/libraries/jvm-retrofit2/infrastructure/ApiClient.kt.mustache
DELETED
|
@@ -1,354 +0,0 @@
|
|
|
1
|
-
package {{packageName}}.infrastructure
|
|
2
|
-
|
|
3
|
-
{{#hasOAuthMethods}}
|
|
4
|
-
import org.apache.oltu.oauth2.client.request.OAuthClientRequest.AuthenticationRequestBuilder
|
|
5
|
-
import org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuilder
|
|
6
|
-
import {{packageName}}.auth.OAuth
|
|
7
|
-
import {{packageName}}.auth.OAuth.AccessTokenListener
|
|
8
|
-
import {{packageName}}.auth.OAuthFlow
|
|
9
|
-
{{/hasOAuthMethods}}
|
|
10
|
-
{{#hasAuthMethods}}
|
|
11
|
-
{{#authMethods}}
|
|
12
|
-
{{#isBasic}}
|
|
13
|
-
{{#isBasicBasic}}
|
|
14
|
-
import {{packageName}}.auth.HttpBasicAuth
|
|
15
|
-
{{/isBasicBasic}}
|
|
16
|
-
{{#isBasicBearer}}
|
|
17
|
-
import {{packageName}}.auth.HttpBearerAuth
|
|
18
|
-
{{/isBasicBearer}}
|
|
19
|
-
{{/isBasic}}
|
|
20
|
-
{{#isApiKey}}
|
|
21
|
-
import {{packageName}}.auth.ApiKeyAuth
|
|
22
|
-
{{/isApiKey}}
|
|
23
|
-
{{/authMethods}}
|
|
24
|
-
{{/hasAuthMethods}}
|
|
25
|
-
|
|
26
|
-
import okhttp3.Call
|
|
27
|
-
import okhttp3.Interceptor
|
|
28
|
-
import okhttp3.OkHttpClient
|
|
29
|
-
import retrofit2.Retrofit
|
|
30
|
-
import okhttp3.logging.HttpLoggingInterceptor
|
|
31
|
-
import retrofit2.Converter
|
|
32
|
-
import retrofit2.CallAdapter
|
|
33
|
-
import retrofit2.converter.scalars.ScalarsConverterFactory
|
|
34
|
-
{{#useRxJava}}
|
|
35
|
-
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory
|
|
36
|
-
{{/useRxJava}}
|
|
37
|
-
{{#useRxJava2}}
|
|
38
|
-
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
|
|
39
|
-
{{/useRxJava2}}
|
|
40
|
-
{{#useRxJava3}}
|
|
41
|
-
import retrofit2.adapter.rxjava3.RxJava3CallAdapterFactory
|
|
42
|
-
{{/useRxJava3}}
|
|
43
|
-
{{#gson}}
|
|
44
|
-
import com.google.gson.Gson
|
|
45
|
-
import com.google.gson.GsonBuilder
|
|
46
|
-
import retrofit2.converter.gson.GsonConverterFactory
|
|
47
|
-
{{/gson}}
|
|
48
|
-
{{#moshi}}
|
|
49
|
-
import com.squareup.moshi.Moshi
|
|
50
|
-
import retrofit2.converter.moshi.MoshiConverterFactory
|
|
51
|
-
{{/moshi}}
|
|
52
|
-
{{#jackson}}
|
|
53
|
-
import com.fasterxml.jackson.databind.ObjectMapper
|
|
54
|
-
{{/jackson}}
|
|
55
|
-
|
|
56
|
-
{{#kotlinx_serialization}}
|
|
57
|
-
import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory
|
|
58
|
-
import {{packageName}}.infrastructure.Serializer.kotlinxSerializationJson
|
|
59
|
-
import okhttp3.MediaType.Companion.toMediaType
|
|
60
|
-
{{/kotlinx_serialization}}
|
|
61
|
-
|
|
62
|
-
{{#nonPublicApi}}internal {{/nonPublicApi}}class ApiClient(
|
|
63
|
-
private var baseUrl: String = defaultBasePath,
|
|
64
|
-
private val okHttpClientBuilder: OkHttpClient.Builder? = null,
|
|
65
|
-
{{^kotlinx_serialization}}
|
|
66
|
-
private val serializerBuilder: {{#gson}}GsonBuilder{{/gson}}{{#moshi}}Moshi.Builder{{/moshi}}{{#jackson}}ObjectMapper{{/jackson}} = Serializer.{{#gson}}gsonBuilder{{/gson}}{{#moshi}}moshiBuilder{{/moshi}}{{#jackson}}jacksonObjectMapper{{/jackson}},
|
|
67
|
-
{{/kotlinx_serialization}}
|
|
68
|
-
private val callFactory : Call.Factory? = null,
|
|
69
|
-
private val callAdapterFactories: List<CallAdapter.Factory> = listOf(
|
|
70
|
-
{{#useRxJava}}
|
|
71
|
-
RxJavaCallAdapterFactory.create(),
|
|
72
|
-
{{/useRxJava}}
|
|
73
|
-
{{#useRxJava2}}
|
|
74
|
-
RxJava2CallAdapterFactory.create(),
|
|
75
|
-
{{/useRxJava2}}
|
|
76
|
-
{{#useRxJava3}}
|
|
77
|
-
RxJava3CallAdapterFactory.create(),
|
|
78
|
-
{{/useRxJava3}}
|
|
79
|
-
),
|
|
80
|
-
private val converterFactories: List<Converter.Factory> = listOf(
|
|
81
|
-
ScalarsConverterFactory.create(),
|
|
82
|
-
{{#gson}}
|
|
83
|
-
GsonConverterFactory.create(serializerBuilder.create()),
|
|
84
|
-
{{/gson}}
|
|
85
|
-
{{#moshi}}
|
|
86
|
-
MoshiConverterFactory.create(serializerBuilder.build()),
|
|
87
|
-
{{/moshi}}
|
|
88
|
-
{{#kotlinx_serialization}}
|
|
89
|
-
kotlinxSerializationJson.asConverterFactory("application/json".toMediaType()),
|
|
90
|
-
{{/kotlinx_serialization}}
|
|
91
|
-
)
|
|
92
|
-
) {
|
|
93
|
-
private val apiAuthorizations = mutableMapOf<String, Interceptor>()
|
|
94
|
-
var logger: ((String) -> Unit)? = null
|
|
95
|
-
|
|
96
|
-
private val retrofitBuilder: Retrofit.Builder by lazy {
|
|
97
|
-
Retrofit.Builder()
|
|
98
|
-
.baseUrl(baseUrl)
|
|
99
|
-
.apply {
|
|
100
|
-
callAdapterFactories.forEach {
|
|
101
|
-
addCallAdapterFactory(it)
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
.apply {
|
|
105
|
-
converterFactories.forEach {
|
|
106
|
-
addConverterFactory(it)
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
private val clientBuilder: OkHttpClient.Builder by lazy {
|
|
112
|
-
okHttpClientBuilder ?: defaultClientBuilder
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
private val defaultClientBuilder: OkHttpClient.Builder by lazy {
|
|
116
|
-
OkHttpClient()
|
|
117
|
-
.newBuilder()
|
|
118
|
-
.addInterceptor(HttpLoggingInterceptor { message -> logger?.invoke(message) }
|
|
119
|
-
.apply { level = HttpLoggingInterceptor.Level.BODY }
|
|
120
|
-
)
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
init {
|
|
124
|
-
normalizeBaseUrl()
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
{{#hasAuthMethods}}
|
|
128
|
-
constructor(
|
|
129
|
-
baseUrl: String = defaultBasePath,
|
|
130
|
-
okHttpClientBuilder: OkHttpClient.Builder? = null,
|
|
131
|
-
{{^kotlinx_serialization}}serializerBuilder: {{#gson}}GsonBuilder{{/gson}}{{#moshi}}Moshi.Builder{{/moshi}}{{#jackson}}ObjectMapper{{/jackson}} = Serializer.{{#gson}}gsonBuilder{{/gson}}{{#moshi}}moshiBuilder{{/moshi}}{{#jackson}}jacksonObjectMapper{{/jackson}},{{/kotlinx_serialization}}
|
|
132
|
-
authNames: Array<String>
|
|
133
|
-
) : this(baseUrl, okHttpClientBuilder{{^kotlinx_serialization}}, serializerBuilder{{/kotlinx_serialization}}) {
|
|
134
|
-
authNames.forEach { authName ->
|
|
135
|
-
val auth: Interceptor? = when (authName) { {{#authMethods}}
|
|
136
|
-
{{#isBasicBasic}}"{{name}}" -> HttpBasicAuth()
|
|
137
|
-
{{/isBasicBasic}}{{#isBasicBearer}}"{{name}}" -> HttpBearerAuth("{{scheme}}")
|
|
138
|
-
{{/isBasicBearer}}{{#isApiKey}}"{{name}}" -> ApiKeyAuth({{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{#isKeyInQuery}}"query"{{/isKeyInQuery}}{{#isKeyInCookie}}"cookie"{{/isKeyInCookie}}, "{{keyParamName}}")
|
|
139
|
-
{{/isApiKey}}{{#isOAuth}}"{{name}}" -> OAuth(OAuthFlow.{{flow}}, "{{authorizationUrl}}", "{{tokenUrl}}", "{{#scopes}}{{scope}}{{^-last}}, {{/-last}}{{/scopes}}")
|
|
140
|
-
{{/isOAuth}}{{^isBasicBasic}}{{^isBasicBearer}}{{^isApiKey}}{{^isOAuth}}"{{name}}" -> null{{/isOAuth}}{{/isApiKey}}{{/isBasicBearer}}{{/isBasicBasic}}{{/authMethods}}
|
|
141
|
-
else -> throw RuntimeException("auth name $authName not found in available auth names")
|
|
142
|
-
}
|
|
143
|
-
if (auth != null) {
|
|
144
|
-
addAuthorization(authName, auth)
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
{{#authMethods}}
|
|
150
|
-
{{#isBasic}}
|
|
151
|
-
{{#isBasicBasic}}
|
|
152
|
-
constructor(
|
|
153
|
-
baseUrl: String = defaultBasePath,
|
|
154
|
-
okHttpClientBuilder: OkHttpClient.Builder? = null,
|
|
155
|
-
{{^kotlinx_serialization}}serializerBuilder: {{#gson}}GsonBuilder{{/gson}}{{#moshi}}Moshi.Builder{{/moshi}}{{#jackson}}ObjectMapper{{/jackson}} = Serializer.{{#gson}}gsonBuilder{{/gson}}{{#moshi}}moshiBuilder{{/moshi}}{{#jackson}}jacksonObjectMapper{{/jackson}},{{/kotlinx_serialization}}
|
|
156
|
-
authName: String,
|
|
157
|
-
username: String,
|
|
158
|
-
password: String
|
|
159
|
-
) : this(baseUrl, okHttpClientBuilder, {{^kotlinx_serialization}}serializerBuilder, {{/kotlinx_serialization}}arrayOf(authName)) {
|
|
160
|
-
setCredentials(username, password)
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
{{/isBasicBasic}}
|
|
164
|
-
{{#isBasicBearer}}
|
|
165
|
-
constructor(
|
|
166
|
-
baseUrl: String = defaultBasePath,
|
|
167
|
-
okHttpClientBuilder: OkHttpClient.Builder? = null,
|
|
168
|
-
{{^kotlinx_serialization}}serializerBuilder: {{#gson}}GsonBuilder{{/gson}}{{#moshi}}Moshi.Builder{{/moshi}}{{#jackson}}ObjectMapper{{/jackson}} = Serializer.{{#gson}}gsonBuilder{{/gson}}{{#moshi}}moshiBuilder{{/moshi}}{{#jackson}}jacksonObjectMapper{{/jackson}},{{/kotlinx_serialization}}
|
|
169
|
-
authName: String,
|
|
170
|
-
bearerToken: String
|
|
171
|
-
) : this(baseUrl, okHttpClientBuilder, {{^kotlinx_serialization}}serializerBuilder, {{/kotlinx_serialization}}arrayOf(authName)) {
|
|
172
|
-
setBearerToken(bearerToken)
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
{{/isBasicBearer}}
|
|
176
|
-
{{/isBasic}}
|
|
177
|
-
{{/authMethods}}
|
|
178
|
-
{{#hasOAuthMethods}}
|
|
179
|
-
constructor(
|
|
180
|
-
baseUrl: String = defaultBasePath,
|
|
181
|
-
okHttpClientBuilder: OkHttpClient.Builder? = null,
|
|
182
|
-
{{^kotlinx_serialization}}serializerBuilder: {{#gson}}GsonBuilder{{/gson}}{{#moshi}}Moshi.Builder{{/moshi}}{{#jackson}}ObjectMapper{{/jackson}} = Serializer.{{#gson}}gsonBuilder{{/gson}}{{#moshi}}moshiBuilder{{/moshi}}{{#jackson}}jacksonObjectMapper{{/jackson}},{{/kotlinx_serialization}}
|
|
183
|
-
authName: String,
|
|
184
|
-
clientId: String,
|
|
185
|
-
secret: String,
|
|
186
|
-
username: String,
|
|
187
|
-
password: String
|
|
188
|
-
) : this(baseUrl, okHttpClientBuilder, {{^kotlinx_serialization}}serializerBuilder, {{/kotlinx_serialization}}arrayOf(authName)) {
|
|
189
|
-
getTokenEndPoint()
|
|
190
|
-
?.setClientId(clientId)
|
|
191
|
-
?.setClientSecret(secret)
|
|
192
|
-
?.setUsername(username)
|
|
193
|
-
?.setPassword(password)
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
{{/hasOAuthMethods}}
|
|
197
|
-
{{#authMethods}}
|
|
198
|
-
{{#isBasic}}
|
|
199
|
-
{{#isBasicBasic}}
|
|
200
|
-
fun setCredentials(username: String, password: String): ApiClient {
|
|
201
|
-
apiAuthorizations.values.runOnFirst<Interceptor, HttpBasicAuth> {
|
|
202
|
-
setCredentials(username, password)
|
|
203
|
-
}
|
|
204
|
-
{{#hasOAuthMethods}}
|
|
205
|
-
apiAuthorizations.values.runOnFirst<Interceptor, OAuth> {
|
|
206
|
-
tokenRequestBuilder.setUsername(username).setPassword(password)
|
|
207
|
-
}
|
|
208
|
-
{{/hasOAuthMethods}}
|
|
209
|
-
return this
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
{{/isBasicBasic}}
|
|
213
|
-
{{^isBasicBasic}}
|
|
214
|
-
{{#hasOAuthMethods}}
|
|
215
|
-
fun setCredentials(username: String, password: String): ApiClient {
|
|
216
|
-
apiAuthorizations.values.runOnFirst<Interceptor, OAuth> {
|
|
217
|
-
tokenRequestBuilder.setUsername(username).setPassword(password)
|
|
218
|
-
}
|
|
219
|
-
return this
|
|
220
|
-
}
|
|
221
|
-
{{/hasOAuthMethods}}
|
|
222
|
-
{{/isBasicBasic}}
|
|
223
|
-
{{#isBasicBearer}}
|
|
224
|
-
fun setBearerToken(bearerToken: String): ApiClient {
|
|
225
|
-
apiAuthorizations.values.runOnFirst<Interceptor, HttpBearerAuth> {
|
|
226
|
-
this.bearerToken = bearerToken
|
|
227
|
-
}
|
|
228
|
-
return this
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
{{/isBasicBearer}}
|
|
232
|
-
{{/isBasic}}
|
|
233
|
-
{{/authMethods}}
|
|
234
|
-
{{/hasAuthMethods}}
|
|
235
|
-
{{#hasOAuthMethods}}
|
|
236
|
-
/**
|
|
237
|
-
* Helper method to configure the token endpoint of the first oauth found in the apiAuthorizations (there should be only one)
|
|
238
|
-
* @return Token request builder
|
|
239
|
-
*/
|
|
240
|
-
fun getTokenEndPoint(): TokenRequestBuilder? {
|
|
241
|
-
var result: TokenRequestBuilder? = null
|
|
242
|
-
apiAuthorizations.values.runOnFirst<Interceptor, OAuth> {
|
|
243
|
-
result = tokenRequestBuilder
|
|
244
|
-
}
|
|
245
|
-
return result
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
/**
|
|
249
|
-
* Helper method to configure authorization endpoint of the first oauth found in the apiAuthorizations (there should be only one)
|
|
250
|
-
* @return Authentication request builder
|
|
251
|
-
*/
|
|
252
|
-
fun getAuthorizationEndPoint(): AuthenticationRequestBuilder? {
|
|
253
|
-
var result: AuthenticationRequestBuilder? = null
|
|
254
|
-
apiAuthorizations.values.runOnFirst<Interceptor, OAuth> {
|
|
255
|
-
result = authenticationRequestBuilder
|
|
256
|
-
}
|
|
257
|
-
return result
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
/**
|
|
261
|
-
* Helper method to pre-set the oauth access token of the first oauth found in the apiAuthorizations (there should be only one)
|
|
262
|
-
* @param accessToken Access token
|
|
263
|
-
* @return ApiClient
|
|
264
|
-
*/
|
|
265
|
-
fun setAccessToken(accessToken: String): ApiClient {
|
|
266
|
-
apiAuthorizations.values.runOnFirst<Interceptor, OAuth> {
|
|
267
|
-
setAccessToken(accessToken)
|
|
268
|
-
}
|
|
269
|
-
return this
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
/**
|
|
273
|
-
* Helper method to configure the oauth accessCode/implicit flow parameters
|
|
274
|
-
* @param clientId Client ID
|
|
275
|
-
* @param clientSecret Client secret
|
|
276
|
-
* @param redirectURI Redirect URI
|
|
277
|
-
* @return ApiClient
|
|
278
|
-
*/
|
|
279
|
-
fun configureAuthorizationFlow(clientId: String, clientSecret: String, redirectURI: String): ApiClient {
|
|
280
|
-
apiAuthorizations.values.runOnFirst<Interceptor, OAuth> {
|
|
281
|
-
tokenRequestBuilder
|
|
282
|
-
.setClientId(clientId)
|
|
283
|
-
.setClientSecret(clientSecret)
|
|
284
|
-
.setRedirectURI(redirectURI)
|
|
285
|
-
authenticationRequestBuilder
|
|
286
|
-
?.setClientId(clientId)
|
|
287
|
-
?.setRedirectURI(redirectURI)
|
|
288
|
-
}
|
|
289
|
-
return this
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
/**
|
|
293
|
-
* Configures a listener which is notified when a new access token is received.
|
|
294
|
-
* @param accessTokenListener Access token listener
|
|
295
|
-
* @return ApiClient
|
|
296
|
-
*/
|
|
297
|
-
fun registerAccessTokenListener(accessTokenListener: AccessTokenListener): ApiClient {
|
|
298
|
-
apiAuthorizations.values.runOnFirst<Interceptor, OAuth> {
|
|
299
|
-
registerAccessTokenListener(accessTokenListener)
|
|
300
|
-
}
|
|
301
|
-
return this
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
{{/hasOAuthMethods}}
|
|
305
|
-
/**
|
|
306
|
-
* Adds an authorization to be used by the client
|
|
307
|
-
* @param authName Authentication name
|
|
308
|
-
* @param authorization Authorization interceptor
|
|
309
|
-
* @return ApiClient
|
|
310
|
-
*/
|
|
311
|
-
fun addAuthorization(authName: String, authorization: Interceptor): ApiClient {
|
|
312
|
-
if (apiAuthorizations.containsKey(authName)) {
|
|
313
|
-
throw RuntimeException("auth name $authName already in api authorizations")
|
|
314
|
-
}
|
|
315
|
-
apiAuthorizations[authName] = authorization
|
|
316
|
-
clientBuilder.addInterceptor(authorization)
|
|
317
|
-
return this
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
fun setLogger(logger: (String) -> Unit): ApiClient {
|
|
321
|
-
this.logger = logger
|
|
322
|
-
return this
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
fun <S> createService(serviceClass: Class<S>): S {
|
|
326
|
-
val usedCallFactory = this.callFactory ?: clientBuilder.build()
|
|
327
|
-
return retrofitBuilder.callFactory(usedCallFactory).build().create(serviceClass)
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
private fun normalizeBaseUrl() {
|
|
331
|
-
if (!baseUrl.endsWith("/")) {
|
|
332
|
-
baseUrl += "/"
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
private inline fun <T, reified U> Iterable<T>.runOnFirst(callback: U.() -> Unit) {
|
|
337
|
-
for (element in this) {
|
|
338
|
-
if (element is U) {
|
|
339
|
-
callback.invoke(element)
|
|
340
|
-
break
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
companion object {
|
|
346
|
-
@JvmStatic
|
|
347
|
-
protected val baseUrlKey = "{{packageName}}.baseUrl"
|
|
348
|
-
|
|
349
|
-
@JvmStatic
|
|
350
|
-
val defaultBasePath: String by lazy {
|
|
351
|
-
System.getProperties().getProperty(baseUrlKey, "{{{basePath}}}")
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
}
|