Skip to content

Commit

Permalink
Merge branch 'main' into type_parameters_derive
Browse files Browse the repository at this point in the history
  • Loading branch information
vigoo authored Aug 12, 2023
2 parents 678568a + 26bb289 commit 8a1a9d4
Show file tree
Hide file tree
Showing 9 changed files with 4,563 additions and 2,911 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ _ZIO Schema_ is used by a growing number of ZIO libraries, including _ZIO Flow_,
In order to use this library, we need to add the following lines in our `build.sbt` file:

```scala
libraryDependencies += "dev.zio" %% "zio-schema" % "0.4.11"
libraryDependencies += "dev.zio" %% "zio-schema-bson" % "0.4.11"
libraryDependencies += "dev.zio" %% "zio-schema-json" % "0.4.11"
libraryDependencies += "dev.zio" %% "zio-schema-protobuf" % "0.4.11"
libraryDependencies += "dev.zio" %% "zio-schema" % "0.4.12"
libraryDependencies += "dev.zio" %% "zio-schema-bson" % "0.4.12"
libraryDependencies += "dev.zio" %% "zio-schema-json" % "0.4.12"
libraryDependencies += "dev.zio" %% "zio-schema-protobuf" % "0.4.12"

// Required for automatic generic derivation of schemas
libraryDependencies += "dev.zio" %% "zio-schema-derivation" % "0.4.11",
libraryDependencies += "dev.zio" %% "zio-schema-derivation" % "0.4.12",
libraryDependencies += "org.scala-lang" % "scala-reflect" % scalaVersion.value % "provided"
```

Expand Down
1 change: 1 addition & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ lazy val zioSchemaAvro = crossProject(JSPlatform, JVMPlatform)
.in(file("zio-schema-avro"))
.dependsOn(zioSchema, zioSchemaDerivation, tests % "test->test")
.settings(stdSettings("zio-schema-avro"))
.settings(dottySettings)
.settings(crossProjectSettings)
.settings(buildInfoSettings("zio.schema.avro"))
.settings(
Expand Down
1,766 changes: 873 additions & 893 deletions zio-schema-avro/shared/src/main/scala/zio/schema/codec/AvroCodec.scala

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2,659 changes: 649 additions & 2,010 deletions zio-schema-avro/shared/src/test/scala-2/zio/schema/codec/AvroCodecSpec.scala

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ private case class DeriveSchema()(using val ctx: Quotes) extends ReflectionUtils
}

def deriveCaseObject[T: Type](stack: Stack, top: Boolean)(using Quotes) = {
val selfRefSymbol = Symbol.newVal(Symbol.spliceOwner, s"derivedSchema${stack.size}", TypeRepr.of[Schema[T]], Flags.Lazy, Symbol.spliceOwner)
val selfRefSymbol = Symbol.newVal(Symbol.spliceOwner, s"derivedSchema${stack.size}", TypeRepr.of[Schema[T]], Flags.Lazy, Symbol.noSymbol)
val selfRef = Ref(selfRefSymbol)

val typeInfo = '{TypeId.parse(${Expr(TypeRepr.of[T].show)})}
Expand Down Expand Up @@ -150,7 +150,7 @@ private case class DeriveSchema()(using val ctx: Quotes) extends ReflectionUtils
}

def deriveCaseClass[T: Type](mirror: Mirror, stack: Stack, top: Boolean)(using Quotes) = {
val selfRefSymbol = Symbol.newVal(Symbol.spliceOwner, s"derivedSchema${stack.size}", TypeRepr.of[Schema[T]], Flags.Lazy, Symbol.spliceOwner)
val selfRefSymbol = Symbol.newVal(Symbol.spliceOwner, s"derivedSchema${stack.size}", TypeRepr.of[Schema[T]], Flags.Lazy, Symbol.noSymbol)
val selfRef = Ref(selfRefSymbol)
val newStack = stack.push(selfRef, TypeRepr.of[T])

Expand Down Expand Up @@ -283,7 +283,7 @@ private case class DeriveSchema()(using val ctx: Quotes) extends ReflectionUtils
}.toMap

def deriveEnum[T: Type](mirror: Mirror, stack: Stack)(using Quotes) = {
val selfRefSymbol = Symbol.newVal(Symbol.spliceOwner, s"derivedSchema${stack.size}", TypeRepr.of[Schema[T]], Flags.Lazy, Symbol.spliceOwner)
val selfRefSymbol = Symbol.newVal(Symbol.spliceOwner, s"derivedSchema${stack.size}", TypeRepr.of[Schema[T]], Flags.Lazy, Symbol.noSymbol)
val selfRef = Ref(selfRefSymbol)
val newStack = stack.push(selfRef, TypeRepr.of[T])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ object JsonCodec {
case Schema.Primitive(StandardType.StringType, _) => Option(JsonFieldEncoder.string)
case Schema.Primitive(StandardType.LongType, _) => Option(JsonFieldEncoder.long)
case Schema.Primitive(StandardType.IntType, _) => Option(JsonFieldEncoder.int)
case Schema.Lazy(inner) => jsonFieldEncoder(inner())
case _ => None
}

Expand Down Expand Up @@ -598,6 +599,7 @@ object JsonCodec {
case Schema.Primitive(StandardType.StringType, _) => Option(JsonFieldDecoder.string)
case Schema.Primitive(StandardType.LongType, _) => Option(JsonFieldDecoder.long)
case Schema.Primitive(StandardType.IntType, _) => Option(JsonFieldDecoder.int)
case Schema.Lazy(inner) => jsonFieldDecoder(inner())
case _ => None
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ object JsonCodecSpec extends ZIOSpecDefault {
"""{"0":{"first":0,"second":true},"1":{"first":1,"second":false}}"""
)
)
},
test("of simple keys and values where the key's schema is lazy") {
assertEncodes(
Schema.map[Int, Value](Schema.defer(Schema[Int]), Schema[Value]),
Map(0 -> Value(0, true), 1 -> Value(1, false)),
charSequenceToByteChunk(
"""{"0":{"first":0,"second":true},"1":{"first":1,"second":false}}"""
)
)
}
),
suite("Set")(
Expand Down Expand Up @@ -469,6 +478,15 @@ object JsonCodecSpec extends ZIOSpecDefault {
"""{"0":{"first":0,"second":true},"1":{"first":1,"second":false}}"""
)
)
},
test("of simple keys and values where the key schema is lazy") {
assertDecodes(
Schema.map[Int, Value](Schema.defer(Schema[Int]), Schema[Value]),
Map(0 -> Value(0, true), 1 -> Value(1, false)),
charSequenceToByteChunk(
"""{"0":{"first":0,"second":true},"1":{"first":1,"second":false}}"""
)
)
}
)
)
Expand Down

0 comments on commit 8a1a9d4

Please sign in to comment.