@team-supercharge/oasg 13.0.0-test-export-01191261.0 → 13.1.0-kmp-8a9ad834.0
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 +47 -12
- package/bin/oasg +15 -17
- package/config.schema.yml +29 -3
- package/package.json +2 -2
- package/targets/android/generate.sh +2 -2
- package/targets/android/generator-config.json +6 -1
- package/targets/android/templates/build.gradle.mustache +54 -21
- package/targets/android/templates/libraries/jvm-retrofit2/api.mustache +2 -10
- package/targets/android/templates/libraries/jvm-retrofit2/infrastructure/ApiClient.kt.mustache +354 -0
- package/targets/common.sh +0 -8
- package/targets/feign/generator-config.json +4 -3
- package/targets/feign/templates/beanValidation.mustache +2 -7
- package/targets/feign/templates/formParams.mustache +2 -1
- package/targets/feign/templates/libraries/spring-cloud/clientConfiguration.mustache +118 -0
- package/targets/feign/templates/libraries/spring-cloud/pom-sb3.mustache +16 -16
- package/targets/feign/templates/libraries/spring-cloud/pom.mustache +16 -16
- package/targets/feign-kotlin/generator-config.json +3 -3
- package/targets/feign-kotlin/templates/libraries/spring-cloud/pom-sb3.mustache +2 -1
- package/targets/flutter/generate.sh +0 -5
- package/targets/kmp/generate.sh +21 -0
- package/targets/kmp/generator-config.json +12 -0
- package/targets/kmp/publish.sh +11 -0
- package/targets/kmp/templates/build.gradle.kts.mustache +121 -0
- package/targets/kmp/templates/libraries/multiplatform/api.mustache +136 -0
- package/targets/nestjs/generate.sh +1 -0
- package/targets/nestjs/generator-config.json +5 -0
- package/targets/nestjs/templates/api.service.mustache +1 -1
- package/targets/nestjs/templates/reorder-operations.js +1 -1
- package/targets/nestjs/templates/rewrite-path-parameters.js +2 -2
- package/targets/react/generator-config.json +14 -0
- package/targets/spring/generator-config.json +4 -4
- package/targets/spring/templates/libraries/spring-boot/pom-sb3.mustache +247 -0
- package/targets/spring/templates/libraries/spring-boot/pom.mustache +257 -0
- package/targets/spring-kotlin/generator-config.json +3 -3
- package/targets/spring-kotlin/templates/libraries/spring-boot/pom-sb3.mustache +0 -1
- package/targets/spring-kotlin/templates/libraries/spring-boot/pom.mustache +0 -1
- package/targets/.env +0 -3
- package/targets/feign-kotlin/templates/apiInterface.mustache +0 -108
- package/targets/feign-kotlin/templates/dataClassReqVar.mustache +0 -5
- package/targets/react-native/generator-config.json +0 -7
- package/targets/spring-kotlin/templates/dataClassReqVar.mustache +0 -5
- /package/targets/{react-native → react}/generate.sh +0 -0
- /package/targets/{react-native → react}/publish.sh +0 -0
package/targets/android/templates/libraries/jvm-retrofit2/infrastructure/ApiClient.kt.mustache
ADDED
@@ -0,0 +1,354 @@
|
|
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
|
+
}
|
package/targets/common.sh
CHANGED
@@ -9,8 +9,6 @@
|
|
9
9
|
# 8. preRelease - building/publishing a pre-release
|
10
10
|
# 9. templateDir - directory for merged templates
|
11
11
|
|
12
|
-
. $(dirname "$0")/.env
|
13
|
-
|
14
12
|
version=$1
|
15
13
|
binary=$2
|
16
14
|
configFile=$3
|
@@ -21,12 +19,6 @@ generatorId=$7
|
|
21
19
|
preRelease=$8
|
22
20
|
templateDir=$9
|
23
21
|
|
24
|
-
echo "------------------"
|
25
|
-
echo "$PATH"
|
26
|
-
echo "$DART_SDK"
|
27
|
-
echo "$TEST_VARIABLE"
|
28
|
-
echo "------------------"
|
29
|
-
|
30
22
|
echo -e "\n=====\n version:\t$version\n binary:\t$binary\n configFile:\t$configFile\n targetId:\t$targetId\n generatorId:\t$generatorId\n openApiFile:\t$openApiFile\n formatter:\t$formatterBinary\n preRelease:\t$preRelease\n templateDir:\t$templateDir\n ---"
|
31
23
|
|
32
24
|
for paramName in $(cat $configFile | jq -r ".targets[] | select(.id==\"$targetId\") | del(.id) | del(.type) | del(.source) | del(.generator) | del(.generatorId) | del(.templateDir) | keys | .[]"); do
|
@@ -2,6 +2,7 @@
|
|
2
2
|
"library": "spring-cloud",
|
3
3
|
"dateLibrary": "java8",
|
4
4
|
"java8": true,
|
5
|
+
"useTags": true,
|
5
6
|
"hideGenerationTimestamp": true,
|
6
7
|
"booleanGetterPrefix": "is",
|
7
8
|
"generateForOpenFeign": true,
|
@@ -17,9 +18,9 @@
|
|
17
18
|
"java.time.OffsetDateTime": "java.time.Instant",
|
18
19
|
"java.util.Date": "java.time.LocalDate"
|
19
20
|
},
|
20
|
-
"
|
21
|
-
"
|
22
|
-
"
|
21
|
+
"inlineSchemaOptions": {
|
22
|
+
"ARRAY_ITEM_SUFFIX": "",
|
23
|
+
"MAP_ITEM_SUFFIX": "",
|
23
24
|
"SKIP_SCHEMA_REUSE": "true"
|
24
25
|
}
|
25
26
|
}
|
@@ -1,7 +1,2 @@
|
|
1
|
-
{{!
|
2
|
-
{{#required}}{{^isReadOnly}}{{^isNullable}}
|
3
|
-
@NotNull{{/isNullable}}{{/isReadOnly}}
|
4
|
-
{{/required}}{{#isContainer}}{{^isPrimitiveType}}{{^isEnum}}
|
5
|
-
@Valid{{/isEnum}}{{/isPrimitiveType}}{{/isContainer}}{{^isContainer}}{{^isPrimitiveType}}
|
6
|
-
@Valid{{/isPrimitiveType}}{{/isContainer}}
|
7
|
-
{{>beanValidationCore}}
|
1
|
+
{{! only add @NotNull if property not nullable }}
|
2
|
+
{{#required}}{{^isReadOnly}}{{^isNullable}}@NotNull {{/isNullable}}{{/isReadOnly}}{{/required}}{{#isContainer}}{{^isPrimitiveType}}{{^isEnum}}@Valid {{/isEnum}}{{/isPrimitiveType}}{{/isContainer}}{{^isContainer}}{{^isPrimitiveType}}@Valid {{/isPrimitiveType}}{{/isContainer}}{{>beanValidationCore}}
|
@@ -1,2 +1,3 @@
|
|
1
|
-
{{!
|
1
|
+
{{! annotate RequestPart instead of RequestParam when model is not array }}
|
2
|
+
{{! add bean validation conditinally if param is file }}
|
2
3
|
{{#isFormParam}}{{^isFile}}{{>paramDoc}}{{#useBeanValidation}} @Valid{{/useBeanValidation}} {{#isModel}}@RequestPart{{/isModel}}{{^isModel}}{{#isArray}}@RequestPart{{/isArray}}{{^isArray}}@RequestPart{{/isArray}}{{/isModel}}(value = "{{baseName}}"{{#required}}, required = true{{/required}}{{^required}}, required = false{{/required}}){{>dateTimeParam}} {{{dataType}}} {{paramName}}{{/isFile}}{{#isFile}}{{>paramDoc}}{{#useBeanValidation}} @Valid{{/useBeanValidation}} @RequestPart(value = "{{baseName}}"{{#required}}, required = true{{/required}}{{^required}}, required = false{{/required}}) {{#isArray}}List<{{/isArray}}{{#reactive}}Flux<Part>{{/reactive}}{{^reactive}}MultipartFile{{/reactive}}{{#isArray}}>{{/isArray}} {{paramName}}{{/isFile}}{{/isFormParam}}
|
@@ -0,0 +1,118 @@
|
|
1
|
+
{{! import ConditionalOnProperty if any auth methods are anbled }}
|
2
|
+
package {{configPackage}};
|
3
|
+
|
4
|
+
{{#authMethods}}
|
5
|
+
{{#isBasicBasic}}
|
6
|
+
import feign.auth.BasicAuthRequestInterceptor;
|
7
|
+
{{^hasApiKeyMethods}}
|
8
|
+
import org.springframework.beans.factory.annotation.Value;
|
9
|
+
{{/hasApiKeyMethods}}
|
10
|
+
{{/isBasicBasic}}
|
11
|
+
{{/authMethods}}
|
12
|
+
{{#hasAuthMethods}}
|
13
|
+
import org.springframework.context.annotation.Bean;
|
14
|
+
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
15
|
+
{{#hasApiKeyMethods}}
|
16
|
+
import org.springframework.beans.factory.annotation.Value;
|
17
|
+
{{/hasApiKeyMethods}}
|
18
|
+
{{#hasOAuthMethods}}
|
19
|
+
import org.springframework.security.authentication.AnonymousAuthenticationToken;
|
20
|
+
import org.springframework.security.oauth2.client.AuthorizedClientServiceOAuth2AuthorizedClientManager;
|
21
|
+
import org.springframework.security.oauth2.client.OAuth2AuthorizeRequest;
|
22
|
+
import org.springframework.security.oauth2.client.OAuth2AuthorizedClient;
|
23
|
+
import org.springframework.security.oauth2.client.OAuth2AuthorizedClientManager;
|
24
|
+
import org.springframework.security.oauth2.client.OAuth2AuthorizedClientService;
|
25
|
+
import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository;
|
26
|
+
import org.springframework.security.oauth2.core.OAuth2AuthenticationException;
|
27
|
+
import org.springframework.security.oauth2.core.OAuth2AccessToken;
|
28
|
+
import org.springframework.security.core.authority.AuthorityUtils;
|
29
|
+
import org.springframework.http.HttpHeaders;
|
30
|
+
|
31
|
+
import feign.RequestInterceptor;
|
32
|
+
import feign.RequestTemplate;
|
33
|
+
|
34
|
+
{{/hasOAuthMethods}}
|
35
|
+
{{/hasAuthMethods}}
|
36
|
+
import org.springframework.context.annotation.Configuration;
|
37
|
+
|
38
|
+
|
39
|
+
@Configuration
|
40
|
+
public class ClientConfiguration {
|
41
|
+
|
42
|
+
{{#authMethods}}
|
43
|
+
{{#isBasicBasic}}
|
44
|
+
@Value("${{openbrace}}{{#lambda.lowercase}}{{{title}}}{{/lambda.lowercase}}.security.{{{name}}}.username:{{closebrace}}")
|
45
|
+
private String {{{name}}}Username;
|
46
|
+
|
47
|
+
@Value("${{openbrace}}{{#lambda.lowercase}}{{{title}}}{{/lambda.lowercase}}.security.{{{name}}}.password:{{closebrace}}")
|
48
|
+
private String {{{name}}}Password;
|
49
|
+
|
50
|
+
@Bean
|
51
|
+
@ConditionalOnProperty(name = "{{#lambda.lowercase}}{{{title}}}{{/lambda.lowercase}}.security.{{{name}}}.username")
|
52
|
+
public BasicAuthRequestInterceptor {{{name}}}RequestInterceptor() {
|
53
|
+
return new BasicAuthRequestInterceptor(this.{{{name}}}Username, this.{{{name}}}Password);
|
54
|
+
}
|
55
|
+
|
56
|
+
{{/isBasicBasic}}
|
57
|
+
{{#isApiKey}}
|
58
|
+
@Value("${{openbrace}}{{#lambda.lowercase}}{{{title}}}{{/lambda.lowercase}}.security.{{{name}}}.key:{{closebrace}}")
|
59
|
+
private String {{{name}}}Key;
|
60
|
+
|
61
|
+
@Bean
|
62
|
+
@ConditionalOnProperty(name = "{{#lambda.lowercase}}{{{title}}}{{/lambda.lowercase}}.security.{{{name}}}.key")
|
63
|
+
public ApiKeyRequestInterceptor {{{name}}}RequestInterceptor() {
|
64
|
+
return new ApiKeyRequestInterceptor({{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{^isKeyInHeader}}"query"{{/isKeyInHeader}}, "{{{keyParamName}}}", this.{{{name}}}Key);
|
65
|
+
}
|
66
|
+
|
67
|
+
{{/isApiKey}}
|
68
|
+
{{#isOAuth}}
|
69
|
+
private static final String CLIENT_PRINCIPAL_{{#lambda.uppercase}}{{{flow}}}{{/lambda.uppercase}} = "oauth2FeignClient";
|
70
|
+
|
71
|
+
@Bean
|
72
|
+
@ConditionalOnProperty( prefix = "spring.security.oauth2.client.registration.{{{name}}}{{#lambda.pascalcase}}{{{flow}}}{{/lambda.pascalcase}}", name = "enabled", havingValue = "true" )
|
73
|
+
public OAuth2RequestInterceptor {{{flow}}}OAuth2RequestInterceptor(final OAuth2AuthorizedClientManager {{{flow}}}AuthorizedClientManager ) {
|
74
|
+
return new OAuth2RequestInterceptor(OAuth2AuthorizeRequest.withClientRegistrationId("{{{name}}}{{#lambda.pascalcase}}{{{flow}}}{{/lambda.pascalcase}}")
|
75
|
+
.principal( new AnonymousAuthenticationToken( CLIENT_PRINCIPAL_{{#lambda.uppercase}}{{{flow}}}{{/lambda.uppercase}}, CLIENT_PRINCIPAL_{{#lambda.uppercase}}{{{flow}}}{{/lambda.uppercase}}, AuthorityUtils.createAuthorityList( "ROLE_ANONYMOUS" ) ) )
|
76
|
+
.build(), {{{flow}}}AuthorizedClientManager );
|
77
|
+
}
|
78
|
+
|
79
|
+
@Bean
|
80
|
+
@ConditionalOnProperty( prefix = "spring.security.oauth2.client.registration.{{{name}}}{{#lambda.pascalcase}}{{{flow}}}{{/lambda.pascalcase}}", name = "enabled", havingValue = "true" )
|
81
|
+
public OAuth2AuthorizedClientManager {{{flow}}}AuthorizedClientManager(ClientRegistrationRepository clientRegistrationRepository,
|
82
|
+
OAuth2AuthorizedClientService authorizedClientService ) {
|
83
|
+
return new AuthorizedClientServiceOAuth2AuthorizedClientManager( clientRegistrationRepository, authorizedClientService );
|
84
|
+
}
|
85
|
+
{{/isOAuth}}
|
86
|
+
{{/authMethods}}
|
87
|
+
{{#hasOAuthMethods}}
|
88
|
+
public static class OAuth2RequestInterceptor implements RequestInterceptor {
|
89
|
+
|
90
|
+
private final OAuth2AuthorizedClientManager oAuth2AuthorizedClientManager;
|
91
|
+
private final OAuth2AuthorizeRequest oAuth2AuthorizeRequest;
|
92
|
+
|
93
|
+
public OAuth2RequestInterceptor(OAuth2AuthorizeRequest oAuth2AuthorizeRequest,OAuth2AuthorizedClientManager oAuth2AuthorizedClientManager){
|
94
|
+
this.oAuth2AuthorizeRequest = oAuth2AuthorizeRequest;
|
95
|
+
this.oAuth2AuthorizedClientManager = oAuth2AuthorizedClientManager;
|
96
|
+
}
|
97
|
+
|
98
|
+
@Override
|
99
|
+
public void apply( final RequestTemplate template ) {
|
100
|
+
template.header( HttpHeaders.AUTHORIZATION, getBearerToken() );
|
101
|
+
}
|
102
|
+
|
103
|
+
public OAuth2AccessToken getAccessToken() {
|
104
|
+
final OAuth2AuthorizedClient authorizedClient = oAuth2AuthorizedClientManager.authorize(oAuth2AuthorizeRequest);
|
105
|
+
if (authorizedClient == null) {
|
106
|
+
throw new OAuth2AuthenticationException( "Client failed to authenticate");
|
107
|
+
}
|
108
|
+
return authorizedClient.getAccessToken();
|
109
|
+
}
|
110
|
+
|
111
|
+
public String getBearerToken() {
|
112
|
+
final OAuth2AccessToken accessToken = getAccessToken();
|
113
|
+
return String.format( "%s %s", accessToken.getTokenType().getValue(), accessToken.getTokenValue() );
|
114
|
+
}
|
115
|
+
}
|
116
|
+
{{/hasOAuthMethods}}
|
117
|
+
|
118
|
+
}
|
@@ -16,7 +16,7 @@
|
|
16
16
|
{{/springDocDocumentationProvider}}
|
17
17
|
{{^springDocDocumentationProvider}}
|
18
18
|
{{#swagger2AnnotationLibrary}}
|
19
|
-
<swagger-annotations.version>
|
19
|
+
<swagger-annotations.version>2.2.7</swagger-annotations.version>
|
20
20
|
{{/swagger2AnnotationLibrary}}
|
21
21
|
{{/springDocDocumentationProvider}}
|
22
22
|
</properties>
|
@@ -47,18 +47,18 @@
|
|
47
47
|
<build>
|
48
48
|
<sourceDirectory>src/main/java</sourceDirectory>
|
49
49
|
<plugins>
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
50
|
+
<plugin>
|
51
|
+
<groupId>org.apache.maven.plugins</groupId>
|
52
|
+
<artifactId>maven-source-plugin</artifactId>
|
53
|
+
<executions>
|
54
|
+
<execution>
|
55
|
+
<id>attach-sources</id>
|
56
|
+
<goals>
|
57
|
+
<goal>jar</goal>
|
58
|
+
</goals>
|
59
|
+
</execution>
|
60
|
+
</executions>
|
61
|
+
</plugin>
|
62
62
|
</plugins>
|
63
63
|
</build>
|
64
64
|
|
@@ -107,10 +107,10 @@
|
|
107
107
|
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
108
108
|
</dependency>
|
109
109
|
<dependency>
|
110
|
-
<groupId>org.springframework.
|
111
|
-
<artifactId>spring-
|
110
|
+
<groupId>org.springframework.security</groupId>
|
111
|
+
<artifactId>spring-security-oauth2-client</artifactId>
|
112
112
|
{{^parentOverridden}}
|
113
|
-
<version>
|
113
|
+
<version>6.1.1</version>
|
114
114
|
{{/parentOverridden}}
|
115
115
|
</dependency>
|
116
116
|
{{#withXml}}
|
@@ -23,7 +23,7 @@
|
|
23
23
|
<swagger-annotations.version>1.6.6</swagger-annotations.version>
|
24
24
|
{{/swagger1AnnotationLibrary}}
|
25
25
|
{{#swagger2AnnotationLibrary}}
|
26
|
-
<swagger-annotations.version>
|
26
|
+
<swagger-annotations.version>2.2.7</swagger-annotations.version>
|
27
27
|
{{/swagger2AnnotationLibrary}}
|
28
28
|
{{/springDocDocumentationProvider}}
|
29
29
|
{{/springFoxDocumentationProvider}}
|
@@ -46,18 +46,18 @@
|
|
46
46
|
<build>
|
47
47
|
<sourceDirectory>src/main/java</sourceDirectory>
|
48
48
|
<plugins>
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
49
|
+
<plugin>
|
50
|
+
<groupId>org.apache.maven.plugins</groupId>
|
51
|
+
<artifactId>maven-source-plugin</artifactId>
|
52
|
+
<executions>
|
53
|
+
<execution>
|
54
|
+
<id>attach-sources</id>
|
55
|
+
<goals>
|
56
|
+
<goal>jar</goal>
|
57
|
+
</goals>
|
58
|
+
</execution>
|
59
|
+
</executions>
|
60
|
+
</plugin>
|
61
61
|
</plugins>
|
62
62
|
</build>
|
63
63
|
|
@@ -123,10 +123,10 @@
|
|
123
123
|
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
124
124
|
</dependency>
|
125
125
|
<dependency>
|
126
|
-
<groupId>org.springframework.
|
127
|
-
<artifactId>spring-
|
126
|
+
<groupId>org.springframework.security</groupId>
|
127
|
+
<artifactId>spring-security-oauth2-client</artifactId>
|
128
128
|
{{^parentOverridden}}
|
129
|
-
<version>
|
129
|
+
<version>5.7.8</version>
|
130
130
|
{{/parentOverridden}}
|
131
131
|
</dependency>
|
132
132
|
{{#withXml}}
|
@@ -18,9 +18,9 @@
|
|
18
18
|
"java.time.OffsetDateTime": "java.time.Instant",
|
19
19
|
"java.util.Date": "java.time.LocalDate"
|
20
20
|
},
|
21
|
-
"
|
22
|
-
"
|
23
|
-
"
|
21
|
+
"inlineSchemaOptions": {
|
22
|
+
"ARRAY_ITEM_SUFFIX": "",
|
23
|
+
"MAP_ITEM_SUFFIX": "",
|
24
24
|
"SKIP_SCHEMA_REUSE": "true"
|
25
25
|
}
|
26
26
|
}
|
@@ -1,5 +1,6 @@
|
|
1
1
|
{{! attach sources }}
|
2
|
-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
2
|
+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
3
|
+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
3
4
|
<modelVersion>4.0.0</modelVersion>
|
4
5
|
<groupId>{{groupId}}</groupId>
|
5
6
|
<artifactId>{{artifactId}}</artifactId>
|