Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ ThisBuild / description := "Google Cloud client code generator"
ThisBuild / organization := "dev.rolang"
ThisBuild / licenses := Seq(License.MIT)
ThisBuild / homepage := Some(url("https://github.com/rolang/google-rest-api-codegen"))
ThisBuild / scalaVersion := "3.8.2"
ThisBuild / scalaVersion := "3.8.3"
ThisBuild / version ~= { v => if (v.contains('+')) s"${v.replace('+', '-')}-SNAPSHOT" else v }
ThisBuild / versionScheme := Some("early-semver")
ThisBuild / scmInfo := Some(
Expand Down Expand Up @@ -46,7 +46,7 @@ val zioVersion = "2.1.23"

val zioJsonVersion = "0.8.0"

val jsoniterVersion = "2.38.8"
val jsoniterVersion = "2.38.12"

val munitVersion = "1.2.1"

Expand Down
35 changes: 28 additions & 7 deletions modules/core/shared/src/main/scala/codegen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ def generateBySpec(
val resourcesPath = config.outDir / resourcesSplit
val schemasPath = config.outDir / schemasPkg.split('.')
val commonCodecsObj = "codecs"
val commonCodecsPkg = s"$schemasPkg.$commonCodecsObj"
val commonCodecsPath = schemasPath / s"$commonCodecsObj.scala"
val commonCodecsPkg = s"${config.outPkg}.$commonCodecsObj"

for {
_ <- Future {
Expand Down Expand Up @@ -143,7 +142,26 @@ def generateBySpec(
Some(e.description)
)} case `${e.location}$locationPostfix` extends Endpoint("${e.location}", uri"${e.endpointUrl}")""".stripMargin
)
.mkString("\n")
.mkString("\n"),
"",
config.jsonCodec match
case _: JsonCodec.Jsoniter =>
s"""|object $commonCodecsObj:
| import com.github.plokhotnyuk.jsoniter_scala.core.JsonValueCodec
| import com.github.plokhotnyuk.jsoniter_scala.macros.JsonCodecMaker
|
|""".stripMargin + (
config.arrayType match
case gcp.codegen.GeneratorConfig.ArrayType.List =>
" given JsonValueCodec[List[String]] = JsonCodecMaker.make"
case gcp.codegen.GeneratorConfig.ArrayType.Vector =>
" given JsonValueCodec[Vector[String]] = JsonCodecMaker.make"
case gcp.codegen.GeneratorConfig.ArrayType.Array =>
" given JsonValueCodec[Array[String]] = JsonCodecMaker.make"
case ArrayType.ZioChunk =>
" given JsonValueCodec[zio.Chunk[String]] = JsonCodecMaker.make"
)
case _ => ""
).mkString("\n")
)
List(path.toFile())
Expand Down Expand Up @@ -236,7 +254,8 @@ def generateBySpec(
pkg = schemasPkg,
jsonCodec = config.jsonCodec,
hasProps = p => specs.hasProps(p),
arrType = config.arrayType
arrType = config.arrayType,
commonCodecsPkg = commonCodecsPkg
)
else
// create a type alias for objects without properties
Expand Down Expand Up @@ -404,7 +423,8 @@ def schemasCode(
pkg: String,
jsonCodec: JsonCodec,
hasProps: SchemaPath => Boolean,
arrType: ArrayType
arrType: ArrayType,
commonCodecsPkg: String
): String = {
def enums =
schema.properties.collect:
Expand Down Expand Up @@ -463,8 +483,9 @@ def schemasCode(
jsonCodec match {
case JsonCodec.ZioJson => "import zio.json.*"
case _: JsonCodec.Jsoniter =>
"""|import com.github.plokhotnyuk.jsoniter_scala.core.*
|import com.github.plokhotnyuk.jsoniter_scala.macros.*""".stripMargin
s"""|import com.github.plokhotnyuk.jsoniter_scala.core.*
|import com.github.plokhotnyuk.jsoniter_scala.macros.*
|import ${commonCodecsPkg}.given""".stripMargin
},
toSchemaClass(schema)
).mkString("\n")
Expand Down
Loading
Loading