Skip to content

Commit 71a9565

Browse files
authored
kotlin: Add support for sub-resources (#1839)
Part of svix/monorepo-private#10043.
2 parents 7e84604 + 92d58e9 commit 71a9565

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

codegen.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ output_dir = "go/models"
138138

139139
[kotlin]
140140
extra_shell_commands = [
141-
"rm kotlin/lib/src/main/kotlin/{Ingest,OperationalWebhook}.kt",
141+
"rm kotlin/lib/src/main/kotlin/Ingest.kt",
142142
]
143143
template_dir = "kotlin/templates"
144144
[[kotlin.task]]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// this file is @generated
2+
package com.svix.kotlin
3+
4+
class OperationalWebhook(private val client: SvixHttpClient) {
5+
val endpoint: OperationalWebhookEndpoint = OperationalWebhookEndpoint(client)
6+
}

kotlin/lib/src/main/kotlin/Svix.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import SvixOptions
44
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
55

66
class Svix(token: String, options: SvixOptions = SvixOptions()) {
7-
87
val application: Application
98
val authentication: Authentication
109
val endpoint: Endpoint
@@ -13,6 +12,7 @@ class Svix(token: String, options: SvixOptions = SvixOptions()) {
1312
val message: Message
1413
val messageAttempt: MessageAttempt
1514
val statistics: Statistics
15+
val operationalWebhook: OperationalWebhook
1616
val operationalWebhookEndpoint: OperationalWebhookEndpoint
1717

1818
init {
@@ -38,6 +38,7 @@ class Svix(token: String, options: SvixOptions = SvixOptions()) {
3838
message = Message(httpClient)
3939
messageAttempt = MessageAttempt(httpClient)
4040
statistics = Statistics(httpClient)
41+
operationalWebhook = OperationalWebhook(httpClient)
4142
operationalWebhookEndpoint = OperationalWebhookEndpoint(httpClient)
4243
}
4344
}

kotlin/templates/api_resource.kt.jinja

+6
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ data class {{ resource_type_name }}{{ op.name | to_upper_camel_case }}Options(
4141

4242

4343
class {{ resource_type_name }}(private val client: SvixHttpClient) {
44+
{% for name, sub in resource.subresources | items -%}
45+
{% set sub_type_name = sub.name | to_upper_camel_case -%}
46+
val {{ name | to_lower_camel_case }}: {{ sub_type_name }} = {{ sub_type_name }}(client)
47+
48+
{% endfor -%}
49+
4450
{% for op in resource.operations -%}
4551
{% set res_type = op.response_body_schema_name | replace("_", "") -%}
4652
{% set has_query_params = op.query_params | length > 0 -%}

0 commit comments

Comments
 (0)