@@ -5,6 +5,8 @@ import io.circe.Decoder
55import io .circe .Encoder
66import io .circe .Json
77import org .polystat .cli .BuildInfo
8+ import org .latestbit .circe .adt .codec .JsonTaggedAdt
9+ import JsonTaggedAdt .*
810
911object 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