Skip to content

Commit

Permalink
a
Browse files Browse the repository at this point in the history
  • Loading branch information
pablf committed Jun 30, 2024
1 parent 09ca54e commit 0c577ea
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -360,10 +360,9 @@ private case class DeriveSchema()(using val ctx: Quotes) {
val cases = typesAndLabels.map { case (tpe, label) => deriveCase[T](tpe, label, newStack) }

val numParentFields: Int = TypeRepr.of[T].typeSymbol.declaredFields.length
val childrens = TypeRepr.of[T].typeSymbol.children
val childrenFields = children.map(_.declaredFields.length)
val childrenFieldsConstructor = children.map(_.caseFields.length)
val isSimpleEnum: Boolean = childrenFieldsConstructor.forall( _ == 0) && childrenFields.forall( _ <= numParentFields) && children.flatMap(_.children).isEmpty
val isSimpleEnum: Boolean = childrenFieldsConstructor.forall( _ == 0) && childrenFields.forall( _ <= numParentFields) && types.flatMap(_.children).isEmpty
val hasSimpleEnumAnn: Boolean = TypeRepr.of[T].typeSymbol.hasAnnotation(TypeRepr.of[_root_.zio.schema.annotation.simpleEnum].typeSymbol)

val docAnnotationExpr = TypeRepr.of[T].typeSymbol.docstring.map { docstring =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,9 @@ object JsonCodecSpec extends ZIOSpecDefault {
charSequenceToByteChunk(""""FinalElem"""")
)
},
test("fails when adding manually @simpleEnum to non-simple enumerations") {
assertZIO(ZIO.attempt(JsonCodec.schemaBasedBinaryCodec(cfg)(schema)).either)(isLeft(anything))
},
test("case class") {
assertEncodes(
searchRequestWithTransientFieldSchema,
Expand Down Expand Up @@ -1763,7 +1766,12 @@ object JsonCodecSpec extends ZIOSpecDefault {
implicit val schema: zio.schema.Schema[IntermediateEnum] = zio.schema.DeriveSchema.gen[IntermediateEnum]
}

sealed trait NonSimpleEnum

object NonSimpleEnum {
case class Leaf(a: Int) extends NonSimpleEnum
implicit val schema: zio.schema.Schema[NonSimpleEnum] = zio.schema.DeriveSchema.gen[NonSimpleEnum].annotate(simpleEnum())
}

sealed trait Color

Expand Down

0 comments on commit 0c577ea

Please sign in to comment.