diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 52ffe29c1..7b494a6ac 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,7 +38,7 @@ jobs: fail-fast: false matrix: java: ['adopt@1.8', 'adopt@1.11'] - scala: ['2.12.17', '2.13.8', '3.2.1'] + scala: ['2.12.18', '2.13.12', '3.3.1'] steps: - uses: actions/checkout@v3.0.0 with: diff --git a/README.md b/README.md index 0256df25a..53af4601c 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,8 @@ import zio.stream._ import zio.schema.codec.{BinaryCodec, ProtobufCodec} import zio.schema.{DeriveSchema, Schema} +import java.io.IOException + final case class Person(name: String, age: Int) object Person { @@ -71,7 +73,7 @@ object Person { } object Main extends ZIOAppDefault { - def run = + def run: ZIO[Any, IOException, Unit] = ZStream .succeed(Person("John", 43)) .via(Person.protobufCodec.streamEncoder) diff --git a/build.sbt b/build.sbt index c17b2c545..fe773ab73 100644 --- a/build.sbt +++ b/build.sbt @@ -190,7 +190,8 @@ lazy val zioSchemaThrift = crossProject(JSPlatform, JVMPlatform) .settings(buildInfoSettings("zio.schema.thrift")) .settings( libraryDependencies ++= Seq( - "org.apache.thrift" % "libthrift" % "0.16.0" + "org.apache.thrift" % "libthrift" % thriftVersion, + "javax.annotation" % "javax.annotation-api" % javaxAnnotationApiVersion ) ) @@ -208,9 +209,9 @@ lazy val zioSchemaMsgPack = crossProject(JSPlatform, JVMPlatform) .settings(buildInfoSettings("zio.schema.msgpack")) .settings( libraryDependencies ++= Seq( - "org.msgpack" % "msgpack-core" % "0.9.3", - "org.msgpack" % "jackson-dataformat-msgpack" % "0.9.3" % Test, - "com.fasterxml.jackson.module" %% "jackson-module-scala" % "2.13.2" % Test + "org.msgpack" % "msgpack-core" % msgpackVersion, + "org.msgpack" % "jackson-dataformat-msgpack" % msgpackVersion % Test, + "com.fasterxml.jackson.module" %% "jackson-module-scala" % jacksonScalaVersion % Test ) ) diff --git a/docs/derivations/optics-derivation.md b/docs/derivations/optics-derivation.md index 1ac56bc9b..e66e794da 100644 --- a/docs/derivations/optics-derivation.md +++ b/docs/derivations/optics-derivation.md @@ -229,7 +229,7 @@ import zio.schema.Schema._ import zio.schema._ object IntList { - implicit val listschema = + implicit val listschema: Schema.Sequence[List[Int], Int, String] = Sequence[List[Int], Int, String]( elementSchema = Schema[Int], fromChunk = _.toList, diff --git a/docs/examples/mapping-dto-to-domain-object.md b/docs/examples/mapping-dto-to-domain-object.md index 11635c2de..f0df64553 100644 --- a/docs/examples/mapping-dto-to-domain-object.md +++ b/docs/examples/mapping-dto-to-domain-object.md @@ -18,10 +18,10 @@ import java.time.LocalDate object MainApp extends ZIOAppDefault { case class PersonDTO( - firstName: String, - lastName: String, - birthday: (Int, Int, Int) - ) + firstName: String, + lastName: String, + birthday: (Int, Int, Int) + ) object PersonDTO { implicit val schema: Schema[PersonDTO] = DeriveSchema.gen[PersonDTO] @@ -71,27 +71,29 @@ object MainApp extends ZIOAppDefault { |} |""".stripMargin - def run = for { - // Approach 1: Decode JSON String to PersonDTO and then Transform it into the Person object - personDTO <- ZIO.fromEither(JsonCodec[PersonDTO].decodeJson(json)) - (year, month, day) = personDTO.birthday - person1 = Person( - name = personDTO.firstName + " " + personDTO.lastName, - LocalDate.of(year, month, day) - ) - _ <- ZIO.debug( - s"person: $person1" - ) - - // Approach 2: Decode JSON string in one step into the Person object - person2 <- ZIO.fromEither( - JsonCodec[Person](Person.personDTOJsonMapperCodec).decodeJson(json) - ) - _ <- ZIO.debug( - s"person: $person2" - ) - } yield assert(person1 == person2) + def run: zio.ZIO[Any, String, Any] = + for { + // Approach 1: Decode JSON String to PersonDTO and then Transform it into the Person object + personDTO <- ZIO.fromEither(JsonCodec[PersonDTO].decodeJson(json)) + (year, month, day) = personDTO.birthday + person1 = Person( + name = personDTO.firstName + " " + personDTO.lastName, + LocalDate.of(year, month, day) + ) + _ <- ZIO.debug( + s"person: $person1" + ) + + // Approach 2: Decode JSON string in one step into the Person object + person2 <- ZIO.fromEither( + JsonCodec[Person](Person.personDTOJsonMapperCodec).decodeJson(json) + ) + _ <- ZIO.debug( + s"person: $person2" + ) + } yield assert(person1 == person2) } + ``` As we can see in the example above, the second approach is much simpler and more convenient than the first one. @@ -111,10 +113,10 @@ import java.time.LocalDate object MainApp extends ZIOAppDefault { case class PersonDTO( - firstName: String, - lastName: String, - birthday: (Int, Int, Int) - ) + firstName: String, + lastName: String, + birthday: (Int, Int, Int) + ) object PersonDTO { implicit val schema: Schema[PersonDTO] = DeriveSchema.gen[PersonDTO] @@ -152,16 +154,17 @@ object MainApp extends ZIOAppDefault { ZIO.fromEither( PersonDTO.schema .migrate(personDTOMapperSchema) - .flatMap(_ (p)) + .flatMap(_(p)) ) } - - def run = for { - personDTO <- ZIO.succeed(PersonDTO("John", "Doe", (1981, 7, 13))) - person <- Person.fromPersonDTO(personDTO) - _ <- ZIO.debug(s"person: $person") - } yield () + def run: zio.ZIO[Any, String, Any] = + for { + personDTO <- ZIO.succeed(PersonDTO("John", "Doe", (1981, 7, 13))) + person <- Person.fromPersonDTO(personDTO) + _ <- ZIO.debug(s"person: $person") + } yield () } + ``` diff --git a/docs/index.md b/docs/index.md index 9ef5f803c..495d90243 100644 --- a/docs/index.md +++ b/docs/index.md @@ -63,6 +63,8 @@ import zio.stream._ import zio.schema.codec.{BinaryCodec, ProtobufCodec} import zio.schema.{DeriveSchema, Schema} +import java.io.IOException + final case class Person(name: String, age: Int) object Person { @@ -71,7 +73,7 @@ object Person { } object Main extends ZIOAppDefault { - def run = + def run: ZIO[Any, IOException, Unit] = ZStream .succeed(Person("John", 43)) .via(Person.protobufCodec.streamEncoder) diff --git a/docs/integration-with-zio-streams.md b/docs/integration-with-zio-streams.md index 7335a5463..9ef5b5489 100644 --- a/docs/integration-with-zio-streams.md +++ b/docs/integration-with-zio-streams.md @@ -22,7 +22,7 @@ object Main extends ZIOAppDefault { implicit val schema: Schema[Person] = DeriveSchema.gen[Person] } - def run = + def run: ZIO[Any, Exception, Unit] = ZStream .fromIterable(Seq(Person("John", 42))) .debug("the input object is") diff --git a/docs/operations/dynamic-data-representation.md b/docs/operations/dynamic-data-representation.md index 395f99978..e89ac0ece 100644 --- a/docs/operations/dynamic-data-representation.md +++ b/docs/operations/dynamic-data-representation.md @@ -25,7 +25,7 @@ import zio.schema._ case class Person(name: String, age: Int) object Person { - implicit val schema = DeriveSchema.gen[Person] + implicit val schema: Schema[Person] = DeriveSchema.gen[Person] } val person = Person("John Doe", 42) diff --git a/docs/operations/validating-types.md b/docs/operations/validating-types.md index 8498ff13c..3cc6d1b57 100644 --- a/docs/operations/validating-types.md +++ b/docs/operations/validating-types.md @@ -24,7 +24,7 @@ import zio.schema.validation.Validation case class Person(name: String, age: Int) object Person { - implicit val schema = CaseClass2( + implicit val schema: Schema[Person] = CaseClass2( id0 = TypeId.fromTypeName("Person"), field01 = Schema.Field( name0 = "name", diff --git a/project/BuildHelper.scala b/project/BuildHelper.scala index 1448a489f..9c7fbb9f7 100644 --- a/project/BuildHelper.scala +++ b/project/BuildHelper.scala @@ -23,22 +23,26 @@ object BuildHelper { val Scala212: String = versions("2.12") val Scala213: String = versions("2.13") - val Scala3: String = versions("3.2") //versions.getOrElse("3.0", versions("3.1")) + val Scala3: String = versions("3.3") - val zioVersion = "2.0.10" - val zioJsonVersion = "0.5.0" - val zioPreludeVersion = "1.0.0-RC18" + val zioVersion = "2.0.19" + val zioJsonVersion = "0.6.2" + val zioPreludeVersion = "1.0.0-RC21" val zioOpticsVersion = "0.2.1" - val zioBsonVersion = "1.0.2" - val silencerVersion = "1.7.11" - val avroVersion = "1.11.0" - val bsonVersion = "4.9.1" + val zioBsonVersion = "1.0.5" + val silencerVersion = "1.7.14" + val avroVersion = "1.11.3" + val bsonVersion = "4.11.1" val zioConstraintlessVersion = "0.3.2" val scalaCollectionCompatVersion = "2.10.0" + val msgpackVersion = "0.9.6" + val jacksonScalaVersion = "2.15.2" + val thriftVersion = "0.16.0" + val javaxAnnotationApiVersion = "1.3.2" private val testDeps = Seq( - "dev.zio" %% "zio-test" % zioVersion % "test", - "dev.zio" %% "zio-test-sbt" % zioVersion % "test" + "dev.zio" %% "zio-test" % zioVersion % Test, + "dev.zio" %% "zio-test-sbt" % zioVersion % Test ) def macroDefinitionSettings = Seq( @@ -47,8 +51,8 @@ object BuildHelper { if (scalaVersion.value == Scala3) Seq() else Seq( - "org.scala-lang" % "scala-reflect" % scalaVersion.value % "provided", - "org.scala-lang" % "scala-compiler" % scalaVersion.value % "provided" + "org.scala-lang" % "scala-reflect" % scalaVersion.value % Provided, + "org.scala-lang" % "scala-compiler" % scalaVersion.value % Provided ) } ) @@ -119,18 +123,19 @@ object BuildHelper { "-opt-warnings", "-Ywarn-extra-implicit", "-Ywarn-unused", - "-Ymacro-annotations" + "-Ymacro-annotations", + "-Ywarn-macros:after" ) ++ std2xOptions ++ optimizerOptions case Some((2, 12)) => Seq( "-Ypartial-unification", "-opt-warnings", "-Ywarn-extra-implicit", - "-Ywarn-unused", "-Yno-adapted-args", "-Ywarn-inaccessible", "-Ywarn-nullary-override", - "-Ywarn-nullary-unit" + "-Ywarn-nullary-unit", + "-Wconf:cat=unused-nowarn:s" ) ++ std2xOptions ++ optimizerOptions case _ => Seq.empty } @@ -205,8 +210,7 @@ object BuildHelper { ThisBuild / semanticdbVersion := scalafixSemanticdb.revision, ThisBuild / scalafixScalaBinaryVersion := CrossVersion.binaryScalaVersion(scalaVersion.value), ThisBuild / scalafixDependencies ++= List( - "com.github.liancheng" %% "organize-imports" % "0.6.0", - "com.github.vovapolu" %% "scaluzzi" % "0.1.21" + "com.github.vovapolu" %% "scaluzzi" % "0.1.23" ), Test / parallelExecution := !sys.env.contains("CI"), incOptions ~= (_.withLogRecompileOnMacro(true)), diff --git a/project/build.properties b/project/build.properties index 46e43a97e..e8a1e246e 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.8.2 +sbt.version=1.9.7 diff --git a/project/plugins.sbt b/project/plugins.sbt index e9332f489..311555266 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,13 +1,13 @@ addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.5") addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.11.1") -addSbtPlugin("com.github.cb372" % "sbt-explicit-dependencies" % "0.2.10") -addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.13.1") -addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.3.0") +addSbtPlugin("com.github.cb372" % "sbt-explicit-dependencies" % "0.3.1") +addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.14.0") +addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.3.2") addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.11.0") -addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.11") -addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "1.1.0") -addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.4") -addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.3") +addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.12") +addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "1.3.2") +addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.16") +addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.6") addSbtPlugin("dev.zio" % "zio-sbt-website" % "0.3.10") -libraryDependencies += "org.snakeyaml" % "snakeyaml-engine" % "2.5" +libraryDependencies += "org.snakeyaml" % "snakeyaml-engine" % "2.7" diff --git a/tests/shared/src/test/scala-2/zio/schema/AccessorBuilderSpec.scala b/tests/shared/src/test/scala-2/zio/schema/AccessorBuilderSpec.scala index d2b467cf7..867d7ff29 100644 --- a/tests/shared/src/test/scala-2/zio/schema/AccessorBuilderSpec.scala +++ b/tests/shared/src/test/scala-2/zio/schema/AccessorBuilderSpec.scala @@ -37,8 +37,8 @@ object AccessorBuilderSpec extends ZIOSpecDefault { check(SchemaGen.anyPrimitive) { schema => val transform = schema.transformOrFail[Unit](_ => Left("error"), _ => Left("error")) - val transformAccessor: Any = transform.makeAccessors(builder).asInstanceOf[Any] - val schemaAccessor: Any = schema.makeAccessors(builder).asInstanceOf[Any] + val transformAccessor = transform.makeAccessors(builder) + val schemaAccessor = schema.makeAccessors(builder) assert( transformAccessor == schemaAccessor diff --git a/tests/shared/src/test/scala/zio/schema/SchemaSpec.scala b/tests/shared/src/test/scala/zio/schema/SchemaSpec.scala index fbecd6bf6..08cb29d35 100644 --- a/tests/shared/src/test/scala/zio/schema/SchemaSpec.scala +++ b/tests/shared/src/test/scala/zio/schema/SchemaSpec.scala @@ -1,5 +1,6 @@ package zio.schema +import scala.annotation.nowarn import scala.collection.immutable.ListMap import zio.Chunk @@ -64,7 +65,7 @@ object SchemaSpec extends ZIOSpecDefault { ) ) - def schemaEnum(key: String): Schema[Any] = + @nowarn def schemaEnum(key: String): Schema[Any] = Schema.enumeration[Any, CaseSet.Aux[Any]]( TypeId.Structural, caseOf[Unit, Any](key)(_ => ())(_.asInstanceOf[CaseSet.Aux[Any]])( diff --git a/zio-schema-derivation/shared/src/main/scala-2/zio/schema/DeriveSchema.scala b/zio-schema-derivation/shared/src/main/scala-2/zio/schema/DeriveSchema.scala index cac9400be..aca1ba21e 100644 --- a/zio-schema-derivation/shared/src/main/scala-2/zio/schema/DeriveSchema.scala +++ b/zio-schema-derivation/shared/src/main/scala-2/zio/schema/DeriveSchema.scala @@ -1,6 +1,5 @@ package zio.schema -import scala.annotation.nowarn import scala.reflect.macros.whitebox import zio.Chunk @@ -28,7 +27,7 @@ object DeriveSchema { def isMap(tpe: Type): Boolean = tpe.typeSymbol.fullName == "scala.collection.immutable.Map" - @nowarn def collectTypeAnnotations(tpe: Type): List[Tree] = + def collectTypeAnnotations(tpe: Type): List[Tree] = tpe.typeSymbol.annotations.collect { case annotation if !(annotation.tree.tpe <:< JavaAnnotationTpe) => annotation.tree match { @@ -185,7 +184,6 @@ object DeriveSchema { } } - @nowarn def getFieldName(annotations: List[Tree]): Option[String] = annotations.collectFirst { case q"new fieldName($name1)" => name1.toString @@ -238,7 +236,6 @@ object DeriveSchema { } .toMap - @nowarn val fieldAnnotations: List[List[Tree]] = //List.fill(arity)(Nil) tpe.typeSymbol.asClass.primaryConstructor.asMethod.paramLists.headOption.map { symbols => symbols.zipWithIndex.map { @@ -260,8 +257,8 @@ object DeriveSchema { } val hasDefaultAnnotation = annotations.exists { - case q"new _root_.zio.schema.annotation.fieldDefaultValue(..$args)" => true - case _ => false + case q"new _root_.zio.schema.annotation.fieldDefaultValue(..$_)" => true + case _ => false } if (hasDefaultAnnotation || defaultConstructorValues.get(i).isEmpty) { annotations @@ -274,14 +271,13 @@ object DeriveSchema { }.filter(_ != EmptyTree) }.getOrElse(Nil) - @nowarn val fieldValidations: List[Tree] = tpe.typeSymbol.asClass.primaryConstructor.asMethod.paramLists.headOption.map { symbols => symbols.map { symbol => symbol.annotations.collect { case annotation if (annotation.tree.tpe.toString.startsWith("zio.schema.annotation.validate")) => annotation.tree match { - case q"new $annConstructor(..$annotationArgs)" => + case q"new $_(..$annotationArgs)" => q"..$annotationArgs" case tree => c.warning(c.enclosingPosition, s"Unhandled annotation tree $tree") @@ -541,7 +537,6 @@ object DeriveSchema { val hasSimpleEnum: Boolean = tpe.typeSymbol.annotations.exists(_.tree.tpe =:= typeOf[_root_.zio.schema.annotation.simpleEnum]) - @nowarn val typeAnnotations: List[Tree] = (isSimpleEnum, hasSimpleEnum) match { case (true, false) => tpe.typeSymbol.annotations.collect { @@ -589,8 +584,7 @@ object DeriveSchema { val typeArgs = subtypes ++ Iterable(tpe) - val cases = subtypes.map { subtype: Type => - @nowarn + val cases = subtypes.map { (subtype: Type) => val typeAnnotations: List[Tree] = subtype.typeSymbol.annotations.collect { case annotation if !(annotation.tree.tpe <:< JavaAnnotationTpe) => diff --git a/zio-schema-derivation/shared/src/main/scala-3/zio/schema/Derive.scala b/zio-schema-derivation/shared/src/main/scala-3/zio/schema/Derive.scala index c33c8cdcf..b4c342f21 100644 --- a/zio-schema-derivation/shared/src/main/scala-3/zio/schema/Derive.scala +++ b/zio-schema-derivation/shared/src/main/scala-3/zio/schema/Derive.scala @@ -14,7 +14,9 @@ object Derive { DeriveInstance().deriveInstance[F, A](deriver, schema, top = true) } -private case class DeriveInstance()(using val ctx: Quotes) extends ReflectionUtils(ctx) { +private case class DeriveInstance()(using val ctx: Quotes) { + val reflectionUtils = ReflectionUtils(ctx) + import reflectionUtils.{MirrorType, Mirror, summonOptional} import ctx.reflect._ case class Frame(ref: Term, tpe: TypeRepr) diff --git a/zio-schema-derivation/shared/src/main/scala-3/zio/schema/DeriveSchema.scala b/zio-schema-derivation/shared/src/main/scala-3/zio/schema/DeriveSchema.scala index 722a23223..55d7a5cf6 100644 --- a/zio-schema-derivation/shared/src/main/scala-3/zio/schema/DeriveSchema.scala +++ b/zio-schema-derivation/shared/src/main/scala-3/zio/schema/DeriveSchema.scala @@ -18,7 +18,9 @@ object DeriveSchema { DeriveSchema().deriveSchema[T](top = true) } -private case class DeriveSchema()(using val ctx: Quotes) extends ReflectionUtils(ctx) { +private case class DeriveSchema()(using val ctx: Quotes) { + val reflectionUtils = ReflectionUtils(ctx) + import reflectionUtils.{MirrorType, Mirror, summonOptional} import ctx.reflect._ case class Frame(ref: Term, tpe: TypeRepr) diff --git a/zio-schema-derivation/shared/src/test/scala-2.13/zio/schema/VersionSpecificDeriveSchemaSpec.scala b/zio-schema-derivation/shared/src/test/scala-2.13/zio/schema/VersionSpecificDeriveSchemaSpec.scala index 221958f6f..8e70f6a32 100644 --- a/zio-schema-derivation/shared/src/test/scala-2.13/zio/schema/VersionSpecificDeriveSchemaSpec.scala +++ b/zio-schema-derivation/shared/src/test/scala-2.13/zio/schema/VersionSpecificDeriveSchemaSpec.scala @@ -1,7 +1,5 @@ package zio.schema -import scala.annotation.nowarn - import zio.test._ trait VersionSpecificDeriveSchemaSpec extends ZIOSpecDefault { @@ -15,7 +13,7 @@ trait VersionSpecificDeriveSchemaSpec extends ZIOSpecDefault { def verifyFieldName[F]: FieldNameVerifier[F] = new FieldNameVerifier[F] class FieldNameVerifier[F] { - @nowarn def apply[S <: String & scala.Singleton](name: S)(implicit ev: F =:= S): Boolean = true + def apply[S <: String & scala.Singleton](name: S)(implicit ev: F =:= S): Boolean = true } def versionSpecificSuite: Spec[Any, Nothing] = Spec.labeled("Scala 2.13 specific tests", Spec.empty) diff --git a/zio-schema-derivation/shared/src/test/scala/zio/schema/DeriveSpec.scala b/zio-schema-derivation/shared/src/test/scala/zio/schema/DeriveSpec.scala index 0814153be..0bd2ea19f 100644 --- a/zio-schema-derivation/shared/src/test/scala/zio/schema/DeriveSpec.scala +++ b/zio-schema-derivation/shared/src/test/scala/zio/schema/DeriveSpec.scala @@ -9,7 +9,7 @@ import zio.schema.annotation.fieldDefaultValue import zio.test.{ Spec, TestEnvironment, ZIOSpecDefault, assertTrue } import zio.{ Chunk, Scope } -object DeriveSpec extends ZIOSpecDefault with VersionSpecificDeriveSpec { +@nowarn object DeriveSpec extends ZIOSpecDefault with VersionSpecificDeriveSpec { override def spec: Spec[TestEnvironment with Scope, Any] = suite("Derive")( suite("case object")( @@ -368,7 +368,7 @@ object DeriveSpec extends ZIOSpecDefault with VersionSpecificDeriveSpec { @SuppressWarnings(Array("all")) object UnsupportedField1 { - @nowarn implicit private val openTraitPlaceholderSchema: Schema[OpenTrait] = Schema.fail("OpenTrait") + implicit private val openTraitPlaceholderSchema: Schema[OpenTrait] = Schema.fail("OpenTrait") implicit val schema: Schema[UnsupportedField1] = DeriveSchema.gen[UnsupportedField1] } diff --git a/zio-schema/shared/src/main/scala/zio/schema/MutableSchemaBasedValueProcessor.scala b/zio-schema/shared/src/main/scala/zio/schema/MutableSchemaBasedValueProcessor.scala index c044608f4..3c1bb24bf 100644 --- a/zio-schema/shared/src/main/scala/zio/schema/MutableSchemaBasedValueProcessor.scala +++ b/zio-schema/shared/src/main/scala/zio/schema/MutableSchemaBasedValueProcessor.scala @@ -1,6 +1,5 @@ package zio.schema -import scala.annotation.nowarn import scala.collection.immutable.ListMap import zio.schema.annotation.transientField @@ -26,49 +25,49 @@ trait MutableSchemaBasedValueProcessor[Target, Context] { protected def processPrimitive(context: Context, value: Any, typ: StandardType[Any]): Target /** Called before processing a record (before calling processXYZ for the record's fields) */ - @nowarn protected def startProcessingRecord(context: Context, schema: Schema.Record[_]): Unit = {} + protected def startProcessingRecord(context: Context, schema: Schema.Record[_]): Unit = {} /** Process a record in the given context with the given schema, using the already processed values of its fields. */ protected def processRecord(context: Context, schema: Schema.Record[_], value: ListMap[String, Target]): Target /** Called before processing an enum */ - @nowarn protected def startProcessingEnum(context: Context, schema: Schema.Enum[_]): Unit = {} + protected def startProcessingEnum(context: Context, schema: Schema.Enum[_]): Unit = {} /** Process an enum in the given context with the given schema using the processed constructor value and it's name */ protected def processEnum(context: Context, schema: Schema.Enum[_], tuple: (String, Target)): Target /** Called before processing a sequence */ - @nowarn protected def startProcessingSequence(context: Context, schema: Schema.Sequence[_, _, _], size: Int): Unit = {} + protected def startProcessingSequence(context: Context, schema: Schema.Sequence[_, _, _], size: Int): Unit = {} /** Process a sequence using its already processed elements */ protected def processSequence(context: Context, schema: Schema.Sequence[_, _, _], value: Chunk[Target]): Target /** Called before processing a dictionary */ - @nowarn protected def startProcessingDictionary(context: Context, schema: Schema.Map[_, _], size: Int): Unit = {} + protected def startProcessingDictionary(context: Context, schema: Schema.Map[_, _], size: Int): Unit = {} /*** Process a dictionary using its already processed key-value pairs */ protected def processDictionary(context: Context, schema: Schema.Map[_, _], value: Chunk[(Target, Target)]): Target /** Called before processing a set */ - @nowarn protected def startProcessingSet(context: Context, schema: Schema.Set[_], size: Int): Unit = {} + protected def startProcessingSet(context: Context, schema: Schema.Set[_], size: Int): Unit = {} /** Process a set using its already processed elements */ protected def processSet(context: Context, schema: Schema.Set[_], value: Set[Target]): Target /** Called before processing and either value */ - @nowarn protected def startProcessingEither(context: Context, schema: Schema.Either[_, _]): Unit = {} + protected def startProcessingEither(context: Context, schema: Schema.Either[_, _]): Unit = {} /** Process an either value using its already processed left or right value */ protected def processEither(context: Context, schema: Schema.Either[_, _], value: Either[Target, Target]): Target /** Called before processing an option value */ - @nowarn protected def startProcessingOption(context: Context, schema: Schema.Optional[_]): Unit = {} + protected def startProcessingOption(context: Context, schema: Schema.Optional[_]): Unit = {} /** Process an optional value using its already processed inner value, or None */ protected def processOption(context: Context, schema: Schema.Optional[_], value: Option[Target]): Target /** Called before processing a pair of values */ - @nowarn protected def startProcessingTuple(context: Context, schema: Schema.Tuple2[_, _]): Unit = {} + protected def startProcessingTuple(context: Context, schema: Schema.Tuple2[_, _]): Unit = {} /** Process a tuple using its already processed left and right values */ protected def processTuple(context: Context, schema: Schema.Tuple2[_, _], left: Target, right: Target): Target diff --git a/zio-schema/shared/src/main/scala/zio/schema/Schema.scala b/zio-schema/shared/src/main/scala/zio/schema/Schema.scala index 3c4532424..09a82ce1e 100644 --- a/zio-schema/shared/src/main/scala/zio/schema/Schema.scala +++ b/zio-schema/shared/src/main/scala/zio/schema/Schema.scala @@ -1,6 +1,6 @@ package zio.schema -import java.net.{ URI, URL } +import java.net.URI import java.time.temporal.ChronoUnit import scala.annotation.tailrec @@ -320,7 +320,7 @@ object Schema extends SchemaEquality { Schema[String].transformOrFail( string => try { - Right(new URL(string)) + Right(new URI(string).toURL) } catch { case _: Exception => Left(s"Invalid URL: $string") }, url => Right(url.toString) ) diff --git a/zio-schema/shared/src/main/scala/zio/schema/meta/ExtensibleMetaSchema.scala b/zio-schema/shared/src/main/scala/zio/schema/meta/ExtensibleMetaSchema.scala index d406e2d08..f9d45fa98 100644 --- a/zio-schema/shared/src/main/scala/zio/schema/meta/ExtensibleMetaSchema.scala +++ b/zio-schema/shared/src/main/scala/zio/schema/meta/ExtensibleMetaSchema.scala @@ -616,9 +616,9 @@ object ExtensibleMetaSchema { Schema.Primitive(typ, Chunk.empty) case ExtensibleMetaSchema.FailNode(msg, _, _) => Schema.Fail(msg) case ExtensibleMetaSchema.Ref(refPath, _, _) => - Schema.defer( - refs.getOrElse(refPath, Schema.Fail(s"invalid ref path $refPath")) - ) + def resolve[A](): Schema[A] = + refs.getOrElse(refPath, Schema.Fail(s"invalid ref path $refPath")).asInstanceOf[Schema[A]] + Schema.defer(resolve()) case ExtensibleMetaSchema.Product(id, _, elems, _) => Schema.record( id,