Generates client code from Google's disovery document. Currently generates code for Scala 3.
See example under example/generate.scala.
//> using scala 3.6.2
//> using dep dev.rolang::gcp-codegen::0.0.1
import gcp.codegen.*, java.nio.file.*, GeneratorConfig.*
@main def run =
val files = Task(
specsInput = SpecsInput.FilePath(Path.of("pubsub_v1.json")),
config = GeneratorConfig(
outDir = Path.of("out"),
resourcesPkg = "example.pubsub.v1.resource",
schemasPkg = "example.pubsub.v1.schemas",
httpSource = HttpSource.Sttp4,
jsonCodec = JsonCodec.Jsoniter,
dialect = Dialect.Scala3,
arrayType = ArrayType.List,
preprocess = specs => specs
)
).runAwait()
println(s"Generated ${files.length} files")
Run example:
cd example && scala generate.scala
See output in example/out
.
Configuration | Description | Options | Default |
---|---|---|---|
--out-dir | Ouput directory | ||
--specs | Can be stdin or a path to the JSON file. |
||
--resources-pkg | Target package for generated resources | ||
--schemas-pkg | Target package for generated schemas | ||
--http-source | Generated http source. | Sttp4, Sttp3 | |
--json-codec | Generated JSON codec | Jsoniter, ZioJson | |
--array-type | Collection type for JSON arrays | List , Vector , Array , ZioChunk |
List |
--include-resources | Optional resource filter. |
Command line binaries are not published (not yet).
A command line binary can be built from the source via sbt buildCliBinary
.
The output directory is modules/cli/target/bin
.
E.g. on Linux the output file will be like modules/cli/target/bin/gcp-codegen-x86_64-linux
.
curl 'https://pubsub.googleapis.com/$discovery/rest?version=v1' > pubsub_v1.json
# the path to the executable may be different
./modules/cli/target/bin/gcp-codegen-x86_64-linux \
--out-dir=src/scala/main/generated \
--specs=./pubsub_v1.json \
--resources-pkg=gcp.pubsub.v1.resources \
--schemas-pkg=gcp.pubsub.v1.schemas \
--http-source=sttp4 \
--json-codec=jsoniter \
--include-resources='projects.*,!projects.snapshots' # optional filters
Generate, compile and run tests for generated code
sbt buildCliBinary test