Skip to content

Commit

Permalink
fix: examples in the OpenApi docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jachro committed Mar 7, 2024
1 parent 5ecca16 commit 1ec4974
Showing 1 changed file with 38 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@

package io.renku.search.api.data

import io.bullet.borer.*
import io.bullet.borer.NullOptions.given
import io.bullet.borer.derivation.MapBasedCodecs.{deriveAllCodecs, deriveCodec}
import io.bullet.borer.{AdtEncodingStrategy, Codec, Decoder, Encoder}
import io.renku.search.model.*
import sttp.tapir.Schema.SName
import sttp.tapir.SchemaType.{SCoproduct, SDateTime, SProductField, SRef}
import sttp.tapir.generic.Configuration
import sttp.tapir.{FieldName, Schema, SchemaType}

import java.time.Instant

sealed trait SearchEntity

final case class Project(
Expand All @@ -50,14 +52,34 @@ object Project:
Schema.derivedEnumeration[projects.Visibility].defaultStringBased
private given Schema[projects.Description] = Schema.string[projects.Description]
private given Schema[projects.CreationDate] = Schema(SDateTime())
given Schema[Project] = Schema.derived[Project]
given Schema[Project] = Schema
.derived[Project]
.encodedExample(
Json.encode {
Project(
projects.Id("01HRA7AZ2Q234CDQWGA052F8MK"),
projects.Name("renku"),
projects.Slug("renku"),
Seq(projects.Repository("https://github.com/renku")),
projects.Visibility.Public,
Some(projects.Description("Renku project")),
UserId(users.Id("1CAF4C73F50D4514A041C9EDDB025A36")),
projects.CreationDate(Instant.now),
Some(1.0)
).asInstanceOf[SearchEntity]
}.toUtf8String
)

final case class UserId(id: users.Id)
object UserId:
given Codec[UserId] = deriveCodec[UserId]

private given Schema[users.Id] = Schema.string[users.Id]
given Schema[UserId] = Schema.derived[UserId]
given Schema[UserId] = Schema
.derived[UserId]
.encodedExample(
Json.encode(UserId(users.Id("01HRA7AZ2Q234CDQWGA052F8MK"))).toUtf8String
)

final case class User(
id: users.Id,
Expand All @@ -72,7 +94,19 @@ object User:
private given Schema[users.FirstName] = Schema.string[users.FirstName]
private given Schema[users.LastName] = Schema.string[users.LastName]
private given Schema[users.Email] = Schema.string[users.Email]
given Schema[User] = Schema.derived[User]
given Schema[User] = Schema
.derived[User]
.encodedExample(
Json.encode {
User(
users.Id("1CAF4C73F50D4514A041C9EDDB025A36"),
Some(users.FirstName("Albert")),
Some(users.LastName("Einstein")),
Some(users.Email("[email protected]")),
Some(2.1)
).asInstanceOf[SearchEntity]
}.toUtf8String
)

object SearchEntity:

Expand Down

0 comments on commit 1ec4974

Please sign in to comment.