From 8a7cdea5b7e757582f722b5274e10965824f8bc4 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 21 Mar 2025 05:29:19 +0000 Subject: [PATCH] docs: refine comments on multipart params chore(internal): make multipart assertions more robust chore(internal): remove unnecessary `assertNotNull` calls --- .../openlayer/api/core/http/HttpRequestBodies.kt | 13 ++++++------- .../InferencePipelineUpdateParamsTest.kt | 4 ---- .../inferencepipelines/data/DataStreamParamsTest.kt | 3 --- .../inferencepipelines/rows/RowUpdateParamsTest.kt | 3 --- .../api/models/projects/ProjectCreateParamsTest.kt | 3 --- .../projects/commits/CommitCreateParamsTest.kt | 3 --- .../InferencePipelineCreateParamsTest.kt | 3 --- 7 files changed, 6 insertions(+), 26 deletions(-) diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/core/http/HttpRequestBodies.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/core/http/HttpRequestBodies.kt index 6166963c..39005535 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/core/http/HttpRequestBodies.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/core/http/HttpRequestBodies.kt @@ -9,7 +9,6 @@ import com.fasterxml.jackson.databind.json.JsonMapper import com.fasterxml.jackson.databind.node.JsonNodeType import com.openlayer.api.core.MultipartField import com.openlayer.api.errors.OpenlayerInvalidDataException -import java.io.ByteArrayInputStream import java.io.InputStream import java.io.OutputStream import kotlin.jvm.optionals.getOrNull @@ -74,12 +73,12 @@ internal fun multipartFormData( when (node.nodeType) { JsonNodeType.MISSING, JsonNodeType.NULL -> emptySequence() - JsonNodeType.BINARY -> sequenceOf(name to ByteArrayInputStream(node.binaryValue())) - JsonNodeType.STRING -> sequenceOf(name to node.textValue().toInputStream()) + JsonNodeType.BINARY -> sequenceOf(name to node.binaryValue().inputStream()) + JsonNodeType.STRING -> sequenceOf(name to node.textValue().inputStream()) JsonNodeType.BOOLEAN -> - sequenceOf(name to node.booleanValue().toString().toInputStream()) + sequenceOf(name to node.booleanValue().toString().inputStream()) JsonNodeType.NUMBER -> - sequenceOf(name to node.numberValue().toString().toInputStream()) + sequenceOf(name to node.numberValue().toString().inputStream()) JsonNodeType.ARRAY -> sequenceOf( name to @@ -104,7 +103,7 @@ internal fun multipartFormData( } } .joinToString(",") - .toInputStream() + .inputStream() ) JsonNodeType.OBJECT -> node.fields().asSequence().flatMap { (key, value) -> @@ -117,7 +116,7 @@ internal fun multipartFormData( ) } - private fun String.toInputStream(): InputStream = ByteArrayInputStream(toByteArray()) + private fun String.inputStream(): InputStream = toByteArray().inputStream() override fun writeTo(outputStream: OutputStream) = entity.writeTo(outputStream) diff --git a/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/inferencepipelines/InferencePipelineUpdateParamsTest.kt b/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/inferencepipelines/InferencePipelineUpdateParamsTest.kt index b06b9fa1..f02bcc14 100644 --- a/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/inferencepipelines/InferencePipelineUpdateParamsTest.kt +++ b/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/inferencepipelines/InferencePipelineUpdateParamsTest.kt @@ -2,7 +2,6 @@ package com.openlayer.api.models.inferencepipelines -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -42,7 +41,6 @@ internal class InferencePipelineUpdateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.description()).contains("This pipeline is used for production.") assertThat(body.name()).contains("production") assertThat(body.referenceDatasetUri()).contains("referenceDatasetUri") @@ -56,7 +54,5 @@ internal class InferencePipelineUpdateParamsTest { .build() val body = params._body() - - assertNotNull(body) } } diff --git a/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/inferencepipelines/data/DataStreamParamsTest.kt b/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/inferencepipelines/data/DataStreamParamsTest.kt index e262bd4e..4cfa2546 100644 --- a/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/inferencepipelines/data/DataStreamParamsTest.kt +++ b/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/inferencepipelines/data/DataStreamParamsTest.kt @@ -3,7 +3,6 @@ package com.openlayer.api.models.inferencepipelines.data import com.openlayer.api.core.JsonValue -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -109,7 +108,6 @@ internal class DataStreamParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.config()) .isEqualTo( DataStreamParams.Config.ofLlmData( @@ -167,7 +165,6 @@ internal class DataStreamParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.config()) .isEqualTo( DataStreamParams.Config.ofLlmData( diff --git a/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/inferencepipelines/rows/RowUpdateParamsTest.kt b/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/inferencepipelines/rows/RowUpdateParamsTest.kt index 73cabb67..7048734d 100644 --- a/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/inferencepipelines/rows/RowUpdateParamsTest.kt +++ b/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/inferencepipelines/rows/RowUpdateParamsTest.kt @@ -4,7 +4,6 @@ package com.openlayer.api.models.inferencepipelines.rows import com.openlayer.api.core.JsonValue import com.openlayer.api.core.http.QueryParams -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -98,7 +97,6 @@ internal class RowUpdateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body._row()).isEqualTo(JsonValue.from(mapOf())) assertThat(body.config()) .contains( @@ -122,7 +120,6 @@ internal class RowUpdateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body._row()).isEqualTo(JsonValue.from(mapOf())) } } diff --git a/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/projects/ProjectCreateParamsTest.kt b/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/projects/ProjectCreateParamsTest.kt index a6dd32da..e9c15aa9 100644 --- a/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/projects/ProjectCreateParamsTest.kt +++ b/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/projects/ProjectCreateParamsTest.kt @@ -3,7 +3,6 @@ package com.openlayer.api.models.projects import java.time.OffsetDateTime -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -97,7 +96,6 @@ internal class ProjectCreateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.id()).isEqualTo("3fa85f64-5717-4562-b3fc-2c963f66afa6") assertThat(body.creatorId()).contains("589ece63-49a2-41b4-98e1-10547761d4b0") assertThat(body.dateCreated()).isEqualTo(OffsetDateTime.parse("2024-03-22T11:31:01.185Z")) @@ -167,7 +165,6 @@ internal class ProjectCreateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.id()).isEqualTo("3fa85f64-5717-4562-b3fc-2c963f66afa6") assertThat(body.creatorId()).contains("589ece63-49a2-41b4-98e1-10547761d4b0") assertThat(body.dateCreated()).isEqualTo(OffsetDateTime.parse("2024-03-22T11:31:01.185Z")) diff --git a/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/projects/commits/CommitCreateParamsTest.kt b/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/projects/commits/CommitCreateParamsTest.kt index e9648b98..465adccc 100644 --- a/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/projects/commits/CommitCreateParamsTest.kt +++ b/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/projects/commits/CommitCreateParamsTest.kt @@ -3,7 +3,6 @@ package com.openlayer.api.models.projects.commits import java.time.OffsetDateTime -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -138,7 +137,6 @@ internal class CommitCreateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.id()).isEqualTo("3fa85f64-5717-4562-b3fc-2c963f66afa6") assertThat(body.commit()) .isEqualTo( @@ -215,7 +213,6 @@ internal class CommitCreateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.id()).isEqualTo("3fa85f64-5717-4562-b3fc-2c963f66afa6") assertThat(body.commit()) .isEqualTo( diff --git a/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/projects/inferencepipelines/InferencePipelineCreateParamsTest.kt b/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/projects/inferencepipelines/InferencePipelineCreateParamsTest.kt index 60fb7650..22054f17 100644 --- a/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/projects/inferencepipelines/InferencePipelineCreateParamsTest.kt +++ b/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/projects/inferencepipelines/InferencePipelineCreateParamsTest.kt @@ -4,7 +4,6 @@ package com.openlayer.api.models.projects.inferencepipelines import java.time.LocalDate import java.time.OffsetDateTime -import kotlin.test.assertNotNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -235,7 +234,6 @@ internal class InferencePipelineCreateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.id()).isEqualTo("3fa85f64-5717-4562-b3fc-2c963f66afa6") assertThat(body.dateCreated()).isEqualTo(OffsetDateTime.parse("2024-03-22T11:31:01.185Z")) assertThat(body.dateLastEvaluated()) @@ -362,7 +360,6 @@ internal class InferencePipelineCreateParamsTest { val body = params._body() - assertNotNull(body) assertThat(body.id()).isEqualTo("3fa85f64-5717-4562-b3fc-2c963f66afa6") assertThat(body.dateCreated()).isEqualTo(OffsetDateTime.parse("2024-03-22T11:31:01.185Z")) assertThat(body.dateLastEvaluated())