diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 34e86a4..9208c3f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,7 @@ jobs: test: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v5 - uses: coursier/cache-action@v6 - uses: VirtusLab/scala-cli-setup@main with: @@ -27,7 +27,7 @@ jobs: needs: [test] if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/master') steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v5 - uses: coursier/cache-action@v6 - uses: VirtusLab/scala-cli-setup@main with: @@ -53,4 +53,4 @@ jobs: env: SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} - run: sbt publishSigned sonatypeCentralRelease + run: sbt publishSigned sonaRelease diff --git a/.gitignore b/.gitignore index 0f6df78..18282cf 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,5 @@ metals.sbt .scala-build example/out .env -test-local \ No newline at end of file +test-local +out \ No newline at end of file diff --git a/README.md b/README.md index 3e0c201..e35cdc8 100644 --- a/README.md +++ b/README.md @@ -24,14 +24,14 @@ The generator can be used with any tool that can perform system calls to a comma See example under [example/generate.scala](./example/generate.scala). ```scala -//> using scala 3.7.1 -//> using dep dev.rolang::gcp-codegen::0.0.7 +//> using scala 3.7.3 +//> using dep dev.rolang::gcp-codegen::0.0.8 import gcp.codegen.*, java.nio.file.*, GeneratorConfig.* @main def run = val files = Task( - specsInput = SpecsInput.FilePath(Path.of("pubsub_v1.json")), + specsInput = SpecsInput.StdIn, config = GeneratorConfig( outDir = Path.of("out"), outPkg = "example.pubsub.v1", @@ -45,7 +45,7 @@ import gcp.codegen.*, java.nio.file.*, GeneratorConfig.* ``` Run example: ```shell -cd example && scala generate.scala && scala fmt ./out +cat example/pubsub_v1.json | scala example/generate.scala ``` See output in `example/out`. diff --git a/build.sbt b/build.sbt index 6905d93..421f240 100644 --- a/build.sbt +++ b/build.sbt @@ -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.7.1" +ThisBuild / scalaVersion := "3.7.3" ThisBuild / version ~= { v => if (v.contains('+')) s"${v.replace('+', '-')}-SNAPSHOT" else v } ThisBuild / versionScheme := Some("early-semver") ThisBuild / scmInfo := Some( @@ -19,7 +19,6 @@ ThisBuild / developers := List( url = url("https://rolang.dev") ) ) -ThisBuild / sonatypeCredentialHost := xerial.sbt.Sonatype.sonatypeCentralHost lazy val testSettings = Seq( Compile / scalacOptions ++= Seq("-Xmax-inlines:64"), @@ -27,7 +26,11 @@ lazy val testSettings = Seq( ) lazy val publishSettings = List( - publishTo := sonatypePublishToBundle.value + publishTo := { + val centralSnapshots = "https://central.sonatype.com/repository/maven-snapshots/" + if (isSnapshot.value) Some("central-snapshots" at centralSnapshots) + else localStaging.value + } ) lazy val noPublish = Seq( @@ -37,15 +40,15 @@ lazy val noPublish = Seq( publish / skip := true ) -lazy val sttpClient4Version = "4.0.9" +lazy val sttpClient4Version = "4.0.11" -lazy val zioVersion = "2.1.16" +lazy val zioVersion = "2.1.21" -lazy val zioJsonVersion = "0.7.39" +lazy val zioJsonVersion = "0.7.44" -lazy val jsoniterVersion = "2.33.2" +lazy val jsoniterVersion = "2.38.2" -lazy val munitVersion = "1.0.2" +lazy val munitVersion = "1.2.0" addCommandAlias("fmt", "all scalafmtSbt scalafmt test:scalafmt") diff --git a/example/generate.scala b/example/generate.scala index 07454f4..a139e8a 100644 --- a/example/generate.scala +++ b/example/generate.scala @@ -1,17 +1,16 @@ -//> using scala 3.7.0 -//> using dep dev.rolang::gcp-codegen::0.0.5 +//> using scala 3.7.3 +//> using dep dev.rolang::gcp-codegen::0.0.8 import gcp.codegen.*, java.nio.file.*, GeneratorConfig.* @main def run = val files = Task( - specsInput = SpecsInput.FilePath(Path.of("pubsub_v1.json")), + specsInput = SpecsInput.StdIn, config = GeneratorConfig( outDir = Path.of("out"), outPkg = "example.pubsub.v1", httpSource = HttpSource.Sttp4, jsonCodec = JsonCodec.Jsoniter, - dialect = Dialect.Scala3, arrayType = ArrayType.List, preprocess = specs => specs ) diff --git a/modules/cli/src/main/scala/cli.scala b/modules/cli/src/main/scala/cli.scala index 6196558..36c6f32 100644 --- a/modules/cli/src/main/scala/cli.scala +++ b/modules/cli/src/main/scala/cli.scala @@ -1,8 +1,8 @@ // for test runs using scala-cli //> using jvm system -//> using scala 3.7.1 +//> using scala 3.7.3 //> using file ../../../../core/shared/src/main/scala/codegen.scala -//> using dep com.lihaoyi::upickle:4.2.1 +//> using dep com.lihaoyi::upickle:4.3.2 package gcp.codegen.cli diff --git a/modules/core/shared/src/main/scala/codegen.scala b/modules/core/shared/src/main/scala/codegen.scala index 5ef3f9f..4fa8969 100644 --- a/modules/core/shared/src/main/scala/codegen.scala +++ b/modules/core/shared/src/main/scala/codegen.scala @@ -165,7 +165,7 @@ def generateBySpec( | try { | Right(readFromArray[T](bytes)) | } catch { - | case e: Exception => + | case e: JsonReaderException => | Left(DeserializationException(String(bytes, java.nio.charset.StandardCharsets.UTF_8), e, metadata)) | } | else Left(UnexpectedStatusCode(String(bytes, java.nio.charset.StandardCharsets.UTF_8), metadata)) @@ -325,10 +325,12 @@ def resourceCode( val (requiredParams, optParams) = method.scalaParameters.partition(_._2.required) def params(indent: String) = - requiredParams.map((n, t) => s"${toComment(t.description)}$indent$n: ${t.scalaType(arrType)}") ::: + requiredParams.map((n, t) => s"${toComment(t.description, indent)}$indent$n: ${t.scalaType(arrType)}") ::: req.toList.map(r => s"${indent}request: ${r.scalaType(arrType)}") ::: uploadProtocol.toList.map((typ, default) => s"${indent}uploadProtocol: $typ = \"$default\"") ::: - optParams.map((n, t) => s"${toComment(t.description)}$indent$n: ${t.scalaType(arrType)} = None") ::: + optParams.map((n, t) => + s"${toComment(t.description, indent)}$indent$n: ${t.scalaType(arrType)} = None" + ) ::: List( s"${indent}endpointUrl: Uri = $rootPkg.baseUrl", s"${indent}commonQueryParams: QueryParameters = " + (( @@ -385,7 +387,8 @@ def resourceCode( ) case _ => (responseType("String"), ".response(asEmptyResponse)") - s"""| def ${toScalaName(k)}(\n${params(indent = " ").mkString(",\n")}\n ): $resType = {$queryParams + s"""|${toComment(method.description)} def ${toScalaName(k)}(\n${params(indent = " ") + .mkString(",\n")}\n ): $resType = {$queryParams | $setReqUri | resourceRequest.${method.httpMethod.toLowerCase()}(requestUri.addParams(params))$body$mapResponse | }""".stripMargin @@ -529,6 +532,7 @@ case class MediaUpload(protocols: Map[String, MediaUploadProtocol], accept: List case class Method( httpMethod: String, + description: Option[String], path: String, flatPath: Option[FlatPath], parameters: Map[String, Parameter], @@ -589,6 +593,7 @@ object Method: given Reader[Method] = reader[ujson.Obj].map { o => Method( httpMethod = o("httpMethod").str, + description = o.value.get("description").map(_.str), path = o("path").str, flatPath = o.value .get("flatPath") diff --git a/project/build.properties b/project/build.properties index cc68b53..5e6884d 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.10.11 +sbt.version=1.11.6 diff --git a/project/plugins.sbt b/project/plugins.sbt index 8e42dc4..23dc177 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,13 +1,7 @@ -addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.5.7") +addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.5.8") addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2") addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "1.3.2") -addSbtPlugin("com.github.sbt" % "sbt-dynver" % "5.0.1") - -addSbtPlugin("org.typelevel" % "sbt-tpolecat" % "0.5.2") - -addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.3.0") - -addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.12.2") +addSbtPlugin("com.github.sbt" % "sbt-dynver" % "5.1.1")