https://github.com/webrpc/gen-kotlin
webrpc Kotlin client generator
https://github.com/webrpc/gen-kotlin
Last synced: 9 months ago
JSON representation
webrpc Kotlin client generator
- Host: GitHub
- URL: https://github.com/webrpc/gen-kotlin
- Owner: webrpc
- License: mit
- Created: 2023-08-06T22:57:34.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2024-04-04T14:43:39.000Z (about 2 years ago)
- Last Synced: 2025-01-01T23:14:27.360Z (over 1 year ago)
- Language: Kotlin
- Homepage:
- Size: 83 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# gen-kotlin
This repo contains the templates used by the `webrpc-gen` cli to code-generate
webrpc Kotlin client code.
This generator, from a webrpc schema/design file will code-generate:
1. Client -- a Kotlin client (via Ktor and Moshi) to speak to a webrpc server using the
provided schema. This client is compatible with any webrpc server language (ie. Go, nodejs, etc.).
## Dependencies
In order to support communication with server, dependencies to few libraries must be provided.
This is a dependency of the generated code, so you must add it to your project.
Add this to `build.gradle.kts`:
```kotlin
val coroutinesVersion = "1.7.3"
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion")
val moshiVersion = "1.15.0"
implementation("com.squareup.moshi:moshi-kotlin:$moshiVersion")
implementation("com.squareup.moshi:moshi-kotlin-codegen:$moshiVersion")
implementation("com.squareup.moshi:moshi-adapters:$moshiVersion")
val ktorVersion = "2.3.7"
implementation("io.ktor:ktor-client-core:$ktorVersion")
implementation("io.ktor:ktor-client-logging:$ktorVersion")
implementation("io.ktor:ktor-client-cio-jvm:$ktorVersion")
// implementation("ch.qos.logback:logback-classic:1.4.14") // Optional for logging
```
## Usage
```
webrpc-gen -schema=example.ridl -target=kotlin -client -out=./example.gen.kt
```
or
```
webrpc-gen -schema=example.ridl -target=github.com/webrpc/gen-kotlin@v0.14.0 -client -out=./example.gen.kt
```
or
```
webrpc-gen -schema=example.ridl -target=./local-templates-on-disk -client -out=./example.gen.kt
```
As you can see, the `-target` supports default `kotlin`, any git URI, or a local folder :)
### Set custom template variables
Change any of the following values by passing `-option="Value"` CLI flag to `webrpc-gen`.
| webrpc-gen -option | Description | Default value |
|---------------------------------|----------------------------|----------------------------|
| `-client` | generate client code | unset (`false`) |
| `-packageName=%package name%` | define package name | `io.webrpc.client` |
## LICENSE
[MIT LICENSE](./LICENSE)