@@ -5,6 +5,8 @@ import io.circe.Decoder
5
5
import io .circe .Encoder
6
6
import io .circe .Json
7
7
import org .polystat .cli .BuildInfo
8
+ import org .latestbit .circe .adt .codec .JsonTaggedAdt
9
+ import JsonTaggedAdt .*
8
10
9
11
object Sarif :
10
12
@@ -57,39 +59,27 @@ object Sarif:
57
59
uri : String
58
60
) derives Codec .AsObject
59
61
60
- enum SarifLevel :
62
+ enum SarifLevel derives PureEncoderWithConfig , PureDecoderWithConfig :
61
63
case ERROR , NONE
62
64
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 :
78
74
case FAIL , PASS
79
75
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
+ )
93
83
94
84
final case class SarifMessage (text : String ) derives Codec .AsObject
95
85
0 commit comments