Skip to content

Commit de42115

Browse files
committed
Add basic Kotlin template
1 parent 24ee24f commit de42115

File tree

4 files changed

+40
-3
lines changed

4 files changed

+40
-3
lines changed

src/api.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl Api {
107107

108108
for (name, resource) in self.resources {
109109
let basename = match tpl_file_ext {
110-
"cs" | "java" | "kotlin" => name.to_upper_camel_case(),
110+
"cs" | "java" | "kt" => name.to_upper_camel_case(),
111111
_ => name.to_snake_case(),
112112
};
113113

src/template.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub(crate) fn env() -> Result<minijinja::Environment<'static>, minijinja::Error>
3131
kwargs.assert_all_used()?;
3232

3333
let prefix = match &*style {
34-
"javascript" | "js" | "ts" | "typescript" => {
34+
"java" | "kotlin" | "javascript" | "js" | "ts" | "typescript" => {
3535
if !s.contains("\n") {
3636
return Ok(format!("/** {s} */"));
3737
}

src/types.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ impl FieldType {
106106
fn to_kotlin_typename(&self) -> Cow<'_, str> {
107107
match self {
108108
Self::Bool => "Boolean".into(),
109-
Self::UInt64 => "Long".into(),
109+
// FIXME: Should be Long..
110+
Self::UInt64 => "Int".into(),
110111
Self::String => "String".into(),
111112
Self::DateTime => "OffsetDateTime".into(),
112113
Self::Set(field_type) => format!("List<{}>", field_type.to_kotlin_typename()).into(),
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// this file is @generated
2+
{% set resource_type_name = resource.name | to_upper_camel_case -%}
3+
{% set api_type_name %}{{ resource_type_name }}Api{% endset -%}
4+
5+
package com.svix.kotlin
6+
7+
import com.svix.kotlin.exceptions.ApiException
8+
import com.svix.kotlin.internal.apis.{{ api_type_name }}
9+
{% for c in referenced_components -%}
10+
import com.svix.kotlin.models.{{ c | to_upper_camel_case }}
11+
{% endfor -%}
12+
13+
{% for op in resource.operations -%}
14+
{% if op.query_params | length > 0 -%}
15+
class {{ resource_type_name }}{{ op.name | to_upper_camel_case }}Options {
16+
{%- for p in op.query_params %}
17+
{% set field_ty = p.type.to_kotlin() -%}
18+
{% if not p.required %}{% set field_ty %}{{ field_ty }}?{% endset %}{% endif -%}
19+
var {{ p.name | to_lower_camel_case }}: {{ field_ty -}}
20+
{% if not p.required %} = null
21+
{%- elif p.default is defined %} = {{ p.default }}
22+
{%- endif -%}
23+
{% endfor %}
24+
25+
{% for p in op.query_params -%}
26+
{% set field_name = p.name | to_lower_camel_case %}
27+
{{ p.description | to_doc_comment(style="kotlin") }}
28+
{% set field_ty = p.type.to_kotlin() -%}
29+
fun {{ field_name }}({{ field_name }}: {{ field_ty }}) = apply {
30+
this.{{ field_name }} = {{ field_name }}
31+
}
32+
{% endfor -%}
33+
}
34+
35+
{% endif -%}
36+
{% endfor -%}

0 commit comments

Comments
 (0)