|
| 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