Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api): update via SDK Studio #41

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
configured_endpoints: 13
configured_endpoints: 14

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
// File generated from our OpenAPI spec by Stainless.

@file:Suppress("OVERLOADS_INTERFACE") // See https://youtrack.jetbrains.com/issue/KT-36102

package com.openlayer.api.services.async

import com.openlayer.api.core.RequestOptions
import com.openlayer.api.models.CommitCreateParams
import com.openlayer.api.models.CommitCreateResponse
import com.openlayer.api.services.async.commits.TestResultServiceAsync
import java.util.concurrent.CompletableFuture

interface CommitServiceAsync {

fun testResults(): TestResultServiceAsync

/** Create a new commit (project version) in a project. */
@JvmOverloads
fun create(
params: CommitCreateParams,
requestOptions: RequestOptions = RequestOptions.none()
): CompletableFuture<CommitCreateResponse>
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,61 @@
package com.openlayer.api.services.async

import com.openlayer.api.core.ClientOptions
import com.openlayer.api.core.RequestOptions
import com.openlayer.api.core.handlers.errorHandler
import com.openlayer.api.core.handlers.jsonHandler
import com.openlayer.api.core.handlers.withErrorHandler
import com.openlayer.api.core.http.HttpMethod
import com.openlayer.api.core.http.HttpRequest
import com.openlayer.api.core.http.HttpResponse.Handler
import com.openlayer.api.core.json
import com.openlayer.api.errors.OpenlayerError
import com.openlayer.api.models.CommitCreateParams
import com.openlayer.api.models.CommitCreateResponse
import com.openlayer.api.services.async.commits.TestResultServiceAsync
import com.openlayer.api.services.async.commits.TestResultServiceAsyncImpl
import java.util.concurrent.CompletableFuture

class CommitServiceAsyncImpl
constructor(
private val clientOptions: ClientOptions,
) : CommitServiceAsync {

private val errorHandler: Handler<OpenlayerError> = errorHandler(clientOptions.jsonMapper)

private val testResults: TestResultServiceAsync by lazy {
TestResultServiceAsyncImpl(clientOptions)
}

override fun testResults(): TestResultServiceAsync = testResults

private val createHandler: Handler<CommitCreateResponse> =
jsonHandler<CommitCreateResponse>(clientOptions.jsonMapper).withErrorHandler(errorHandler)

/** Create a new commit (project version) in a project. */
override fun create(
params: CommitCreateParams,
requestOptions: RequestOptions
): CompletableFuture<CommitCreateResponse> {
val request =
HttpRequest.builder()
.method(HttpMethod.POST)
.addPathSegments("projects", params.getPathParam(0), "versions")
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
.body(json(clientOptions.jsonMapper, params.getBody()))
.build()
return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response
->
response
.use { createHandler.handle(it) }
.apply {
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
validate()
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
// File generated from our OpenAPI spec by Stainless.

@file:Suppress("OVERLOADS_INTERFACE") // See https://youtrack.jetbrains.com/issue/KT-36102

package com.openlayer.api.services.blocking

import com.openlayer.api.core.RequestOptions
import com.openlayer.api.models.CommitCreateParams
import com.openlayer.api.models.CommitCreateResponse
import com.openlayer.api.services.blocking.commits.TestResultService

interface CommitService {

fun testResults(): TestResultService

/** Create a new commit (project version) in a project. */
@JvmOverloads
fun create(
params: CommitCreateParams,
requestOptions: RequestOptions = RequestOptions.none()
): CommitCreateResponse
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
package com.openlayer.api.services.blocking

import com.openlayer.api.core.ClientOptions
import com.openlayer.api.core.RequestOptions
import com.openlayer.api.core.handlers.errorHandler
import com.openlayer.api.core.handlers.jsonHandler
import com.openlayer.api.core.handlers.withErrorHandler
import com.openlayer.api.core.http.HttpMethod
import com.openlayer.api.core.http.HttpRequest
import com.openlayer.api.core.http.HttpResponse.Handler
import com.openlayer.api.core.json
import com.openlayer.api.errors.OpenlayerError
import com.openlayer.api.models.CommitCreateParams
import com.openlayer.api.models.CommitCreateResponse
import com.openlayer.api.services.blocking.commits.TestResultService
import com.openlayer.api.services.blocking.commits.TestResultServiceImpl

Expand All @@ -11,7 +22,38 @@ constructor(
private val clientOptions: ClientOptions,
) : CommitService {

private val errorHandler: Handler<OpenlayerError> = errorHandler(clientOptions.jsonMapper)

private val testResults: TestResultService by lazy { TestResultServiceImpl(clientOptions) }

override fun testResults(): TestResultService = testResults

private val createHandler: Handler<CommitCreateResponse> =
jsonHandler<CommitCreateResponse>(clientOptions.jsonMapper).withErrorHandler(errorHandler)

/** Create a new commit (project version) in a project. */
override fun create(
params: CommitCreateParams,
requestOptions: RequestOptions
): CommitCreateResponse {
val request =
HttpRequest.builder()
.method(HttpMethod.POST)
.addPathSegments("projects", params.getPathParam(0), "versions")
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
.body(json(clientOptions.jsonMapper, params.getBody()))
.build()
return clientOptions.httpClient.execute(request, requestOptions).let { response ->
response
.use { createHandler.handle(it) }
.apply {
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
validate()
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
// File generated from our OpenAPI spec by Stainless.

package com.openlayer.api.models

import com.openlayer.api.models.*
import java.time.OffsetDateTime
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test

class CommitCreateParamsTest {

@Test
fun createCommitCreateParams() {
CommitCreateParams.builder()
.projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
.commit(
CommitCreateParams.Commit.builder()
.id("3fa85f64-5717-4562-b3fc-2c963f66afa6")
.authorId("589ece63-49a2-41b4-98e1-10547761d4b0")
.fileSize(123L)
.message("Updated the prompt.")
.mlModelId("3fa85f64-5717-4562-b3fc-2c963f66afa6")
.storageUri("s3://...")
.trainingDatasetId("3fa85f64-5717-4562-b3fc-2c963f66afa6")
.validationDatasetId("3fa85f64-5717-4562-b3fc-2c963f66afa6")
.dateCreated(OffsetDateTime.parse("2024-03-22T11:31:01.185Z"))
.gitCommitRef("main")
.gitCommitSha(123L)
.gitCommitUrl("gitCommitUrl")
.build()
)
.storageUri("s3://...")
.archived(true)
.deploymentStatus("Deployed")
.build()
}

@Test
fun getBody() {
val params =
CommitCreateParams.builder()
.projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
.commit(
CommitCreateParams.Commit.builder()
.id("3fa85f64-5717-4562-b3fc-2c963f66afa6")
.authorId("589ece63-49a2-41b4-98e1-10547761d4b0")
.fileSize(123L)
.message("Updated the prompt.")
.mlModelId("3fa85f64-5717-4562-b3fc-2c963f66afa6")
.storageUri("s3://...")
.trainingDatasetId("3fa85f64-5717-4562-b3fc-2c963f66afa6")
.validationDatasetId("3fa85f64-5717-4562-b3fc-2c963f66afa6")
.dateCreated(OffsetDateTime.parse("2024-03-22T11:31:01.185Z"))
.gitCommitRef("main")
.gitCommitSha(123L)
.gitCommitUrl("gitCommitUrl")
.build()
)
.storageUri("s3://...")
.archived(true)
.deploymentStatus("Deployed")
.build()
val body = params.getBody()
assertThat(body).isNotNull
assertThat(body.commit())
.isEqualTo(
CommitCreateParams.Commit.builder()
.id("3fa85f64-5717-4562-b3fc-2c963f66afa6")
.authorId("589ece63-49a2-41b4-98e1-10547761d4b0")
.fileSize(123L)
.message("Updated the prompt.")
.mlModelId("3fa85f64-5717-4562-b3fc-2c963f66afa6")
.storageUri("s3://...")
.trainingDatasetId("3fa85f64-5717-4562-b3fc-2c963f66afa6")
.validationDatasetId("3fa85f64-5717-4562-b3fc-2c963f66afa6")
.dateCreated(OffsetDateTime.parse("2024-03-22T11:31:01.185Z"))
.gitCommitRef("main")
.gitCommitSha(123L)
.gitCommitUrl("gitCommitUrl")
.build()
)
assertThat(body.storageUri()).isEqualTo("s3://...")
assertThat(body.archived()).isEqualTo(true)
assertThat(body.deploymentStatus()).isEqualTo("Deployed")
}

@Test
fun getBodyWithoutOptionalFields() {
val params =
CommitCreateParams.builder()
.projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
.commit(
CommitCreateParams.Commit.builder()
.id("3fa85f64-5717-4562-b3fc-2c963f66afa6")
.authorId("589ece63-49a2-41b4-98e1-10547761d4b0")
.message("Updated the prompt.")
.storageUri("s3://...")
.build()
)
.storageUri("s3://...")
.build()
val body = params.getBody()
assertThat(body).isNotNull
assertThat(body.commit())
.isEqualTo(
CommitCreateParams.Commit.builder()
.id("3fa85f64-5717-4562-b3fc-2c963f66afa6")
.authorId("589ece63-49a2-41b4-98e1-10547761d4b0")
.message("Updated the prompt.")
.storageUri("s3://...")
.build()
)
assertThat(body.storageUri()).isEqualTo("s3://...")
}

@Test
fun getPathParam() {
val params =
CommitCreateParams.builder()
.projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
.commit(
CommitCreateParams.Commit.builder()
.id("3fa85f64-5717-4562-b3fc-2c963f66afa6")
.authorId("589ece63-49a2-41b4-98e1-10547761d4b0")
.message("Updated the prompt.")
.storageUri("s3://...")
.build()
)
.storageUri("s3://...")
.build()
assertThat(params).isNotNull
// path param "projectId"
assertThat(params.getPathParam(0)).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
// out-of-bound path param
assertThat(params.getPathParam(1)).isEqualTo("")
}
}
Loading