Skip to content

Commit 93b2777

Browse files
feat(api): make client id, client secret optional again
1 parent 3503998 commit 93b2777

6 files changed

Lines changed: 87 additions & 104 deletions

File tree

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 45
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/finch%2Ffinch-edbdcdf654a3ab8c23745e1d115fc8b54908eb913571d70f1145a0b6a45cc811.yml
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/finch%2Ffinch-bb50c0ae41ff5036adf72344d33057941f6de67c5fae811eba2e758bfa4ffd31.yml
33
openapi_spec_hash: 1b21e4bfc46daeef1613e410e5aa8f28
4-
config_hash: 5146b12344dae76238940989dac1e8a0
4+
config_hash: 6d3585c0032e08d723d077d660fc8448

README.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -596,9 +596,7 @@ import com.tryfinch.api.models.AccessTokenCreateParams;
596596
import com.tryfinch.api.models.HrisDirectoryListParams;
597597

598598
HrisDirectoryListParams params = AccessTokenCreateParams.builder()
599-
.clientSecret("client_secret")
600-
.code("code")
601-
.clientId(JsonMissing.of())
599+
.code(JsonMissing.of())
602600
.build();
603601
```
604602

@@ -640,19 +638,19 @@ To access a property's raw JSON value, which may be undocumented, call its `_` p
640638
import com.tryfinch.api.core.JsonField;
641639
import java.util.Optional;
642640

643-
JsonField<String> clientId = client.accessTokens().create(params)._clientId();
641+
JsonField<String> code = client.accessTokens().create(params)._code();
644642

645-
if (clientId.isMissing()) {
643+
if (code.isMissing()) {
646644
// The property is absent from the JSON response
647-
} else if (clientId.isNull()) {
645+
} else if (code.isNull()) {
648646
// The property was set to literal null
649647
} else {
650648
// Check if value was provided as a string
651649
// Other methods include `asNumber()`, `asBoolean()`, etc.
652-
Optional<String> jsonString = clientId.asString();
650+
Optional<String> jsonString = code.asString();
653651

654652
// Try to deserialize into a custom type
655-
MyClass myObject = clientId.asUnknown().orElseThrow().convert(MyClass.class);
653+
MyClass myObject = code.asUnknown().orElseThrow().convert(MyClass.class);
656654
}
657655
```
658656

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

