Skip to content

Commit 2758e9e

Browse files
authored
add resource method description as comment, update dependencies (#18)
1 parent 0ef68ef commit 2758e9e

File tree

9 files changed

+37
-35
lines changed

9 files changed

+37
-35
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
test:
1212
runs-on: ubuntu-latest
1313
steps:
14-
- uses: actions/checkout@v2
14+
- uses: actions/checkout@v5
1515
- uses: coursier/cache-action@v6
1616
- uses: VirtusLab/scala-cli-setup@main
1717
with:
@@ -27,7 +27,7 @@ jobs:
2727
needs: [test]
2828
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/master')
2929
steps:
30-
- uses: actions/checkout@v2
30+
- uses: actions/checkout@v5
3131
- uses: coursier/cache-action@v6
3232
- uses: VirtusLab/scala-cli-setup@main
3333
with:
@@ -53,4 +53,4 @@ jobs:
5353
env:
5454
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
5555
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
56-
run: sbt publishSigned sonatypeCentralRelease
56+
run: sbt publishSigned sonaRelease

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ metals.sbt
99
.scala-build
1010
example/out
1111
.env
12-
test-local
12+
test-local
13+
out

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ The generator can be used with any tool that can perform system calls to a comma
2424
See example under [example/generate.scala](./example/generate.scala).
2525

2626
```scala
27-
//> using scala 3.7.1
28-
//> using dep dev.rolang::gcp-codegen::0.0.7
27+
//> using scala 3.7.3
28+
//> using dep dev.rolang::gcp-codegen::0.0.8
2929

3030
import gcp.codegen.*, java.nio.file.*, GeneratorConfig.*
3131

3232
@main def run =
3333
val files = Task(
34-
specsInput = SpecsInput.FilePath(Path.of("pubsub_v1.json")),
34+
specsInput = SpecsInput.StdIn,
3535
config = GeneratorConfig(
3636
outDir = Path.of("out"),
3737
outPkg = "example.pubsub.v1",
@@ -45,7 +45,7 @@ import gcp.codegen.*, java.nio.file.*, GeneratorConfig.*
4545
```
4646
Run example:
4747
```shell
48-
cd example && scala generate.scala && scala fmt ./out
48+
cat example/pubsub_v1.json | scala example/generate.scala
4949
```
5050
See output in `example/out`.
5151

build.sbt

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ ThisBuild / description := "Google Cloud client code generator"
22
ThisBuild / organization := "dev.rolang"
33
ThisBuild / licenses := Seq(License.MIT)
44
ThisBuild / homepage := Some(url("https://github.com/rolang/google-rest-api-codegen"))
5-
ThisBuild / scalaVersion := "3.7.1"
5+
ThisBuild / scalaVersion := "3.7.3"
66
ThisBuild / version ~= { v => if (v.contains('+')) s"${v.replace('+', '-')}-SNAPSHOT" else v }
77
ThisBuild / versionScheme := Some("early-semver")
88
ThisBuild / scmInfo := Some(
@@ -19,15 +19,18 @@ ThisBuild / developers := List(
1919
url = url("https://rolang.dev")
2020
)
2121
)
22-
ThisBuild / sonatypeCredentialHost := xerial.sbt.Sonatype.sonatypeCentralHost
2322

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

2928
lazy val publishSettings = List(
30-
publishTo := sonatypePublishToBundle.value
29+
publishTo := {
30+
val centralSnapshots = "https://central.sonatype.com/repository/maven-snapshots/"
31+
if (isSnapshot.value) Some("central-snapshots" at centralSnapshots)
32+
else localStaging.value
33+
}
3134
)
3235

3336
lazy val noPublish = Seq(
@@ -37,15 +40,15 @@ lazy val noPublish = Seq(
3740
publish / skip := true
3841
)
3942

40-
lazy val sttpClient4Version = "4.0.9"
43+
lazy val sttpClient4Version = "4.0.11"
4144

42-
lazy val zioVersion = "2.1.16"
45+
lazy val zioVersion = "2.1.21"
4346

44-
lazy val zioJsonVersion = "0.7.39"
47+
lazy val zioJsonVersion = "0.7.44"
4548

46-
lazy val jsoniterVersion = "2.33.2"
49+
lazy val jsoniterVersion = "2.38.2"
4750

48-
lazy val munitVersion = "1.0.2"
51+
lazy val munitVersion = "1.2.0"
4952

5053
addCommandAlias("fmt", "all scalafmtSbt scalafmt test:scalafmt")
5154

example/generate.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
//> using scala 3.7.0
2-
//> using dep dev.rolang::gcp-codegen::0.0.5
1+
//> using scala 3.7.3
2+
//> using dep dev.rolang::gcp-codegen::0.0.8
33

44
import gcp.codegen.*, java.nio.file.*, GeneratorConfig.*
55

66
@main def run =
77
val files = Task(
8-
specsInput = SpecsInput.FilePath(Path.of("pubsub_v1.json")),
8+
specsInput = SpecsInput.StdIn,
99
config = GeneratorConfig(
1010
outDir = Path.of("out"),
1111
outPkg = "example.pubsub.v1",
1212
httpSource = HttpSource.Sttp4,
1313
jsonCodec = JsonCodec.Jsoniter,
14-
dialect = Dialect.Scala3,
1514
arrayType = ArrayType.List,
1615
preprocess = specs => specs
1716
)

modules/cli/src/main/scala/cli.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// for test runs using scala-cli
22
//> using jvm system
3-
//> using scala 3.7.1
3+
//> using scala 3.7.3
44
//> using file ../../../../core/shared/src/main/scala/codegen.scala
5-
//> using dep com.lihaoyi::upickle:4.2.1
5+
//> using dep com.lihaoyi::upickle:4.3.2
66

77
package gcp.codegen.cli
88

modules/core/shared/src/main/scala/codegen.scala

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def generateBySpec(
165165
| try {
166166
| Right(readFromArray[T](bytes))
167167
| } catch {
168-
| case e: Exception =>
168+
| case e: JsonReaderException =>
169169
| Left(DeserializationException(String(bytes, java.nio.charset.StandardCharsets.UTF_8), e, metadata))
170170
| }
171171
| else Left(UnexpectedStatusCode(String(bytes, java.nio.charset.StandardCharsets.UTF_8), metadata))
@@ -325,10 +325,12 @@ def resourceCode(
325325

326326
val (requiredParams, optParams) = method.scalaParameters.partition(_._2.required)
327327
def params(indent: String) =
328-
requiredParams.map((n, t) => s"${toComment(t.description)}$indent$n: ${t.scalaType(arrType)}") :::
328+
requiredParams.map((n, t) => s"${toComment(t.description, indent)}$indent$n: ${t.scalaType(arrType)}") :::
329329
req.toList.map(r => s"${indent}request: ${r.scalaType(arrType)}") :::
330330
uploadProtocol.toList.map((typ, default) => s"${indent}uploadProtocol: $typ = \"$default\"") :::
331-
optParams.map((n, t) => s"${toComment(t.description)}$indent$n: ${t.scalaType(arrType)} = None") :::
331+
optParams.map((n, t) =>
332+
s"${toComment(t.description, indent)}$indent$n: ${t.scalaType(arrType)} = None"
333+
) :::
332334
List(
333335
s"${indent}endpointUrl: Uri = $rootPkg.baseUrl",
334336
s"${indent}commonQueryParams: QueryParameters = " + ((
@@ -385,7 +387,8 @@ def resourceCode(
385387
)
386388
case _ => (responseType("String"), ".response(asEmptyResponse)")
387389

388-
s"""| def ${toScalaName(k)}(\n${params(indent = " ").mkString(",\n")}\n ): $resType = {$queryParams
390+
s"""|${toComment(method.description)} def ${toScalaName(k)}(\n${params(indent = " ")
391+
.mkString(",\n")}\n ): $resType = {$queryParams
389392
| $setReqUri
390393
| resourceRequest.${method.httpMethod.toLowerCase()}(requestUri.addParams(params))$body$mapResponse
391394
| }""".stripMargin
@@ -529,6 +532,7 @@ case class MediaUpload(protocols: Map[String, MediaUploadProtocol], accept: List
529532

530533
case class Method(
531534
httpMethod: String,
535+
description: Option[String],
532536
path: String,
533537
flatPath: Option[FlatPath],
534538
parameters: Map[String, Parameter],
@@ -589,6 +593,7 @@ object Method:
589593
given Reader[Method] = reader[ujson.Obj].map { o =>
590594
Method(
591595
httpMethod = o("httpMethod").str,
596+
description = o.value.get("description").map(_.str),
592597
path = o("path").str,
593598
flatPath = o.value
594599
.get("flatPath")

project/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=1.10.11
1+
sbt.version=1.11.6

project/plugins.sbt

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
1-
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.5.7")
1+
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.5.8")
22

33
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2")
44

55
addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "1.3.2")
66

7-
addSbtPlugin("com.github.sbt" % "sbt-dynver" % "5.0.1")
8-
9-
addSbtPlugin("org.typelevel" % "sbt-tpolecat" % "0.5.2")
10-
11-
addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.3.0")
12-
13-
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.12.2")
7+
addSbtPlugin("com.github.sbt" % "sbt-dynver" % "5.1.1")

0 commit comments

Comments
 (0)