Skip to content

Commit fea391e

Browse files
feat(api): dpr type update
1 parent a439ece commit fea391e

9 files changed

Lines changed: 223 additions & 38 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: 47
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/imagekit-inc%2Fimagekit-13fc3d7cafdea492f62eef7c1d63424d6d9d8adbff74b9f6ca6fd3fc12a36840.yml
3-
openapi_spec_hash: a1fe6fa48207791657a1ea2d60a6dfcc
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/imagekit-inc%2Fimagekit-e5b5a158784fff63311ceef956e8d5ce9e87c6b557d23ab737270040eb39adcd.yml
3+
openapi_spec_hash: b0293985a8806f367319af573d1b418c
44
config_hash: 47cb702ee2cb52c58d803ae39ade9b44

image-kit-java-core/src/main/kotlin/com/imagekit/api/models/Transformation.kt

Lines changed: 190 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ private constructor(
6060
private val cropMode: JsonField<CropMode>,
6161
private val defaultImage: JsonField<String>,
6262
private val distort: JsonField<String>,
63-
private val dpr: JsonField<Double>,
63+
private val dpr: JsonField<Dpr>,
6464
private val duration: JsonField<Duration>,
6565
private val endOffset: JsonField<EndOffset>,
6666
private val flip: JsonField<Flip>,
@@ -147,7 +147,7 @@ private constructor(
147147
@ExcludeMissing
148148
defaultImage: JsonField<String> = JsonMissing.of(),
149149
@JsonProperty("distort") @ExcludeMissing distort: JsonField<String> = JsonMissing.of(),
150-
@JsonProperty("dpr") @ExcludeMissing dpr: JsonField<Double> = JsonMissing.of(),
150+
@JsonProperty("dpr") @ExcludeMissing dpr: JsonField<Dpr> = JsonMissing.of(),
151151
@JsonProperty("duration") @ExcludeMissing duration: JsonField<Duration> = JsonMissing.of(),
152152
@JsonProperty("endOffset")
153153
@ExcludeMissing
@@ -481,7 +481,7 @@ private constructor(
481481
* @throws ImageKitInvalidDataException if the JSON field has an unexpected type (e.g. if the
482482
* server responded with an unexpected value).
483483
*/
484-
fun dpr(): Optional<Double> = dpr.getOptional("dpr")
484+
fun dpr(): Optional<Dpr> = dpr.getOptional("dpr")
485485

486486
/**
487487
* Specifies the duration (in seconds) for trimming videos, e.g., `5` or `10.5`. Typically used
@@ -994,7 +994,7 @@ private constructor(
994994
*
995995
* Unlike [dpr], this method doesn't throw if the JSON field has an unexpected type.
996996
*/
997-
@JsonProperty("dpr") @ExcludeMissing fun _dpr(): JsonField<Double> = dpr
997+
@JsonProperty("dpr") @ExcludeMissing fun _dpr(): JsonField<Dpr> = dpr
998998

999999
/**
10001000
* Returns the raw JSON value of [duration].
@@ -1280,7 +1280,7 @@ private constructor(
12801280
private var cropMode: JsonField<CropMode> = JsonMissing.of()
12811281
private var defaultImage: JsonField<String> = JsonMissing.of()
12821282
private var distort: JsonField<String> = JsonMissing.of()
1283-
private var dpr: JsonField<Double> = JsonMissing.of()
1283+
private var dpr: JsonField<Dpr> = JsonMissing.of()
12841284
private var duration: JsonField<Duration> = JsonMissing.of()
12851285
private var endOffset: JsonField<EndOffset> = JsonMissing.of()
12861286
private var flip: JsonField<Flip> = JsonMissing.of()
@@ -1752,15 +1752,21 @@ private constructor(
17521752
* [Arithmetic expressions](https://imagekit.io/docs/arithmetic-expressions-in-transformations).
17531753
* - See [DPR](https://imagekit.io/docs/image-resize-and-crop#dpr---dpr).
17541754
*/
1755-
fun dpr(dpr: Double) = dpr(JsonField.of(dpr))
1755+
fun dpr(dpr: Dpr) = dpr(JsonField.of(dpr))
17561756

17571757
/**
17581758
* Sets [Builder.dpr] to an arbitrary JSON value.
17591759
*
1760-
* You should usually call [Builder.dpr] with a well-typed [Double] value instead. This
1761-
* method is primarily for setting the field to an undocumented or not yet supported value.
1760+
* You should usually call [Builder.dpr] with a well-typed [Dpr] value instead. This method
1761+
* is primarily for setting the field to an undocumented or not yet supported value.
17621762
*/
1763-
fun dpr(dpr: JsonField<Double>) = apply { this.dpr = dpr }
1763+
fun dpr(dpr: JsonField<Dpr>) = apply { this.dpr = dpr }
1764+
1765+
/** Alias for calling [dpr] with `Dpr.ofNumber(number)`. */
1766+
fun dpr(number: Double) = dpr(Dpr.ofNumber(number))
1767+
1768+
/** Alias for calling [dpr] with `Dpr.ofString(string)`. */
1769+
fun dpr(string: String) = dpr(Dpr.ofString(string))
17641770

17651771
/**
17661772
* Specifies the duration (in seconds) for trimming videos, e.g., `5` or `10.5`. Typically
@@ -2582,7 +2588,7 @@ private constructor(
25822588
cropMode().ifPresent { it.validate() }
25832589
defaultImage()
25842590
distort()
2585-
dpr()
2591+
dpr().ifPresent { it.validate() }
25862592
duration().ifPresent { it.validate() }
25872593
endOffset().ifPresent { it.validate() }
25882594
flip().ifPresent { it.validate() }
@@ -2654,7 +2660,7 @@ private constructor(
26542660
(cropMode.asKnown().getOrNull()?.validity() ?: 0) +
26552661
(if (defaultImage.asKnown().isPresent) 1 else 0) +
26562662
(if (distort.asKnown().isPresent) 1 else 0) +
2657-
(if (dpr.asKnown().isPresent) 1 else 0) +
2663+
(dpr.asKnown().getOrNull()?.validity() ?: 0) +
26582664
(duration.asKnown().getOrNull()?.validity() ?: 0) +
26592665
(endOffset.asKnown().getOrNull()?.validity() ?: 0) +
26602666
(flip.asKnown().getOrNull()?.validity() ?: 0) +
@@ -4235,6 +4241,179 @@ private constructor(
42354241
override fun toString() = value.toString()
42364242
}
42374243

4244+
/**
4245+
* Accepts values between 0.1 and 5, or `auto` for automatic device pixel ratio (DPR)
4246+
* calculation. Also accepts arithmetic expressions.
4247+
* - Learn about
4248+
* [Arithmetic expressions](https://imagekit.io/docs/arithmetic-expressions-in-transformations).
4249+
* - See [DPR](https://imagekit.io/docs/image-resize-and-crop#dpr---dpr).
4250+
*/
4251+
@JsonDeserialize(using = Dpr.Deserializer::class)
4252+
@JsonSerialize(using = Dpr.Serializer::class)
4253+
class Dpr
4254+
private constructor(
4255+
private val number: Double? = null,
4256+
private val string: String? = null,
4257+
private val _json: JsonValue? = null,
4258+
) {
4259+
4260+
fun number(): Optional<Double> = Optional.ofNullable(number)
4261+
4262+
fun string(): Optional<String> = Optional.ofNullable(string)
4263+
4264+
fun isNumber(): Boolean = number != null
4265+
4266+
fun isString(): Boolean = string != null
4267+
4268+
fun asNumber(): Double = number.getOrThrow("number")
4269+
4270+
fun asString(): String = string.getOrThrow("string")
4271+
4272+
fun _json(): Optional<JsonValue> = Optional.ofNullable(_json)
4273+
4274+
fun <T> accept(visitor: Visitor<T>): T =
4275+
when {
4276+
number != null -> visitor.visitNumber(number)
4277+
string != null -> visitor.visitString(string)
4278+
else -> visitor.unknown(_json)
4279+
}
4280+
4281+
private var validated: Boolean = false
4282+
4283+
fun validate(): Dpr = apply {
4284+
if (validated) {
4285+
return@apply
4286+
}
4287+
4288+
accept(
4289+
object : Visitor<Unit> {
4290+
override fun visitNumber(number: Double) {}
4291+
4292+
override fun visitString(string: String) {}
4293+
}
4294+
)
4295+
validated = true
4296+
}
4297+
4298+
fun isValid(): Boolean =
4299+
try {
4300+
validate()
4301+
true
4302+
} catch (e: ImageKitInvalidDataException) {
4303+
false
4304+
}
4305+
4306+
/**
4307+
* Returns a score indicating how many valid values are contained in this object
4308+
* recursively.
4309+
*
4310+
* Used for best match union deserialization.
4311+
*/
4312+
@JvmSynthetic
4313+
internal fun validity(): Int =
4314+
accept(
4315+
object : Visitor<Int> {
4316+
override fun visitNumber(number: Double) = 1
4317+
4318+
override fun visitString(string: String) = 1
4319+
4320+
override fun unknown(json: JsonValue?) = 0
4321+
}
4322+
)
4323+
4324+
override fun equals(other: Any?): Boolean {
4325+
if (this === other) {
4326+
return true
4327+
}
4328+
4329+
return other is Dpr && number == other.number && string == other.string
4330+
}
4331+
4332+
override fun hashCode(): Int = Objects.hash(number, string)
4333+
4334+
override fun toString(): String =
4335+
when {
4336+
number != null -> "Dpr{number=$number}"
4337+
string != null -> "Dpr{string=$string}"
4338+
_json != null -> "Dpr{_unknown=$_json}"
4339+
else -> throw IllegalStateException("Invalid Dpr")
4340+
}
4341+
4342+
companion object {
4343+
4344+
@JvmStatic fun ofNumber(number: Double) = Dpr(number = number)
4345+
4346+
@JvmStatic fun ofString(string: String) = Dpr(string = string)
4347+
}
4348+
4349+
/** An interface that defines how to map each variant of [Dpr] to a value of type [T]. */
4350+
interface Visitor<out T> {
4351+
4352+
fun visitNumber(number: Double): T
4353+
4354+
fun visitString(string: String): T
4355+
4356+
/**
4357+
* Maps an unknown variant of [Dpr] to a value of type [T].
4358+
*
4359+
* An instance of [Dpr] can contain an unknown variant if it was deserialized from data
4360+
* that doesn't match any known variant. For example, if the SDK is on an older version
4361+
* than the API, then the API may respond with new variants that the SDK is unaware of.
4362+
*
4363+
* @throws ImageKitInvalidDataException in the default implementation.
4364+
*/
4365+
fun unknown(json: JsonValue?): T {
4366+
throw ImageKitInvalidDataException("Unknown Dpr: $json")
4367+
}
4368+
}
4369+
4370+
internal class Deserializer : BaseDeserializer<Dpr>(Dpr::class) {
4371+
4372+
override fun ObjectCodec.deserialize(node: JsonNode): Dpr {
4373+
val json = JsonValue.fromJsonNode(node)
4374+
4375+
val bestMatches =
4376+
sequenceOf(
4377+
tryDeserialize(node, jacksonTypeRef<String>())?.let {
4378+
Dpr(string = it, _json = json)
4379+
},
4380+
tryDeserialize(node, jacksonTypeRef<Double>())?.let {
4381+
Dpr(number = it, _json = json)
4382+
},
4383+
)
4384+
.filterNotNull()
4385+
.allMaxBy { it.validity() }
4386+
.toList()
4387+
return when (bestMatches.size) {
4388+
// This can happen if what we're deserializing is completely incompatible with
4389+
// all the possible variants (e.g. deserializing from boolean).
4390+
0 -> Dpr(_json = json)
4391+
1 -> bestMatches.single()
4392+
// If there's more than one match with the highest validity, then use the first
4393+
// completely valid match, or simply the first match if none are completely
4394+
// valid.
4395+
else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first()
4396+
}
4397+
}
4398+
}
4399+
4400+
internal class Serializer : BaseSerializer<Dpr>(Dpr::class) {
4401+
4402+
override fun serialize(
4403+
value: Dpr,
4404+
generator: JsonGenerator,
4405+
provider: SerializerProvider,
4406+
) {
4407+
when {
4408+
value.number != null -> generator.writeObject(value.number)
4409+
value.string != null -> generator.writeObject(value.string)
4410+
value._json != null -> generator.writeObject(value._json)
4411+
else -> throw IllegalStateException("Invalid Dpr")
4412+
}
4413+
}
4414+
}
4415+
}
4416+
42384417
/**
42394418
* Specifies the duration (in seconds) for trimming videos, e.g., `5` or `10.5`. Typically used
42404419
* with startOffset to indicate the length from the start offset. Arithmetic expressions are

image-kit-java-core/src/main/kotlin/com/imagekit/api/models/beta/v2/files/FileUploadParams.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@ import kotlin.io.path.name
4242
* [Learn more](/docs/api-reference/upload-file/upload-file-v2#how-to-implement-secure-client-side-file-upload)
4343
* about how to implement secure client-side file upload.
4444
*
45-
* **File size limit** \ On the free plan, the maximum upload file sizes are 20MB for images, audio,
46-
* and raw files, and 100MB for videos. On the paid plan, these limits increase to 40MB for images,
47-
* audio, and raw files, and 2GB for videos. These limits can be further increased with higher-tier
48-
* plans.
45+
* **File size limit** \ On the free plan, the maximum upload file sizes are 25MB for images, audio,
46+
* and raw files, and 100MB for videos. On the Lite paid plan, these limits increase to 40MB for
47+
* images, audio, and raw files and 300MB for videos, whereas on the Pro paid plan, these limits
48+
* increase to 50MB for images, audio, and raw files and 2GB for videos. These limits can be further
49+
* increased with enterprise plans.
4950
*
5051
* **Version limit** \ A file can have a maximum of 100 versions.
5152
*

image-kit-java-core/src/main/kotlin/com/imagekit/api/models/files/FileUploadParams.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@ import kotlin.io.path.name
4343
* The [V2 API](/docs/api-reference/upload-file/upload-file-v2) enhances security by verifying the
4444
* entire payload using JWT.
4545
*
46-
* **File size limit** \ On the free plan, the maximum upload file sizes are 20MB for images, audio,
47-
* and raw files and 100MB for videos. On the paid plan, these limits increase to 40MB for images,
48-
* audio, and raw files and 2GB for videos. These limits can be further increased with higher-tier
49-
* plans.
46+
* **File size limit** \ On the free plan, the maximum upload file sizes are 25MB for images, audio,
47+
* and raw files and 100MB for videos. On the Lite paid plan, these limits increase to 40MB for
48+
* images, audio, and raw files and 300MB for videos, whereas on the Pro paid plan, these limits
49+
* increase to 50MB for images, audio, and raw files and 2GB for videos. These limits can be further
50+
* increased with enterprise plans.
5051
*
5152
* **Version limit** \ A file can have a maximum of 100 versions.
5253
*

image-kit-java-core/src/main/kotlin/com/imagekit/api/services/async/FileServiceAsync.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,11 @@ interface FileServiceAsync {
194194
* The [V2 API](/docs/api-reference/upload-file/upload-file-v2) enhances security by verifying
195195
* the entire payload using JWT.
196196
*
197-
* **File size limit** \ On the free plan, the maximum upload file sizes are 20MB for images,
198-
* audio, and raw files and 100MB for videos. On the paid plan, these limits increase to 40MB
199-
* for images, audio, and raw files and 2GB for videos. These limits can be further increased
200-
* with higher-tier plans.
197+
* **File size limit** \ On the free plan, the maximum upload file sizes are 25MB for images,
198+
* audio, and raw files and 100MB for videos. On the Lite paid plan, these limits increase to
199+
* 40MB for images, audio, and raw files and 300MB for videos, whereas on the Pro paid plan,
200+
* these limits increase to 50MB for images, audio, and raw files and 2GB for videos. These
201+
* limits can be further increased with enterprise plans.
201202
*
202203
* **Version limit** \ A file can have a maximum of 100 versions.
203204
*

image-kit-java-core/src/main/kotlin/com/imagekit/api/services/async/beta/v2/FileServiceAsync.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ interface FileServiceAsync {
3333
* [Learn more](/docs/api-reference/upload-file/upload-file-v2#how-to-implement-secure-client-side-file-upload)
3434
* about how to implement secure client-side file upload.
3535
*
36-
* **File size limit** \ On the free plan, the maximum upload file sizes are 20MB for images,
37-
* audio, and raw files, and 100MB for videos. On the paid plan, these limits increase to 40MB
38-
* for images, audio, and raw files, and 2GB for videos. These limits can be further increased
39-
* with higher-tier plans.
36+
* **File size limit** \ On the free plan, the maximum upload file sizes are 25MB for images,
37+
* audio, and raw files, and 100MB for videos. On the Lite paid plan, these limits increase to
38+
* 40MB for images, audio, and raw files and 300MB for videos, whereas on the Pro paid plan,
39+
* these limits increase to 50MB for images, audio, and raw files and 2GB for videos. These
40+
* limits can be further increased with enterprise plans.
4041
*
4142
* **Version limit** \ A file can have a maximum of 100 versions.
4243
*

image-kit-java-core/src/main/kotlin/com/imagekit/api/services/blocking/FileService.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,11 @@ interface FileService {
180180
* The [V2 API](/docs/api-reference/upload-file/upload-file-v2) enhances security by verifying
181181
* the entire payload using JWT.
182182
*
183-
* **File size limit** \ On the free plan, the maximum upload file sizes are 20MB for images,
184-
* audio, and raw files and 100MB for videos. On the paid plan, these limits increase to 40MB
185-
* for images, audio, and raw files and 2GB for videos. These limits can be further increased
186-
* with higher-tier plans.
183+
* **File size limit** \ On the free plan, the maximum upload file sizes are 25MB for images,
184+
* audio, and raw files and 100MB for videos. On the Lite paid plan, these limits increase to
185+
* 40MB for images, audio, and raw files and 300MB for videos, whereas on the Pro paid plan,
186+
* these limits increase to 50MB for images, audio, and raw files and 2GB for videos. These
187+
* limits can be further increased with enterprise plans.
187188
*
188189
* **Version limit** \ A file can have a maximum of 100 versions.
189190
*

image-kit-java-core/src/main/kotlin/com/imagekit/api/services/blocking/beta/v2/FileService.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ interface FileService {
3333
* [Learn more](/docs/api-reference/upload-file/upload-file-v2#how-to-implement-secure-client-side-file-upload)
3434
* about how to implement secure client-side file upload.
3535
*
36-
* **File size limit** \ On the free plan, the maximum upload file sizes are 20MB for images,
37-
* audio, and raw files, and 100MB for videos. On the paid plan, these limits increase to 40MB
38-
* for images, audio, and raw files, and 2GB for videos. These limits can be further increased
39-
* with higher-tier plans.
36+
* **File size limit** \ On the free plan, the maximum upload file sizes are 25MB for images,
37+
* audio, and raw files, and 100MB for videos. On the Lite paid plan, these limits increase to
38+
* 40MB for images, audio, and raw files and 300MB for videos, whereas on the Pro paid plan,
39+
* these limits increase to 50MB for images, audio, and raw files and 2GB for videos. These
40+
* limits can be further increased with enterprise plans.
4041
*
4142
* **Version limit** \ A file can have a maximum of 100 versions.
4243
*

image-kit-java-core/src/test/kotlin/com/imagekit/api/models/TransformationTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ internal class TransformationTest {
124124
assertThat(transformation.cropMode()).contains(Transformation.CropMode.PAD_RESIZE)
125125
assertThat(transformation.defaultImage()).contains("defaultImage")
126126
assertThat(transformation.distort()).contains("distort")
127-
assertThat(transformation.dpr()).contains(2.0)
127+
assertThat(transformation.dpr()).contains(Transformation.Dpr.ofNumber(2.0))
128128
assertThat(transformation.duration()).contains(Transformation.Duration.ofNumber(0.0))
129129
assertThat(transformation.endOffset()).contains(Transformation.EndOffset.ofNumber(0.0))
130130
assertThat(transformation.flip()).contains(Transformation.Flip.H)

0 commit comments

Comments
 (0)