Lines changed: 72 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,28 @@ private constructor(
2828
) : Params {
2929

3030
/**
31-
* The client ID for your application
31+
* The authorization code received from the authorization server
3232
*
3333
* @throws FinchInvalidDataException if the JSON field has an unexpected type or is unexpectedly
3434
* missing or null (e.g. if the server responded with an unexpected value).
3535
*/
36-
fun clientId(): String = body.clientId()
36+
fun code(): String = body.code()
3737

3838
/**
39-
* The client secret for your application
39+
* The client ID for your application
4040
*
41-
* @throws FinchInvalidDataException if the JSON field has an unexpected type or is unexpectedly
42-
* missing or null (e.g. if the server responded with an unexpected value).
41+
* @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the
42+
* server responded with an unexpected value).
4343
*/
44-
fun clientSecret(): String = body.clientSecret()
44+
fun clientId(): Optional<String> = body.clientId()
4545

4646
/**
47-
* The authorization code received from the authorization server
47+
* The client secret for your application
4848
*
49-
* @throws FinchInvalidDataException if the JSON field has an unexpected type or is unexpectedly
50-
* missing or null (e.g. if the server responded with an unexpected value).
49+
* @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the
50+
* server responded with an unexpected value).
5151
*/
52-
fun code(): String = body.code()
52+
fun clientSecret(): Optional<String> = body.clientSecret()
5353

5454
/**
5555
* The redirect URI used in the authorization request (optional)
@@ -59,6 +59,13 @@ private constructor(
5959
*/
6060
fun redirectUri(): Optional<String> = body.redirectUri()
6161

62+
/**
63+
* Returns the raw JSON value of [code].
64+
*
65+
* Unlike [code], this method doesn't throw if the JSON field has an unexpected type.
66+
*/
67+
fun _code(): JsonField<String> = body._code()
68+
6269
/**
6370
* Returns the raw JSON value of [clientId].
6471
*
@@ -73,13 +80,6 @@ private constructor(
7380
*/
7481
fun _clientSecret(): JsonField<String> = body._clientSecret()
7582

76-
/**
77-
* Returns the raw JSON value of [code].
78-
*
79-
* Unlike [code], this method doesn't throw if the JSON field has an unexpected type.
80-
*/
81-
fun _code(): JsonField<String> = body._code()
82-
8383
/**
8484
* Returns the raw JSON value of [redirectUri].
8585
*
@@ -104,8 +104,6 @@ private constructor(
104104
*
105105
* The following fields are required:
106106
* ```java
107-
* .clientId()
108-
* .clientSecret()
109107
* .code()
110108
* ```
111109
*/
@@ -131,13 +129,24 @@ private constructor(
131129
*
132130
* This is generally only useful if you are already constructing the body separately.
133131
* Otherwise, it's more convenient to use the top-level setters instead:
132+
* - [code]
134133
* - [clientId]
135134
* - [clientSecret]
136-
* - [code]
137135
* - [redirectUri]
138136
*/
139137
fun body(body: CreateAccessTokenRequest) = apply { this.body = body.toBuilder() }
140138

139+
/** The authorization code received from the authorization server */
140+
fun code(code: String) = apply { body.code(code) }
141+
142+
/**
143+
* Sets [Builder.code] to an arbitrary JSON value.
144+
*
145+
* You should usually call [Builder.code] with a well-typed [String] value instead. This
146+
* method is primarily for setting the field to an undocumented or not yet supported value.
147+
*/
148+
fun code(code: JsonField<String>) = apply { body.code(code) }
149+
141150
/** The client ID for your application */
142151
fun clientId(clientId: String) = apply { body.clientId(clientId) }
143152

@@ -163,17 +172,6 @@ private constructor(
163172
body.clientSecret(clientSecret)
164173
}
165174

166-
/** The authorization code received from the authorization server */
167-
fun code(code: String) = apply { body.code(code) }
168-
169-
/**
170-
* Sets [Builder.code] to an arbitrary JSON value.
171-
*
172-
* You should usually call [Builder.code] with a well-typed [String] value instead. This
173-
* method is primarily for setting the field to an undocumented or not yet supported value.
174-
*/
175-
fun code(code: JsonField<String>) = apply { body.code(code) }
176-
177175
/** The redirect URI used in the authorization request (optional) */
178176
fun redirectUri(redirectUri: String) = apply { body.redirectUri(redirectUri) }
179177

@@ -310,8 +308,6 @@ private constructor(
310308
*
311309
* The following fields are required:
312310
* ```java
313-
* .clientId()
314-
* .clientSecret()
315311
* .code()
316312
* ```
317313
*
@@ -333,50 +329,50 @@ private constructor(
333329

334330
class CreateAccessTokenRequest
335331
private constructor(
332+
private val code: JsonField<String>,
336333
private val clientId: JsonField<String>,
337334
private val clientSecret: JsonField<String>,
338-
private val code: JsonField<String>,
339335
private val redirectUri: JsonField<String>,
340336
private val additionalProperties: MutableMap<String, JsonValue>,
341337
) {
342338

343339
@JsonCreator
344340
private constructor(
341+
@JsonProperty("code") @ExcludeMissing code: JsonField<String> = JsonMissing.of(),
345342
@JsonProperty("client_id")
346343
@ExcludeMissing
347344
clientId: JsonField<String> = JsonMissing.of(),
348345
@JsonProperty("client_secret")
349346
@ExcludeMissing
350347
clientSecret: JsonField<String> = JsonMissing.of(),
351-
@JsonProperty("code") @ExcludeMissing code: JsonField<String> = JsonMissing.of(),
352348
@JsonProperty("redirect_uri")
353349
@ExcludeMissing
354350
redirectUri: JsonField<String> = JsonMissing.of(),
355-
) : this(clientId, clientSecret, code, redirectUri, mutableMapOf())
351+
) : this(code, clientId, clientSecret, redirectUri, mutableMapOf())
356352

357353
/**
358-
* The client ID for your application
354+
* The authorization code received from the authorization server
359355
*
360356
* @throws FinchInvalidDataException if the JSON field has an unexpected type or is
361357
* unexpectedly missing or null (e.g. if the server responded with an unexpected value).
362358
*/
363-
fun clientId(): String = clientId.getRequired("client_id")
359+
fun code(): String = code.getRequired("code")
364360

365361
/**
366-
* The client secret for your application
362+
* The client ID for your application
367363
*
368-
* @throws FinchInvalidDataException if the JSON field has an unexpected type or is
369-
* unexpectedly missing or null (e.g. if the server responded with an unexpected value).
364+
* @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the
365+
* server responded with an unexpected value).
370366
*/
371-
fun clientSecret(): String = clientSecret.getRequired("client_secret")
367+
fun clientId(): Optional<String> = clientId.getOptional("client_id")
372368

373369
/**
374-
* The authorization code received from the authorization server
370+
* The client secret for your application
375371
*
376-
* @throws FinchInvalidDataException if the JSON field has an unexpected type or is
377-
* unexpectedly missing or null (e.g. if the server responded with an unexpected value).
372+
* @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the
373+
* server responded with an unexpected value).
378374
*/
379-
fun code(): String = code.getRequired("code")
375+
fun clientSecret(): Optional<String> = clientSecret.getOptional("client_secret")
380376

381377
/**
382378
* The redirect URI used in the authorization request (optional)
@@ -386,6 +382,13 @@ private constructor(
386382
*/
387383
fun redirectUri(): Optional<String> = redirectUri.getOptional("redirect_uri")
388384

385+
/**
386+
* Returns the raw JSON value of [code].
387+
*
388+
* Unlike [code], this method doesn't throw if the JSON field has an unexpected type.
389+
*/
390+
@JsonProperty("code") @ExcludeMissing fun _code(): JsonField<String> = code
391+
389392
/**
390393
* Returns the raw JSON value of [clientId].
391394
*
@@ -403,13 +406,6 @@ private constructor(
403406
@ExcludeMissing
404407
fun _clientSecret(): JsonField<String> = clientSecret
405408

406-
/**
407-
* Returns the raw JSON value of [code].
408-
*
409-
* Unlike [code], this method doesn't throw if the JSON field has an unexpected type.
410-
*/
411-
@JsonProperty("code") @ExcludeMissing fun _code(): JsonField<String> = code
412-
413409
/**
414410
* Returns the raw JSON value of [redirectUri].
415411
*
@@ -438,8 +434,6 @@ private constructor(
438434
*
439435
* The following fields are required:
440436
* ```java
441-
* .clientId()
442-
* .clientSecret()
443437
* .code()
444438
* ```
445439
*/
@@ -449,21 +443,33 @@ private constructor(
449443
/** A builder for [CreateAccessTokenRequest]. */
450444
class Builder internal constructor() {
451445

452-
private var clientId: JsonField<String>? = null
453-
private var clientSecret: JsonField<String>? = null
454446
private var code: JsonField<String>? = null
447+
private var clientId: JsonField<String> = JsonMissing.of()
448+
private var clientSecret: JsonField<String> = JsonMissing.of()
455449
private var redirectUri: JsonField<String> = JsonMissing.of()
456450
private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf()
457451

458452
@JvmSynthetic
459453
internal fun from(createAccessTokenRequest: CreateAccessTokenRequest) = apply {
454+
code = createAccessTokenRequest.code
460455
clientId = createAccessTokenRequest.clientId
461456
clientSecret = createAccessTokenRequest.clientSecret
462-
code = createAccessTokenRequest.code
463457
redirectUri = createAccessTokenRequest.redirectUri
464458
additionalProperties = createAccessTokenRequest.additionalProperties.toMutableMap()
465459
}
466460

461+
/** The authorization code received from the authorization server */
462+
fun code(code: String) = code(JsonField.of(code))
463+
464+
/**
465+
* Sets [Builder.code] to an arbitrary JSON value.
466+
*
467+
* You should usually call [Builder.code] with a well-typed [String] value instead. This
468+
* method is primarily for setting the field to an undocumented or not yet supported
469+
* value.
470+
*/
471+
fun code(code: JsonField<String>) = apply { this.code = code }
472+
467473
/** The client ID for your application */
468474
fun clientId(clientId: String) = clientId(JsonField.of(clientId))
469475

@@ -490,18 +496,6 @@ private constructor(
490496
this.clientSecret = clientSecret
491497
}
492498

493-
/** The authorization code received from the authorization server */
494-
fun code(code: String) = code(JsonField.of(code))
495-
496-
/**
497-
* Sets [Builder.code] to an arbitrary JSON value.
498-
*
499-
* You should usually call [Builder.code] with a well-typed [String] value instead. This
500-
* method is primarily for setting the field to an undocumented or not yet supported
501-
* value.
502-
*/
503-
fun code(code: JsonField<String>) = apply { this.code = code }
504-
505499
/** The redirect URI used in the authorization request (optional) */
506500
fun redirectUri(redirectUri: String) = redirectUri(JsonField.of(redirectUri))
507501

@@ -542,18 +536,16 @@ private constructor(
542536
*
543537
* The following fields are required:
544538
* ```java
545-
* .clientId()
546-
* .clientSecret()
547539
* .code()
548540
* ```
549541
*
550542
* @throws IllegalStateException if any required field is unset.
551543
*/
552544
fun build(): CreateAccessTokenRequest =
553545
CreateAccessTokenRequest(
554-
checkRequired("clientId", clientId),
555-
checkRequired("clientSecret", clientSecret),
556546
checkRequired("code", code),
547+
clientId,
548+
clientSecret,
557549
redirectUri,
558550
additionalProperties.toMutableMap(),
559551
)
@@ -566,9 +558,9 @@ private constructor(
566558
return@apply
567559
}
568560

561+
code()
569562
clientId()
570563
clientSecret()
571-
code()
572564
redirectUri()
573565
validated = true
574566
}
@@ -589,9 +581,9 @@ private constructor(
589581
*/
590582
@JvmSynthetic
591583
internal fun validity(): Int =
592-
(if (clientId.asKnown().isPresent) 1 else 0) +
584+
(if (code.asKnown().isPresent) 1 else 0) +
585+
(if (clientId.asKnown().isPresent) 1 else 0) +
593586
(if (clientSecret.asKnown().isPresent) 1 else 0) +
594-
(if (code.asKnown().isPresent) 1 else 0) +
595587
(if (redirectUri.asKnown().isPresent) 1 else 0)
596588

597589
override fun equals(other: Any?): Boolean {
@@ -600,21 +592,21 @@ private constructor(
600592
}
601593

602594
return other is CreateAccessTokenRequest &&
595+
code == other.code &&
603596
clientId == other.clientId &&
604597
clientSecret == other.clientSecret &&
605-
code == other.code &&
606598
redirectUri == other.redirectUri &&
607599
additionalProperties == other.additionalProperties
608600
}
609601

610602
private val hashCode: Int by lazy {
611-
Objects.hash(clientId, clientSecret, code, redirectUri, additionalProperties)
603+
Objects.hash(code, clientId, clientSecret, redirectUri, additionalProperties)
612604
}
613605

614606
override fun hashCode(): Int = hashCode
615607

616608
override fun toString() =
617-
"CreateAccessTokenRequest{clientId=$clientId, clientSecret=$clientSecret, code=$code, redirectUri=$redirectUri, additionalProperties=$additionalProperties}"
609+
"CreateAccessTokenRequest{code=$code, clientId=$clientId, clientSecret=$clientSecret, redirectUri=$redirectUri, additionalProperties=$additionalProperties}"
618610
}
619611

620612
override fun equals(other: Any?): Boolean {

0 commit comments

Comments
 (0)