@@ -80,8 +80,7 @@ def generateBySpec(
8080 val resourcesPath = config.outDir / resourcesSplit
8181 val schemasPath = config.outDir / schemasPkg.split('.' )
8282 val commonCodecsObj = " codecs"
83- val commonCodecsPkg = s " $schemasPkg. $commonCodecsObj"
84- val commonCodecsPath = schemasPath / s " $commonCodecsObj.scala "
83+ val commonCodecsPkg = s " ${config.outPkg}. $commonCodecsObj"
8584
8685 for {
8786 _ <- Future {
@@ -143,7 +142,26 @@ def generateBySpec(
143142 Some (e.description)
144143 )} case ` ${e.location}$locationPostfix` extends Endpoint(" ${e.location}", uri" ${e.endpointUrl}") """ .stripMargin
145144 )
146- .mkString(" \n " )
145+ .mkString(" \n " ),
146+ " " ,
147+ config.jsonCodec match
148+ case _ : JsonCodec .Jsoniter =>
149+ s """ |object $commonCodecsObj:
150+ | import com.github.plokhotnyuk.jsoniter_scala.core.JsonValueCodec
151+ | import com.github.plokhotnyuk.jsoniter_scala.macros.JsonCodecMaker
152+ |
153+ | """ .stripMargin + (
154+ config.arrayType match
155+ case gcp.codegen.GeneratorConfig .ArrayType .List =>
156+ " given JsonValueCodec[List[String]] = JsonCodecMaker.make"
157+ case gcp.codegen.GeneratorConfig .ArrayType .Vector =>
158+ " given JsonValueCodec[Vector[String]] = JsonCodecMaker.make"
159+ case gcp.codegen.GeneratorConfig .ArrayType .Array =>
160+ " given JsonValueCodec[Array[String]] = JsonCodecMaker.make"
161+ case ArrayType .ZioChunk =>
162+ " given JsonValueCodec[zio.Chunk[String]] = JsonCodecMaker.make"
163+ )
164+ case _ => " "
147165 ).mkString(" \n " )
148166 )
149167 List (path.toFile())
@@ -236,7 +254,8 @@ def generateBySpec(
236254 pkg = schemasPkg,
237255 jsonCodec = config.jsonCodec,
238256 hasProps = p => specs.hasProps(p),
239- arrType = config.arrayType
257+ arrType = config.arrayType,
258+ commonCodecsPkg = commonCodecsPkg
240259 )
241260 else
242261 // create a type alias for objects without properties
@@ -404,7 +423,8 @@ def schemasCode(
404423 pkg : String ,
405424 jsonCodec : JsonCodec ,
406425 hasProps : SchemaPath => Boolean ,
407- arrType : ArrayType
426+ arrType : ArrayType ,
427+ commonCodecsPkg : String
408428): String = {
409429 def enums =
410430 schema.properties.collect:
@@ -463,8 +483,9 @@ def schemasCode(
463483 jsonCodec match {
464484 case JsonCodec .ZioJson => " import zio.json.*"
465485 case _ : JsonCodec .Jsoniter =>
466- """ |import com.github.plokhotnyuk.jsoniter_scala.core.*
467- |import com.github.plokhotnyuk.jsoniter_scala.macros.*""" .stripMargin
486+ s """ |import com.github.plokhotnyuk.jsoniter_scala.core.*
487+ |import com.github.plokhotnyuk.jsoniter_scala.macros.*
488+ |import ${commonCodecsPkg}.given """ .stripMargin
468489 },
469490 toSchemaClass(schema)
470491 ).mkString(" \n " )
0 commit comments