Skip to content

Commit

Permalink
[OPIK-309] Expose API contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagohora committed Oct 31, 2024
1 parent 3df4eb4 commit 18cc509
Show file tree
Hide file tree
Showing 5 changed files with 360 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.comet.opik.api;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonView;
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Builder;

@Builder(toBuilder = true)
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
public record CreatePromptVersion(@JsonView( {
PromptVersion.View.Detail.class}) @NotBlank String name,
@JsonView({PromptVersion.View.Detail.class}) @NotNull PromptVersion version){
}
36 changes: 24 additions & 12 deletions apps/opik-backend/src/main/java/com/comet/opik/api/Prompt.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,41 @@
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
public record Prompt(
@JsonView( {
Prompt.View.Public.class, Prompt.View.Write.class}) UUID id,
@JsonView({Prompt.View.Public.class, Prompt.View.Write.class}) @NotBlank String name,
Prompt.View.Public.class, Prompt.View.Write.class, Prompt.View.Detail.class}) UUID id,
@JsonView({Prompt.View.Public.class, Prompt.View.Write.class, Prompt.View.Detail.class}) @NotBlank String name,
@JsonView({Prompt.View.Public.class,
Prompt.View.Write.class}) @Pattern(regexp = NULL_OR_NOT_BLANK, message = "must not be blank") String description,
@JsonView({Prompt.View.Public.class}) @Schema(accessMode = Schema.AccessMode.READ_ONLY) Instant createdAt,
@JsonView({Prompt.View.Public.class}) @Schema(accessMode = Schema.AccessMode.READ_ONLY) String createdBy,
@JsonView({Prompt.View.Public.class}) @Schema(accessMode = Schema.AccessMode.READ_ONLY) Instant lastUpdatedAt,
@JsonView({Prompt.View.Public.class}) @Schema(accessMode = Schema.AccessMode.READ_ONLY) String lastUpdatedBy){
Prompt.View.Write.class,
Prompt.View.Detail.class}) @Pattern(regexp = NULL_OR_NOT_BLANK, message = "must not be blank") String description,
@JsonView({Prompt.View.Public.class,
Prompt.View.Detail.class}) @Schema(accessMode = Schema.AccessMode.READ_ONLY) Instant createdAt,
@JsonView({Prompt.View.Public.class,
Prompt.View.Detail.class}) @Schema(accessMode = Schema.AccessMode.READ_ONLY) String createdBy,
@JsonView({Prompt.View.Public.class,
Prompt.View.Detail.class}) @Schema(accessMode = Schema.AccessMode.READ_ONLY) Instant lastUpdatedAt,
@JsonView({Prompt.View.Public.class,
Prompt.View.Detail.class}) @Schema(accessMode = Schema.AccessMode.READ_ONLY) String lastUpdatedBy,
@JsonView({Prompt.View.Public.class,
Prompt.View.Detail.class}) @Schema(accessMode = Schema.AccessMode.READ_ONLY) long versionCount,
@JsonView({
Prompt.View.Detail.class}) @Schema(accessMode = Schema.AccessMode.READ_ONLY) PromptVersion latestVersion){

public static class View {
public static class Write {
}

public static class Public {
}
}

public static class Detail {
}
}
@Builder
public record PromptPage(
@JsonView( {
Project.View.Public.class}) int page,
@JsonView({Project.View.Public.class}) int size,
@JsonView({Project.View.Public.class}) long total,
@JsonView({Project.View.Public.class}) List<Prompt> content)
Prompt.View.Public.class}) int page,
@JsonView({Prompt.View.Public.class}) int size,
@JsonView({Prompt.View.Public.class}) long total,
@JsonView({Prompt.View.Public.class}) List<Prompt> content)
implements
Page<Prompt>{

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.comet.opik.api;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonView;
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.Builder;

import java.time.Instant;
import java.util.List;
import java.util.Set;
import java.util.UUID;

@Builder(toBuilder = true)
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
public record PromptVersion(
@JsonView( {
PromptVersion.View.Public.class,
PromptVersion.View.Detail.class}) @Schema(description = "version unique identifier, generated if absent") UUID id,
@JsonView({PromptVersion.View.Public.class,
PromptVersion.View.Detail.class}) @Schema(description = "version short unique identifier, generated if absent") String commit,
@JsonView({PromptVersion.View.Detail.class}) @NotNull String template,
@JsonView({
PromptVersion.View.Detail.class}) @Schema(accessMode = Schema.AccessMode.READ_ONLY) Set<String> variables,
@JsonView({PromptVersion.View.Public.class,
PromptVersion.View.Detail.class}) @Schema(accessMode = Schema.AccessMode.READ_ONLY) Instant createdAt,
@JsonView({PromptVersion.View.Public.class,
PromptVersion.View.Detail.class}) @Schema(accessMode = Schema.AccessMode.READ_ONLY) String createdBy){

public static class View {
public static class Public {
}

public static class Detail {
}
}

@Builder
public record PromptVersionPage(
@JsonView( {
PromptVersion.View.Public.class}) int page,
@JsonView({PromptVersion.View.Public.class}) int size,
@JsonView({PromptVersion.View.Public.class}) long total,
@JsonView({PromptVersion.View.Public.class}) List<PromptVersion> content)
implements
Page<PromptVersion>{

public static PromptVersion.PromptVersionPage empty(int page) {
return new PromptVersion.PromptVersionPage(page, 0, 0, List.of());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.comet.opik.api;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import jakarta.validation.constraints.NotBlank;
import lombok.Builder;

@Builder(toBuilder = true)
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
public record PromptVersionRetrieve(@NotBlank String name, String commit) {
}
Loading

0 comments on commit 18cc509

Please sign in to comment.