Skip to content

Commit

Permalink
feat(api): update via SDK Studio (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored and stainless-bot committed Sep 23, 2024
1 parent 9c103d7 commit af97a69
Show file tree
Hide file tree
Showing 13 changed files with 134 additions and 129 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ To create a new project, first use the `ProjectCreateParams` builder to specify
then pass that to the `create` method of the `project` service.

```java
import com.braintrustdata.api.models.Project;
import com.braintrustdata.api.models.ProjectCreateParams;
import com.braintrustdata.api.models.ProjectModel;

ProjectCreateParams params = ProjectCreateParams.builder()
.name("foobar")
.build();
Project project = client.project().create(params);
ProjectModel projectModel = client.project().create(params);
```

### Example: listing resources
Expand All @@ -88,10 +88,10 @@ You can retrieve the first page by:

```java
import com.braintrustdata.api.models.Page;
import com.braintrustdata.api.models.Project;
import com.braintrustdata.api.models.ProjectModel;

ProjectListPage page = client.project().list();
for (Project project : page.objects()) {
for (ProjectModel project : page.objects()) {
System.out.println(project);
}
```
Expand Down Expand Up @@ -127,7 +127,7 @@ ProjectCreateParams params = ProjectCreateParams.builder()
When receiving a response, the Braintrust Java SDK will deserialize it into instances of the typed model classes. In rare cases, the API may return a response property that doesn't match the expected Java type. If you directly access the mistaken property, the SDK will throw an unchecked `BraintrustInvalidDataException` at runtime. If you would prefer to check in advance that that response is completely well-typed, call `.validate()` on the returned model.

```java
Project project = client.project().create().validate();
ProjectModel projectModel = client.project().create().validate();
```

### Response properties as JSON
Expand Down Expand Up @@ -177,7 +177,7 @@ which automatically handles fetching more pages for you:
```java
// As an Iterable:
ProjectListPage page = client.project().list(params);
for (Project project : page.autoPager()) {
for (ProjectModel project : page.autoPager()) {
System.out.println(project);
};

Expand Down Expand Up @@ -205,7 +205,7 @@ A page of results has a `data()` method to fetch the list of objects, as well as
```java
ProjectListPage page = client.project().list(params);
while (page != null) {
for (Project project : page.objects()) {
for (ProjectModel project : page.objects()) {
System.out.println(project);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private constructor(

fun response(): Response = response

fun objects(): List<Project> = response().objects()
fun objects(): List<ProjectModel> = response().objects()

override fun equals(other: Any?): Boolean {
if (this === other) {
Expand Down Expand Up @@ -98,16 +98,16 @@ private constructor(
@NoAutoDetect
class Response
constructor(
private val objects: JsonField<List<Project>>,
private val objects: JsonField<List<ProjectModel>>,
private val additionalProperties: Map<String, JsonValue>,
) {

private var validated: Boolean = false

fun objects(): List<Project> = objects.getNullable("objects") ?: listOf()
fun objects(): List<ProjectModel> = objects.getNullable("objects") ?: listOf()

@JsonProperty("objects")
fun _objects(): Optional<JsonField<List<Project>>> = Optional.ofNullable(objects)
fun _objects(): Optional<JsonField<List<ProjectModel>>> = Optional.ofNullable(objects)

@JsonAnyGetter
@ExcludeMissing
Expand Down Expand Up @@ -146,7 +146,7 @@ private constructor(

class Builder {

private var objects: JsonField<List<Project>> = JsonMissing.of()
private var objects: JsonField<List<ProjectModel>> = JsonMissing.of()
private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf()

@JvmSynthetic
Expand All @@ -155,10 +155,10 @@ private constructor(
this.additionalProperties.putAll(page.additionalProperties)
}

fun objects(objects: List<Project>) = objects(JsonField.of(objects))
fun objects(objects: List<ProjectModel>) = objects(JsonField.of(objects))

@JsonProperty("objects")
fun objects(objects: JsonField<List<Project>>) = apply { this.objects = objects }
fun objects(objects: JsonField<List<ProjectModel>>) = apply { this.objects = objects }

@JsonAnySetter
fun putAdditionalProperty(key: String, value: JsonValue) = apply {
Expand All @@ -172,9 +172,9 @@ private constructor(
class AutoPager
constructor(
private val firstPage: ProjectListPage,
) : Iterable<Project> {
) : Iterable<ProjectModel> {

override fun iterator(): Iterator<Project> = iterator {
override fun iterator(): Iterator<ProjectModel> = iterator {
var page = firstPage
var index = 0
while (true) {
Expand All @@ -186,7 +186,7 @@ private constructor(
}
}

fun stream(): Stream<Project> {
fun stream(): Stream<ProjectModel> {
return StreamSupport.stream(spliterator(), false)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ private constructor(

fun response(): Response = response

fun objects(): List<Project> = response().objects()
fun objects(): List<ProjectModel> = response().objects()

override fun equals(other: Any?): Boolean {
if (this === other) {
Expand Down Expand Up @@ -101,16 +101,16 @@ private constructor(
@NoAutoDetect
class Response
constructor(
private val objects: JsonField<List<Project>>,
private val objects: JsonField<List<ProjectModel>>,
private val additionalProperties: Map<String, JsonValue>,
) {

private var validated: Boolean = false

fun objects(): List<Project> = objects.getNullable("objects") ?: listOf()
fun objects(): List<ProjectModel> = objects.getNullable("objects") ?: listOf()

@JsonProperty("objects")
fun _objects(): Optional<JsonField<List<Project>>> = Optional.ofNullable(objects)
fun _objects(): Optional<JsonField<List<ProjectModel>>> = Optional.ofNullable(objects)

@JsonAnyGetter
@ExcludeMissing
Expand Down Expand Up @@ -149,7 +149,7 @@ private constructor(

class Builder {

private var objects: JsonField<List<Project>> = JsonMissing.of()
private var objects: JsonField<List<ProjectModel>> = JsonMissing.of()
private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf()

@JvmSynthetic
Expand All @@ -158,10 +158,10 @@ private constructor(
this.additionalProperties.putAll(page.additionalProperties)
}

fun objects(objects: List<Project>) = objects(JsonField.of(objects))
fun objects(objects: List<ProjectModel>) = objects(JsonField.of(objects))

@JsonProperty("objects")
fun objects(objects: JsonField<List<Project>>) = apply { this.objects = objects }
fun objects(objects: JsonField<List<ProjectModel>>) = apply { this.objects = objects }

@JsonAnySetter
fun putAdditionalProperty(key: String, value: JsonValue) = apply {
Expand All @@ -177,9 +177,9 @@ private constructor(
private val firstPage: ProjectListPageAsync,
) {

fun forEach(action: Predicate<Project>, executor: Executor): CompletableFuture<Void> {
fun forEach(action: Predicate<ProjectModel>, executor: Executor): CompletableFuture<Void> {
fun CompletableFuture<Optional<ProjectListPageAsync>>.forEach(
action: (Project) -> Boolean,
action: (ProjectModel) -> Boolean,
executor: Executor
): CompletableFuture<Void> =
thenComposeAsync(
Expand All @@ -195,8 +195,8 @@ private constructor(
.forEach(action::test, executor)
}

fun toList(executor: Executor): CompletableFuture<List<Project>> {
val values = mutableListOf<Project>()
fun toList(executor: Executor): CompletableFuture<List<ProjectModel>> {
val values = mutableListOf<ProjectModel>()
return forEach(values::add, executor).thenApply { values }
}
}
Expand Down
32 changes: 16 additions & 16 deletions .../com/braintrustdata/api/models/Project.kt → ...braintrustdata/api/models/ProjectModel.kt
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import java.time.OffsetDateTime
import java.util.Objects
import java.util.Optional

@JsonDeserialize(builder = Project.Builder::class)
@JsonDeserialize(builder = ProjectModel.Builder::class)
@NoAutoDetect
class Project
class ProjectModel
private constructor(
private val id: JsonField<String>,
private val orgId: JsonField<String>,
Expand Down Expand Up @@ -79,7 +79,7 @@ private constructor(
@ExcludeMissing
fun _additionalProperties(): Map<String, JsonValue> = additionalProperties

fun validate(): Project = apply {
fun validate(): ProjectModel = apply {
if (!validated) {
id()
orgId()
Expand All @@ -99,7 +99,7 @@ private constructor(
return true
}

return other is Project &&
return other is ProjectModel &&
this.id == other.id &&
this.orgId == other.orgId &&
this.name == other.name &&
Expand Down Expand Up @@ -128,7 +128,7 @@ private constructor(
}

override fun toString() =
"Project{id=$id, orgId=$orgId, name=$name, created=$created, deletedAt=$deletedAt, userId=$userId, settings=$settings, additionalProperties=$additionalProperties}"
"ProjectModel{id=$id, orgId=$orgId, name=$name, created=$created, deletedAt=$deletedAt, userId=$userId, settings=$settings, additionalProperties=$additionalProperties}"

companion object {

Expand All @@ -147,15 +147,15 @@ private constructor(
private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf()

@JvmSynthetic
internal fun from(project: Project) = apply {
this.id = project.id
this.orgId = project.orgId
this.name = project.name
this.created = project.created
this.deletedAt = project.deletedAt
this.userId = project.userId
this.settings = project.settings
additionalProperties(project.additionalProperties)
internal fun from(projectModel: ProjectModel) = apply {
this.id = projectModel.id
this.orgId = projectModel.orgId
this.name = projectModel.name
this.created = projectModel.created
this.deletedAt = projectModel.deletedAt
this.userId = projectModel.userId
this.settings = projectModel.settings
additionalProperties(projectModel.additionalProperties)
}

/** Unique identifier for the project */
Expand Down Expand Up @@ -224,8 +224,8 @@ private constructor(
this.additionalProperties.putAll(additionalProperties)
}

fun build(): Project =
Project(
fun build(): ProjectModel =
ProjectModel(
id,
orgId,
name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
package com.braintrustdata.api.services.async

import com.braintrustdata.api.core.RequestOptions
import com.braintrustdata.api.models.Project
import com.braintrustdata.api.models.ProjectCreateParams
import com.braintrustdata.api.models.ProjectDeleteParams
import com.braintrustdata.api.models.ProjectListPageAsync
import com.braintrustdata.api.models.ProjectListParams
import com.braintrustdata.api.models.ProjectModel
import com.braintrustdata.api.models.ProjectRetrieveParams
import com.braintrustdata.api.models.ProjectUpdateParams
import com.braintrustdata.api.services.async.project.LogServiceAsync
Expand All @@ -27,14 +27,14 @@ interface ProjectServiceAsync {
fun create(
params: ProjectCreateParams,
requestOptions: RequestOptions = RequestOptions.none()
): CompletableFuture<Project>
): CompletableFuture<ProjectModel>

/** Get a project object by its id */
@JvmOverloads
fun retrieve(
params: ProjectRetrieveParams,
requestOptions: RequestOptions = RequestOptions.none()
): CompletableFuture<Project>
): CompletableFuture<ProjectModel>

/**
* Partially update a project object. Specify the fields to update in the payload. Any
Expand All @@ -45,7 +45,7 @@ interface ProjectServiceAsync {
fun update(
params: ProjectUpdateParams,
requestOptions: RequestOptions = RequestOptions.none()
): CompletableFuture<Project>
): CompletableFuture<ProjectModel>

/**
* List out all projects. The projects are sorted by creation date, with the most
Expand All @@ -62,5 +62,5 @@ interface ProjectServiceAsync {
fun delete(
params: ProjectDeleteParams,
requestOptions: RequestOptions = RequestOptions.none()
): CompletableFuture<Project>
): CompletableFuture<ProjectModel>
}
Loading

0 comments on commit af97a69

Please sign in to comment.