Kotlin SDK
This is the README that tungsten generates for the Kotlin target, shown for a small example API (Swagger's Petstore). Names change with your API; the structure does not.
These recorded examples retain their original generator and runtime versions. Their installation snippets name example generated packages; they are not a current registry installation recipe. See runtime distribution for the verified stable 0.1.2 package versions and matching source routes for the unreleased 0.1.3 candidate.
Generated by tungsten 0.1.3. Kotlin/JVM, JVM 17 or later; the runtimes are io.github.pboachie.tungsten:tungsten-runtime-kotlin:0.1.3 (the Kotlin layer) and io.github.pboachie.tungsten:tungsten-runtime:0.1.3 (the Java runtime, no further dependencies).
dependencies {
implementation("com.example:openapi-sdk:0.1.0")
}
Usage
import com.example.openapi.OpenapiClient
import io.github.pboachie.tungsten.runtime.*
import io.github.pboachie.tungsten.runtime.kotlin.*
val client = OpenapiClient(
ClientOptions.builder()
.build(),
)
client.pets.list()
.onError { System.err.println(it.toJson()) } // the error envelope
.fold({ value -> println(value) }, { error -> println(error.category()) })
Every call returns the runtime's Result: Result.Ok with the typed value and the response metadata, or Result.Err with the error envelope (Diagnostic: category, remediation, retryable, ...). Nothing throws for API or transport failures; getOrThrow(), fold and onError are the Kotlin layer's extensions.
- Request classes are data classes with named, defaulted parameters: members that are null on the wire are
Patch<T>(Patch.Unset,Patch.Null,Patch.of(value)), every other member isT?. - Destructive and irreversible operations need
CallOptions.builder().confirm(...): a token from the operation'spreview...function, orConfirm.YESfor destructive ones. - Mutations with a caller-owned idempotency key take
idempotencyKey(...); reuse it on every retry. - Paginated operations have a
...Pagesfunction (aSequenceof page results, fetched as it advances;itemsOrThrow()flattens it into the items), streaming ones a...Streamfunction (anEventStream: iterate it or callevents(), or useon,collect,reduce,first;cancelandclose, oruse { }). client.dispatch()runs operations by id with JSON arguments;com.example.openapi.Opsholds the operation descriptors.
Files under src/main/kotlin/com/example/openapi/custom/ are yours: tungsten creates the folder once and never overwrites it.