Skip to content

Commit 48ad126

Browse files
committed
using json-tagged-adt
1 parent 5c2474b commit 48ad126

File tree

2 files changed

+21
-30
lines changed

2 files changed

+21
-30
lines changed

build.sbt

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import ReleaseTransformations._
22
import Dependencies._
33
import scala.sys.process._
44

5-
ThisBuild / scalaVersion := "3.2.0-RC1"
5+
ThisBuild / scalaVersion := "3.2.0-RC3"
66
ThisBuild / versionScheme := Some("semver-spec")
77
ThisBuild / releaseVersionBump := sbtrelease.Version.Bump.Next
88

@@ -40,6 +40,7 @@ excludeDependencies ++= Seq(
4040
)
4141

4242
libraryDependencies ++= Seq(
43+
"org.latestbit" %% "circe-tagged-adt-codec" % "0.10.1",
4344
"co.fs2" %% "fs2-io" % "3.2.9",
4445
"com.monovore" %% "decline-effect" % "2.3.0",
4546
"io.circe" %% "circe-core" % "0.14.2",

src/main/scala/org/polystat/sarif/Sarif.scala

+19-29
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import io.circe.Decoder
55
import io.circe.Encoder
66
import io.circe.Json
77
import org.polystat.cli.BuildInfo
8+
import org.latestbit.circe.adt.codec.JsonTaggedAdt
9+
import JsonTaggedAdt.*
810

911
object Sarif:
1012

@@ -57,39 +59,27 @@ object Sarif:
5759
uri: String
5860
) derives Codec.AsObject
5961

60-
enum SarifLevel:
62+
enum SarifLevel derives PureEncoderWithConfig, PureDecoderWithConfig:
6163
case ERROR, NONE
6264

63-
given Encoder[SarifLevel] with
64-
final def apply(a: SarifLevel): Json = a match
65-
case SarifLevel.ERROR => Json.fromString("error")
66-
case SarifLevel.NONE => Json.fromString("none")
67-
end given
68-
69-
given Decoder[SarifLevel] with
70-
def apply(c: io.circe.HCursor): Decoder.Result[SarifLevel] =
71-
c.get[String]("level").map {
72-
case "error" => SarifLevel.ERROR
73-
case "none" => SarifLevel.NONE
74-
}
75-
end given
76-
77-
enum SarifKind:
65+
given PureConfig[SarifLevel] =
66+
PureConfig.Values[SarifLevel](
67+
mappings = Map(
68+
"error" -> tagged[SarifLevel.ERROR.type],
69+
"none" -> tagged[SarifLevel.NONE.type],
70+
)
71+
)
72+
73+
enum SarifKind derives PureEncoderWithConfig, PureDecoderWithConfig:
7874
case FAIL, PASS
7975

80-
given Encoder[SarifKind] with
81-
final def apply(a: SarifKind): Json = a match
82-
case SarifKind.PASS => Json.fromString("pass")
83-
case SarifKind.FAIL => Json.fromString("fail")
84-
end given
85-
86-
given Decoder[SarifKind] with
87-
def apply(c: io.circe.HCursor): Decoder.Result[SarifKind] =
88-
c.get[String]("kind").map {
89-
case "pass" => SarifKind.PASS
90-
case "fail" => SarifKind.FAIL
91-
}
92-
end given
76+
given PureConfig[SarifKind] =
77+
PureConfig.Values[SarifKind](
78+
mappings = Map(
79+
"fail" -> tagged[SarifKind.FAIL.type],
80+
"pass" -> tagged[SarifKind.PASS.type],
81+
)
82+
)
9383

9484
final case class SarifMessage(text: String) derives Codec.AsObject
9585

0 commit comments

Comments
 (0)