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
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -53,4 +53,4 @@ jobs:
env:
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
run: sbt publishSigned sonatypeCentralRelease
run: sbt publishSigned sonaRelease
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ metals.sbt
.scala-build
example/out
.env
test-local
test-local
out
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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`.

Expand Down
19 changes: 11 additions & 8 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.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(
Expand All @@ -19,15 +19,18 @@ ThisBuild / developers := List(
url = url("https://rolang.dev")
)
)
ThisBuild / sonatypeCredentialHost := xerial.sbt.Sonatype.sonatypeCentralHost

lazy val testSettings = Seq(
Compile / scalacOptions ++= Seq("-Xmax-inlines:64"),
scalacOptions -= "-Xfatal-warnings"
)

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(
Expand All @@ -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")

Expand Down
7 changes: 3 additions & 4 deletions example/generate.scala
Original file line number Diff line number Diff line change
@@ -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
)
Expand Down
4 changes: 2 additions & 2 deletions modules/cli/src/main/scala/cli.scala
Original file line number Diff line number Diff line change
@@ -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

Expand Down
13 changes: 9 additions & 4 deletions modules/core/shared/src/main/scala/codegen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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 = " + ((
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.10.11
sbt.version=1.11.6
10 changes: 2 additions & 8 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -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")