Skip to content

Instantly share code, notes, and snippets.

@blast-hardcheese
Created May 27, 2022 05:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blast-hardcheese/4e0037332eb606330b90c3b19650e874 to your computer and use it in GitHub Desktop.
Save blast-hardcheese/4e0037332eb606330b90c3b19650e874 to your computer and use it in GitHub Desktop.
guardrail sbt extensibility example
diff --git a/target/scala-2.13/src_managed/main/example/client/definitions/Pet.scala b/target/scala-2.13/src_managed/main/example/client/definitions/Pet.scala
index 14c35aa..2200d91 100644
--- a/target/scala-2.13/src_managed/main/example/client/definitions/Pet.scala
+++ b/target/scala-2.13/src_managed/main/example/client/definitions/Pet.scala
@@ -8,7 +8,7 @@ import io.circe._
import io.circe.syntax._
import cats.implicits._
import _root_.example.client.Implicits._
-case class Pet(category: Option[Category] = None, id: Option[Long] = None, name: String = "Fluffy", photoUrls: Vector[String] = Vector.empty, status: Option[Pet.Status] = None, tags: Option[_root_.scala.Vector[Tag]] = None)
+case class Pet(category: Option[Category], id: Option[Long], name: String, photoUrls: Vector[String], status: Option[Pet.Status], tags: Option[_root_.scala.Vector[Tag]])
object Pet {
implicit val encodePet: _root_.io.circe.Encoder.AsObject[Pet] = {
val readOnlyKeys = _root_.scala.Predef.Set[_root_.scala.Predef.String]()
  1. Check out the http4s sample repo and switch to bespoke-guardrail-extensibility branch.
  2. sbt> ++ 2.12.13 to select a version compatible with sbt's scalaVersion
  3. sbt> customCirce/publishLocal
  4. Uncomment "customcirce" dependency in project/plugins.sbt
  5. sbt> reload
  6. sbt> guardrail

This will use the custom CirceProtocolGenerator extensions defined in

custom-circe/src/main/scala/CustomCirce.scala

injected by way of

custom-circe/src/main/resources/META-INF/services/dev.guardrail.generators.spi.ProtocolGeneratorLoader

The diff of circe vs custom-circe is in the Changeset.diff included in this gist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment