Skip to content

Commit

Permalink
Added codec for IntOrBoolean.
Browse files Browse the repository at this point in the history
  • Loading branch information
pme123 committed Jan 14, 2025
1 parent 18b7332 commit f8051a1
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions 01-domain/src/main/scala/camundala/domain/exports.scala
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,22 @@ given InOutCodec[IntOrString] = CirceCodec.from(
type IntOrString = Int | String
given ApiSchema[IntOrString] = Schema.derivedUnion

type IntOrBoolean = Int | Boolean

given ApiSchema[IntOrBoolean] = Schema.derivedUnion
given InOutCodec[IntOrBoolean] = CirceCodec.from(
new Decoder[IntOrBoolean]:
final def apply(c: HCursor): Decoder.Result[IntOrBoolean] =
if c.value.isBoolean
then c.as[Boolean]
else c.as[Int]
,
new Encoder[IntOrBoolean]:
final def apply(a: IntOrBoolean): Json = a match
case s: Boolean => Json.fromBoolean(s)
case i: Int => Json.fromInt(i)
)

case class NoInput()
object NoInput:
given ApiSchema[NoInput] = deriveApiSchema
Expand Down

0 comments on commit f8051a1

Please sign in to comment.