Skip to content

Commit 09b41e1

Browse files
feat(api): add OAuthErrorCode type
1 parent 39eb772 commit 09b41e1

2 files changed

Lines changed: 134 additions & 2 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: 151
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-dd99495ad509338e6de862802839360dfe394d5cd6d6ba6d13fec8fca92328b8.yml
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-a6eca1bd01e0c434af356fe5275c206057216a4e626d1051d294c27016cd6d05.yml
33
openapi_spec_hash: 68abda9122013a9ae3f084cfdbe8e8c1
4-
config_hash: 1b7e3ce9f1cb351b5077f6c9d8dccd8f
4+
config_hash: 5b9de93ccb5052ffa603a3c2d93b621c
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
// File generated from our OpenAPI spec by Stainless.
2+
3+
package com.openai.models
4+
5+
import com.fasterxml.jackson.annotation.JsonCreator
6+
import com.openai.core.Enum
7+
import com.openai.core.JsonField
8+
import com.openai.errors.OpenAIInvalidDataException
9+
10+
class OAuthErrorCode @JsonCreator private constructor(private val value: JsonField<String>) : Enum {
11+
12+
/**
13+
* Returns this class instance's raw value.
14+
*
15+
* This is usually only useful if this instance was deserialized from data that doesn't match
16+
* any known member, and you want to know that value. For example, if the SDK is on an older
17+
* version than the API, then the API may respond with new members that the SDK is unaware of.
18+
*/
19+
@com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField<String> = value
20+
21+
companion object {
22+
23+
@JvmField val INVALID_GRANT = of("invalid_grant")
24+
25+
@JvmField val INVALID_SUBJECT_TOKEN = of("invalid_subject_token")
26+
27+
@JvmStatic fun of(value: String) = OAuthErrorCode(JsonField.of(value))
28+
}
29+
30+
/** An enum containing [OAuthErrorCode]'s known values. */
31+
enum class Known {
32+
INVALID_GRANT,
33+
INVALID_SUBJECT_TOKEN,
34+
}
35+
36+
/**
37+
* An enum containing [OAuthErrorCode]'s known values, as well as an [_UNKNOWN] member.
38+
*
39+
* An instance of [OAuthErrorCode] can contain an unknown value in a couple of cases:
40+
* - It was deserialized from data that doesn't match any known member. For example, if the SDK
41+
* is on an older version than the API, then the API may respond with new members that the SDK
42+
* is unaware of.
43+
* - It was constructed with an arbitrary value using the [of] method.
44+
*/
45+
enum class Value {
46+
INVALID_GRANT,
47+
INVALID_SUBJECT_TOKEN,
48+
/**
49+
* An enum member indicating that [OAuthErrorCode] was instantiated with an unknown value.
50+
*/
51+
_UNKNOWN,
52+
}
53+
54+
/**
55+
* Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] if
56+
* the class was instantiated with an unknown value.
57+
*
58+
* Use the [known] method instead if you're certain the value is always known or if you want to
59+
* throw for the unknown case.
60+
*/
61+
fun value(): Value =
62+
when (this) {
63+
INVALID_GRANT -> Value.INVALID_GRANT
64+
INVALID_SUBJECT_TOKEN -> Value.INVALID_SUBJECT_TOKEN
65+
else -> Value._UNKNOWN
66+
}
67+
68+
/**
69+
* Returns an enum member corresponding to this class instance's value.
70+
*
71+
* Use the [value] method instead if you're uncertain the value is always known and don't want
72+
* to throw for the unknown case.
73+
*
74+
* @throws OpenAIInvalidDataException if this class instance's value is a not a known member.
75+
*/
76+
fun known(): Known =
77+
when (this) {
78+
INVALID_GRANT -> Known.INVALID_GRANT
79+
INVALID_SUBJECT_TOKEN -> Known.INVALID_SUBJECT_TOKEN
80+
else -> throw OpenAIInvalidDataException("Unknown OAuthErrorCode: $value")
81+
}
82+
83+
/**
84+
* Returns this class instance's primitive wire representation.
85+
*
86+
* This differs from the [toString] method because that method is primarily for debugging and
87+
* generally doesn't throw.
88+
*
89+
* @throws OpenAIInvalidDataException if this class instance's value does not have the expected
90+
* primitive type.
91+
*/
92+
fun asString(): String =
93+
_value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") }
94+
95+
private var validated: Boolean = false
96+
97+
fun validate(): OAuthErrorCode = apply {
98+
if (validated) {
99+
return@apply
100+
}
101+
102+
known()
103+
validated = true
104+
}
105+
106+
fun isValid(): Boolean =
107+
try {
108+
validate()
109+
true
110+
} catch (e: OpenAIInvalidDataException) {
111+
false
112+
}
113+
114+
/**
115+
* Returns a score indicating how many valid values are contained in this object recursively.
116+
*
117+
* Used for best match union deserialization.
118+
*/
119+
@JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1
120+
121+
override fun equals(other: Any?): Boolean {
122+
if (this === other) {
123+
return true
124+
}
125+
126+
return other is OAuthErrorCode && value == other.value
127+
}
128+
129+
override fun hashCode() = value.hashCode()
130+
131+
override fun toString() = value.toString()
132+
}

0 commit comments

Comments
 (0)