Skip to content

Commit 0d457cf

Browse files
stainless-botstainless-app[bot]
authored andcommitted
feat(api): make redirect_uri optional (#165)
1 parent 2b5414a commit 0d457cf

3 files changed

Lines changed: 29 additions & 34 deletions

File tree

finch-java-core/src/main/kotlin/com/tryfinch/api/models/AccessTokenCreateParams.kt

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,29 @@ import java.util.Optional
1717
class AccessTokenCreateParams
1818
constructor(
1919
private val code: String,
20-
private val redirectUri: String,
2120
private val clientId: String?,
2221
private val clientSecret: String?,
22+
private val redirectUri: String?,
2323
private val additionalQueryParams: Map<String, List<String>>,
2424
private val additionalHeaders: Map<String, List<String>>,
2525
private val additionalBodyProperties: Map<String, JsonValue>,
2626
) {
2727

2828
fun code(): String = code
2929

30-
fun redirectUri(): String = redirectUri
31-
3230
fun clientId(): Optional<String> = Optional.ofNullable(clientId)
3331

3432
fun clientSecret(): Optional<String> = Optional.ofNullable(clientSecret)
3533

34+
fun redirectUri(): Optional<String> = Optional.ofNullable(redirectUri)
35+
3636
@JvmSynthetic
3737
internal fun getBody(): AccessTokenCreateBody {
3838
return AccessTokenCreateBody(
3939
code,
40-
redirectUri,
4140
clientId,
4241
clientSecret,
42+
redirectUri,
4343
additionalBodyProperties,
4444
)
4545
}
@@ -53,22 +53,22 @@ constructor(
5353
class AccessTokenCreateBody
5454
internal constructor(
5555
private val code: String?,
56-
private val redirectUri: String?,
5756
private val clientId: String?,
5857
private val clientSecret: String?,
58+
private val redirectUri: String?,
5959
private val additionalProperties: Map<String, JsonValue>,
6060
) {
6161

6262
private var hashCode: Int = 0
6363

6464
@JsonProperty("code") fun code(): String? = code
6565

66-
@JsonProperty("redirect_uri") fun redirectUri(): String? = redirectUri
67-
6866
@JsonProperty("client_id") fun clientId(): String? = clientId
6967

7068
@JsonProperty("client_secret") fun clientSecret(): String? = clientSecret
7169

70+
@JsonProperty("redirect_uri") fun redirectUri(): String? = redirectUri
71+
7272
@JsonAnyGetter
7373
@ExcludeMissing
7474
fun _additionalProperties(): Map<String, JsonValue> = additionalProperties
@@ -82,9 +82,9 @@ constructor(
8282

8383
return other is AccessTokenCreateBody &&
8484
this.code == other.code &&
85-
this.redirectUri == other.redirectUri &&
8685
this.clientId == other.clientId &&
8786
this.clientSecret == other.clientSecret &&
87+
this.redirectUri == other.redirectUri &&
8888
this.additionalProperties == other.additionalProperties
8989
}
9090

@@ -93,17 +93,17 @@ constructor(
9393
hashCode =
9494
Objects.hash(
9595
code,
96-
redirectUri,
9796
clientId,
9897
clientSecret,
98+
redirectUri,
9999
additionalProperties,
100100
)
101101
}
102102
return hashCode
103103
}
104104

105105
override fun toString() =
106-
"AccessTokenCreateBody{code=$code, redirectUri=$redirectUri, clientId=$clientId, clientSecret=$clientSecret, additionalProperties=$additionalProperties}"
106+
"AccessTokenCreateBody{code=$code, clientId=$clientId, clientSecret=$clientSecret, redirectUri=$redirectUri, additionalProperties=$additionalProperties}"
107107

108108
companion object {
109109

@@ -113,31 +113,31 @@ constructor(
113113
class Builder {
114114

115115
private var code: String? = null
116-
private var redirectUri: String? = null
117116
private var clientId: String? = null
118117
private var clientSecret: String? = null
118+
private var redirectUri: String? = null
119119
private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf()
120120

121121
@JvmSynthetic
122122
internal fun from(accessTokenCreateBody: AccessTokenCreateBody) = apply {
123123
this.code = accessTokenCreateBody.code
124-
this.redirectUri = accessTokenCreateBody.redirectUri
125124
this.clientId = accessTokenCreateBody.clientId
126125
this.clientSecret = accessTokenCreateBody.clientSecret
126+
this.redirectUri = accessTokenCreateBody.redirectUri
127127
additionalProperties(accessTokenCreateBody.additionalProperties)
128128
}
129129

130130
@JsonProperty("code") fun code(code: String) = apply { this.code = code }
131131

132-
@JsonProperty("redirect_uri")
133-
fun redirectUri(redirectUri: String) = apply { this.redirectUri = redirectUri }
134-
135132
@JsonProperty("client_id")
136133
fun clientId(clientId: String) = apply { this.clientId = clientId }
137134

138135
@JsonProperty("client_secret")
139136
fun clientSecret(clientSecret: String) = apply { this.clientSecret = clientSecret }
140137

138+
@JsonProperty("redirect_uri")
139+
fun redirectUri(redirectUri: String) = apply { this.redirectUri = redirectUri }
140+
141141
fun additionalProperties(additionalProperties: Map<String, JsonValue>) = apply {
142142
this.additionalProperties.clear()
143143
this.additionalProperties.putAll(additionalProperties)
@@ -155,9 +155,9 @@ constructor(
155155
fun build(): AccessTokenCreateBody =
156156
AccessTokenCreateBody(
157157
checkNotNull(code) { "`code` is required but was not set" },
158-
checkNotNull(redirectUri) { "`redirectUri` is required but was not set" },
159158
clientId,
160159
clientSecret,
160+
redirectUri,
161161
additionalProperties.toUnmodifiable(),
162162
)
163163
}
@@ -176,9 +176,9 @@ constructor(
176176

177177
return other is AccessTokenCreateParams &&
178178
this.code == other.code &&
179-
this.redirectUri == other.redirectUri &&
180179
this.clientId == other.clientId &&
181180
this.clientSecret == other.clientSecret &&
181+
this.redirectUri == other.redirectUri &&
182182
this.additionalQueryParams == other.additionalQueryParams &&
183183
this.additionalHeaders == other.additionalHeaders &&
184184
this.additionalBodyProperties == other.additionalBodyProperties
@@ -187,17 +187,17 @@ constructor(
187187
override fun hashCode(): Int {
188188
return Objects.hash(
189189
code,
190-
redirectUri,
191190
clientId,
192191
clientSecret,
192+
redirectUri,
193193
additionalQueryParams,
194194
additionalHeaders,
195195
additionalBodyProperties,
196196
)
197197
}
198198

199199
override fun toString() =
200-
"AccessTokenCreateParams{code=$code, redirectUri=$redirectUri, clientId=$clientId, clientSecret=$clientSecret, additionalQueryParams=$additionalQueryParams, additionalHeaders=$additionalHeaders, additionalBodyProperties=$additionalBodyProperties}"
200+
"AccessTokenCreateParams{code=$code, clientId=$clientId, clientSecret=$clientSecret, redirectUri=$redirectUri, additionalQueryParams=$additionalQueryParams, additionalHeaders=$additionalHeaders, additionalBodyProperties=$additionalBodyProperties}"
201201

202202
fun toBuilder() = Builder().from(this)
203203

@@ -210,32 +210,32 @@ constructor(
210210
class Builder {
211211

212212
private var code: String? = null
213-
private var redirectUri: String? = null
214213
private var clientId: String? = null
215214
private var clientSecret: String? = null
215+
private var redirectUri: String? = null
216216
private var additionalQueryParams: MutableMap<String, MutableList<String>> = mutableMapOf()
217217
private var additionalHeaders: MutableMap<String, MutableList<String>> = mutableMapOf()
218218
private var additionalBodyProperties: MutableMap<String, JsonValue> = mutableMapOf()
219219

220220
@JvmSynthetic
221221
internal fun from(accessTokenCreateParams: AccessTokenCreateParams) = apply {
222222
this.code = accessTokenCreateParams.code
223-
this.redirectUri = accessTokenCreateParams.redirectUri
224223
this.clientId = accessTokenCreateParams.clientId
225224
this.clientSecret = accessTokenCreateParams.clientSecret
225+
this.redirectUri = accessTokenCreateParams.redirectUri
226226
additionalQueryParams(accessTokenCreateParams.additionalQueryParams)
227227
additionalHeaders(accessTokenCreateParams.additionalHeaders)
228228
additionalBodyProperties(accessTokenCreateParams.additionalBodyProperties)
229229
}
230230

231231
fun code(code: String) = apply { this.code = code }
232232

233-
fun redirectUri(redirectUri: String) = apply { this.redirectUri = redirectUri }
234-
235233
fun clientId(clientId: String) = apply { this.clientId = clientId }
236234

237235
fun clientSecret(clientSecret: String) = apply { this.clientSecret = clientSecret }
238236

237+
fun redirectUri(redirectUri: String) = apply { this.redirectUri = redirectUri }
238+
239239
fun additionalQueryParams(additionalQueryParams: Map<String, List<String>>) = apply {
240240
this.additionalQueryParams.clear()
241241
putAllQueryParams(additionalQueryParams)
@@ -293,9 +293,9 @@ constructor(
293293
fun build(): AccessTokenCreateParams =
294294
AccessTokenCreateParams(
295295
checkNotNull(code) { "`code` is required but was not set" },
296-
checkNotNull(redirectUri) { "`redirectUri` is required but was not set" },
297296
clientId,
298297
clientSecret,
298+
redirectUri,
299299
additionalQueryParams.mapValues { it.value.toUnmodifiable() }.toUnmodifiable(),
300300
additionalHeaders.mapValues { it.value.toUnmodifiable() }.toUnmodifiable(),
301301
additionalBodyProperties.toUnmodifiable(),

finch-java-core/src/test/kotlin/com/tryfinch/api/models/AccessTokenCreateParamsTest.kt

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ class AccessTokenCreateParamsTest {
1212
fun createAccessTokenCreateParams() {
1313
AccessTokenCreateParams.builder()
1414
.code("<your_authorization_code>")
15-
.redirectUri("https://example.com")
1615
.clientId("<your_client_id>")
1716
.clientSecret("<your_client_secret>")
17+
.redirectUri("https://example.com")
1818
.build()
1919
}
2020

@@ -23,28 +23,23 @@ class AccessTokenCreateParamsTest {
2323
val params =
2424
AccessTokenCreateParams.builder()
2525
.code("<your_authorization_code>")
26-
.redirectUri("https://example.com")
2726
.clientId("<your_client_id>")
2827
.clientSecret("<your_client_secret>")
28+
.redirectUri("https://example.com")
2929
.build()
3030
val body = params.getBody()
3131
assertThat(body).isNotNull
3232
assertThat(body.code()).isEqualTo("<your_authorization_code>")
33-
assertThat(body.redirectUri()).isEqualTo("https://example.com")
3433
assertThat(body.clientId()).isEqualTo("<your_client_id>")
3534
assertThat(body.clientSecret()).isEqualTo("<your_client_secret>")
35+
assertThat(body.redirectUri()).isEqualTo("https://example.com")
3636
}
3737

3838
@Test
3939
fun getBodyWithoutOptionalFields() {
40-
val params =
41-
AccessTokenCreateParams.builder()
42-
.code("<your_authorization_code>")
43-
.redirectUri("https://example.com")
44-
.build()
40+
val params = AccessTokenCreateParams.builder().code("<your_authorization_code>").build()
4541
val body = params.getBody()
4642
assertThat(body).isNotNull
4743
assertThat(body.code()).isEqualTo("<your_authorization_code>")
48-
assertThat(body.redirectUri()).isEqualTo("https://example.com")
4944
}
5045
}

finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/AccessTokenServiceTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ class AccessTokenServiceTest {
2525
accessTokenService.create(
2626
AccessTokenCreateParams.builder()
2727
.code("<your_authorization_code>")
28-
.redirectUri("https://example.com")
2928
.clientId("<your_client_id>")
3029
.clientSecret("<your_client_secret>")
30+
.redirectUri("https://example.com")
3131
.build()
3232
)
3333
println(createAccessTokenResponse)

0 commit comments

Comments
 (0)