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

Add Scala 3-specific method for building custom schemas #2211

Merged
merged 4 commits into from
May 6, 2024

Conversation

kyri-petrou
Copy link
Collaborator

Improves UX of building custom schemas significantly for Scala 3:

Scala 2:

case class Author(id: String, firstName: String, lastName: String)

implicit val authorSchema: Schema[Any, Author] = Schema.obj("Author"){ implicit attrs =>
  List(
    field("id")(_.id),
    field("fullName")(_ => "foo"),
  )
}

Scala 3:

case class Author(id: String, firstName: String, lastName: String)

given Schema[Any, Author] = Schema.custom("Author")(
  field("id")(_.id),
  field("fullName")(_ => "foo"),
)

Not too sure on the name though, custom implies that it can be used to build other kinds of schemas, but customObject feels a bit too verbose. Thoughts @ghostdogpr?

@ghostdogpr
Copy link
Owner

Since the original was obj, how about customObj?

@kyri-petrou
Copy link
Collaborator Author

Since the original was obj, how about customObj?

Done 👍

@kyri-petrou kyri-petrou merged commit fa51e3a into series/2.x May 6, 2024
10 checks passed
@kyri-petrou kyri-petrou deleted the improve-custom-schema-scala-3 branch May 6, 2024 05:09
XiNiHa pushed a commit to XiNiHa/caliban that referenced this pull request May 11, 2024
)

* Add Scala 3-specific method for building custom schemas

* Fix scaladoc

* PR comment

* Rename customObj in scaladoc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants