Skip to content

Commit 0caeef8

Browse files
feat(api): indentation fix
1 parent 26eba98 commit 0caeef8

5 files changed

Lines changed: 513 additions & 20 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-f4cd00365ba96133e0675eae3d5d3c6ac13874789e2ce69a84310ab64a4f87dd.yml
3-
openapi_spec_hash: dce632cfbb5464a98c0f5d8eb9573d68
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/imagekit-inc%2Fimagekit-3234424a3a5871f31f5d6dcb8173593fc6c1db14802a0e71f14f3527ad16c871.yml
3+
openapi_spec_hash: 017a8ab68d905ed9e163022f68d8be78
44
config_hash: 17e408231b0b01676298010c7405f483

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

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ import com.imagekit.api.core.JsonMissing
1212
import com.imagekit.api.core.JsonValue
1313
import com.imagekit.api.core.checkRequired
1414
import com.imagekit.api.errors.ImageKitInvalidDataException
15+
import com.imagekit.api.models.files.File
1516
import java.time.OffsetDateTime
1617
import java.util.Collections
1718
import java.util.Objects
19+
import kotlin.jvm.optionals.getOrNull
1820

1921
/** Triggered when a file version is created. */
2022
class DamFileVersionCreateEvent
@@ -23,7 +25,7 @@ private constructor(
2325
private val id: JsonField<String>,
2426
private val type: JsonField<String>,
2527
private val createdAt: JsonField<OffsetDateTime>,
26-
private val data: JsonValue,
28+
private val data: JsonField<File>,
2729
private val additionalProperties: MutableMap<String, JsonValue>,
2830
) {
2931

@@ -34,7 +36,7 @@ private constructor(
3436
@JsonProperty("created_at")
3537
@ExcludeMissing
3638
createdAt: JsonField<OffsetDateTime> = JsonMissing.of(),
37-
@JsonProperty("data") @ExcludeMissing data: JsonValue = JsonMissing.of(),
39+
@JsonProperty("data") @ExcludeMissing data: JsonField<File> = JsonMissing.of(),
3840
) : this(id, type, createdAt, data, mutableMapOf())
3941

4042
fun toBaseWebhookEvent(): BaseWebhookEvent =
@@ -65,12 +67,12 @@ private constructor(
6567
fun createdAt(): OffsetDateTime = createdAt.getRequired("created_at")
6668

6769
/**
68-
* This arbitrary value can be deserialized into a custom type using the `convert` method:
69-
* ```java
70-
* MyClass myObject = damFileVersionCreateEvent.data().convert(MyClass.class);
71-
* ```
70+
* Object containing details of a file or file version.
71+
*
72+
* @throws ImageKitInvalidDataException if the JSON field has an unexpected type or is
73+
* unexpectedly missing or null (e.g. if the server responded with an unexpected value).
7274
*/
73-
@JsonProperty("data") @ExcludeMissing fun _data(): JsonValue = data
75+
fun data(): File = data.getRequired("data")
7476

7577
/**
7678
* Returns the raw JSON value of [id].
@@ -95,6 +97,13 @@ private constructor(
9597
@ExcludeMissing
9698
fun _createdAt(): JsonField<OffsetDateTime> = createdAt
9799

100+
/**
101+
* Returns the raw JSON value of [data].
102+
*
103+
* Unlike [data], this method doesn't throw if the JSON field has an unexpected type.
104+
*/
105+
@JsonProperty("data") @ExcludeMissing fun _data(): JsonField<File> = data
106+
98107
@JsonAnySetter
99108
private fun putAdditionalProperty(key: String, value: JsonValue) {
100109
additionalProperties.put(key, value)
@@ -129,7 +138,7 @@ private constructor(
129138
private var id: JsonField<String>? = null
130139
private var type: JsonField<String>? = null
131140
private var createdAt: JsonField<OffsetDateTime>? = null
132-
private var data: JsonValue? = null
141+
private var data: JsonField<File>? = null
133142
private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf()
134143

135144
@JvmSynthetic
@@ -175,7 +184,16 @@ private constructor(
175184
*/
176185
fun createdAt(createdAt: JsonField<OffsetDateTime>) = apply { this.createdAt = createdAt }
177186

178-
fun data(data: JsonValue) = apply { this.data = data }
187+
/** Object containing details of a file or file version. */
188+
fun data(data: File) = data(JsonField.of(data))
189+
190+
/**
191+
* Sets [Builder.data] to an arbitrary JSON value.
192+
*
193+
* You should usually call [Builder.data] with a well-typed [File] value instead. This
194+
* method is primarily for setting the field to an undocumented or not yet supported value.
195+
*/
196+
fun data(data: JsonField<File>) = apply { this.data = data }
179197

180198
fun additionalProperties(additionalProperties: Map<String, JsonValue>) = apply {
181199
this.additionalProperties.clear()
@@ -231,6 +249,7 @@ private constructor(
231249
id()
232250
type()
233251
createdAt()
252+
data().validate()
234253
validated = true
235254
}
236255

@@ -251,7 +270,8 @@ private constructor(
251270
internal fun validity(): Int =
252271
(if (id.asKnown().isPresent) 1 else 0) +
253272
(if (type.asKnown().isPresent) 1 else 0) +
254-
(if (createdAt.asKnown().isPresent) 1 else 0)
273+
(if (createdAt.asKnown().isPresent) 1 else 0) +
274+
(data.asKnown().getOrNull()?.validity() ?: 0)
255275

256276
override fun equals(other: Any?): Boolean {
257277
if (this === other) {

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

Lines changed: 199 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package com.imagekit.api.models.webhooks
55
import com.fasterxml.jackson.module.kotlin.jacksonTypeRef
66
import com.imagekit.api.core.JsonValue
77
import com.imagekit.api.core.jsonMapper
8+
import com.imagekit.api.models.files.File
89
import java.time.OffsetDateTime
910
import org.assertj.core.api.Assertions.assertThat
1011
import org.junit.jupiter.api.Test
@@ -18,15 +19,143 @@ internal class DamFileVersionCreateEventTest {
1819
.id("id")
1920
.type("file-version.created")
2021
.createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z"))
21-
.data(JsonValue.from(mapOf<String, Any>()))
22+
.data(
23+
File.builder()
24+
.addAiTag(
25+
File.AiTag.builder()
26+
.confidence(0.0)
27+
.name("name")
28+
.source("source")
29+
.build()
30+
)
31+
.audioCodec("audioCodec")
32+
.bitRate(0L)
33+
.createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z"))
34+
.customCoordinates("customCoordinates")
35+
.customMetadata(
36+
File.CustomMetadata.builder()
37+
.putAdditionalProperty("foo", JsonValue.from("bar"))
38+
.build()
39+
)
40+
.description("description")
41+
.duration(0L)
42+
.embeddedMetadata(
43+
File.EmbeddedMetadata.builder()
44+
.putAdditionalProperty("foo", JsonValue.from("bar"))
45+
.build()
46+
)
47+
.fileId("fileId")
48+
.filePath("filePath")
49+
.fileType("fileType")
50+
.hasAlpha(true)
51+
.height(0.0)
52+
.isPrivateFile(true)
53+
.isPublished(true)
54+
.mime("mime")
55+
.name("name")
56+
.selectedFieldsSchema(
57+
File.SelectedFieldsSchema.builder()
58+
.putAdditionalProperty(
59+
"foo",
60+
JsonValue.from(
61+
mapOf(
62+
"type" to "Text",
63+
"defaultValue" to "string",
64+
"isValueRequired" to true,
65+
"maxLength" to 0,
66+
"maxValue" to "string",
67+
"minLength" to 0,
68+
"minValue" to "string",
69+
"readOnly" to true,
70+
"selectOptions" to
71+
listOf("small", "medium", "large", 30, 40, true),
72+
"selectOptionsTruncated" to true,
73+
)
74+
),
75+
)
76+
.build()
77+
)
78+
.size(0.0)
79+
.addTag("string")
80+
.thumbnail("https://example.com")
81+
.type(File.Type.FILE)
82+
.updatedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z"))
83+
.url("https://example.com")
84+
.versionInfo(File.VersionInfo.builder().id("id").name("name").build())
85+
.videoCodec("videoCodec")
86+
.width(0.0)
87+
.build()
88+
)
2289
.build()
2390

2491
assertThat(damFileVersionCreateEvent.id()).isEqualTo("id")
2592
assertThat(damFileVersionCreateEvent.type()).isEqualTo("file-version.created")
2693
assertThat(damFileVersionCreateEvent.createdAt())
2794
.isEqualTo(OffsetDateTime.parse("2019-12-27T18:11:19.117Z"))
28-
assertThat(damFileVersionCreateEvent._data())
29-
.isEqualTo(JsonValue.from(mapOf<String, Any>()))
95+
assertThat(damFileVersionCreateEvent.data())
96+
.isEqualTo(
97+
File.builder()
98+
.addAiTag(
99+
File.AiTag.builder().confidence(0.0).name("name").source("source").build()
100+
)
101+
.audioCodec("audioCodec")
102+
.bitRate(0L)
103+
.createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z"))
104+
.customCoordinates("customCoordinates")
105+
.customMetadata(
106+
File.CustomMetadata.builder()
107+
.putAdditionalProperty("foo", JsonValue.from("bar"))
108+
.build()
109+
)
110+
.description("description")
111+
.duration(0L)
112+
.embeddedMetadata(
113+
File.EmbeddedMetadata.builder()
114+
.putAdditionalProperty("foo", JsonValue.from("bar"))
115+
.build()
116+
)
117+
.fileId("fileId")
118+
.filePath("filePath")
119+
.fileType("fileType")
120+
.hasAlpha(true)
121+
.height(0.0)
122+
.isPrivateFile(true)
123+
.isPublished(true)
124+
.mime("mime")
125+
.name("name")
126+
.selectedFieldsSchema(
127+
File.SelectedFieldsSchema.builder()
128+
.putAdditionalProperty(
129+
"foo",
130+
JsonValue.from(
131+
mapOf(
132+
"type" to "Text",
133+
"defaultValue" to "string",
134+
"isValueRequired" to true,
135+
"maxLength" to 0,
136+
"maxValue" to "string",
137+
"minLength" to 0,
138+
"minValue" to "string",
139+
"readOnly" to true,
140+
"selectOptions" to
141+
listOf("small", "medium", "large", 30, 40, true),
142+
"selectOptionsTruncated" to true,
143+
)
144+
),
145+
)
146+
.build()
147+
)
148+
.size(0.0)
149+
.addTag("string")
150+
.thumbnail("https://example.com")
151+
.type(File.Type.FILE)
152+
.updatedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z"))
153+
.url("https://example.com")
154+
.versionInfo(File.VersionInfo.builder().id("id").name("name").build())
155+
.videoCodec("videoCodec")
156+
.width(0.0)
157+
.build()
158+
)
30159
}
31160

32161
@Test
@@ -37,7 +166,73 @@ internal class DamFileVersionCreateEventTest {
37166
.id("id")
38167
.type("file-version.created")
39168
.createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z"))
40-
.data(JsonValue.from(mapOf<String, Any>()))
169+
.data(
170+
File.builder()
171+
.addAiTag(
172+
File.AiTag.builder()
173+
.confidence(0.0)
174+
.name("name")
175+
.source("source")
176+
.build()
177+
)
178+
.audioCodec("audioCodec")
179+
.bitRate(0L)
180+
.createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z"))
181+
.customCoordinates("customCoordinates")
182+
.customMetadata(
183+
File.CustomMetadata.builder()
184+
.putAdditionalProperty("foo", JsonValue.from("bar"))
185+
.build()
186+
)
187+
.description("description")
188+
.duration(0L)
189+
.embeddedMetadata(
190+
File.EmbeddedMetadata.builder()
191+
.putAdditionalProperty("foo", JsonValue.from("bar"))
192+
.build()
193+
)
194+
.fileId("fileId")
195+
.filePath("filePath")
196+
.fileType("fileType")
197+
.hasAlpha(true)
198+
.height(0.0)
199+
.isPrivateFile(true)
200+
.isPublished(true)
201+
.mime("mime")
202+
.name("name")
203+
.selectedFieldsSchema(
204+
File.SelectedFieldsSchema.builder()
205+
.putAdditionalProperty(
206+
"foo",
207+
JsonValue.from(
208+
mapOf(
209+
"type" to "Text",
210+
"defaultValue" to "string",
211+
"isValueRequired" to true,
212+
"maxLength" to 0,
213+
"maxValue" to "string",
214+
"minLength" to 0,
215+
"minValue" to "string",
216+
"readOnly" to true,
217+
"selectOptions" to
218+
listOf("small", "medium", "large", 30, 40, true),
219+
"selectOptionsTruncated" to true,
220+
)
221+
),
222+
)
223+
.build()
224+
)
225+
.size(0.0)
226+
.addTag("string")
227+
.thumbnail("https://example.com")
228+
.type(File.Type.FILE)
229+
.updatedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z"))
230+
.url("https://example.com")
231+
.versionInfo(File.VersionInfo.builder().id("id").name("name").build())
232+
.videoCodec("videoCodec")
233+
.width(0.0)
234+
.build()
235+
)
41236
.build()
42237

43238
val roundtrippedDamFileVersionCreateEvent =

0 commit comments

Comments
 (0)