Skip to content

Commit 3c895c7

Browse files
committed
docs: update 0.10.0-alpha API documents
Signed-off-by: peefy <[email protected]>
1 parent e426ace commit 3c895c7

File tree

6 files changed

+170
-8
lines changed

6 files changed

+170
-8
lines changed

docs/reference/xlang-api/kotlin-api.md

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,35 @@ sidebar_position: 8
44

55
# Kotlin API
66

7-
The official [Kotlin KCL package](https://github.com/kcl-lang/lib/tree/main/kotlin) has not been released yet. Issues and PRs are welcome!
7+
## Installation
88

9-
Of course, you can use the KCL Java package to call the KCL API in Kotlin.
9+
Refer to [this](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-apache-maven-registry#authenticating-to-github-packages) to configure your Maven; set up your GitHub account and Token in the `settings.xml`.
10+
11+
### Maven
12+
13+
In your project's pom.xml, configure our repository as follows:
14+
15+
```xml
16+
<repositories>
17+
<repository>
18+
<id>github</id>
19+
<url>https://maven.pkg.github.com/kcl-lang/*</url>
20+
<snapshots>
21+
<enabled>true</enabled>
22+
</snapshots>
23+
</repository>
24+
</repositories>
25+
```
26+
27+
This way you'll be able to import the above dependency to use the SDK.
28+
29+
```xml
30+
<dependency>
31+
<groupId>com.kcl</groupId>
32+
<artifactId>kcl-lib-kotlin</artifactId>
33+
<version>0.10.0-alpha.2-SNAPSHOT</version>
34+
</dependency>
35+
```
1036

1137
## Quick Start
1238

@@ -18,3 +44,58 @@ val args = execProgramArgs { kFilenameList += "schema.k" }
1844
val api = API()
1945
val result = api.execProgram(args)
2046
```
47+
48+
## API Reference
49+
50+
### execProgram
51+
52+
Execute KCL file with arguments and return the JSON/YAML result.
53+
54+
<details><summary>Example</summary>
55+
<p>
56+
57+
The content of `schema.k` is
58+
59+
```python
60+
schema AppConfig:
61+
replicas: int
62+
63+
app: AppConfig {
64+
replicas: 2
65+
}
66+
```
67+
68+
Kotlin Code
69+
70+
```kotlin
71+
import com.kcl.api.API
72+
import com.kcl.api.execProgramArgs
73+
74+
val args = execProgramArgs { kFilenameList += "schema.k" }
75+
val api = API()
76+
val result = api.execProgram(args)
77+
```
78+
79+
</p>
80+
</details>
81+
82+
### validateCode
83+
84+
Validate code using schema and JSON/YAML data strings.
85+
86+
<details><summary>Example</summary>
87+
<p>
88+
89+
Kotlin Code
90+
91+
```kotlin
92+
val args = validateCodeArgs {
93+
code = "schema Person:\n" + " name: str\n" + " age: int\n" + " check:\n" + " 0 < age < 120\n"
94+
data = "{\"name\": \"Alice\", \"age\": 10}"
95+
}
96+
val apiInstance = API();
97+
val result = apiInstance.validateCode(args);
98+
```
99+
100+
</p>
101+
</details>

docs/reference/xlang-api/python-api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ assert list(result.symbols.values())[0].ty.schema_name == "AppConfig"
174174
</p>
175175
</details>
176176
177-
### list_variable
177+
### list_variables
178178
179179
list_variables provides users with the ability to parse KCL program and get all variables by specs.
180180

i18n/zh-CN/docusaurus-plugin-content-docs/current/reference/xlang-api/kotlin-api.md

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,35 @@ sidebar_position: 8
44

55
# Kotlin API
66

7-
[Kotlin KCL API](https://github.com/kcl-lang/lib/tree/main/kotlin) 正在开发当中,尚未正式发布。欢迎提交 Issues 或者 PRs 参与共建!
7+
## 添加依赖
88

9-
当然,您也可以在 Kotlin 中直接调用 KCL Java API。
9+
参考[此处](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-apache-maven-registry#authenticating-to-github-packages)来配置您的 Maven;在 settings.xml 中设置您的 GitHub 账户和 Token。
10+
11+
### Maven
12+
13+
在您项目的 pom.xml 中,按如下配置 Maven 仓库:
14+
15+
```xml
16+
<repositories>
17+
<repository>
18+
<id>github</id>
19+
<url>https://maven.pkg.github.com/kcl-lang/*</url>
20+
<snapshots>
21+
<enabled>true</enabled>
22+
</snapshots>
23+
</repository>
24+
</repositories>
25+
```
26+
27+
通过这种方式,您将能够导入上述依赖以使用 Kotlin SDK。
28+
29+
```xml
30+
<dependency>
31+
<groupId>com.kcl</groupId>
32+
<artifactId>kcl-lib-kotlin</artifactId>
33+
<version>0.10.0-alpha.2-SNAPSHOT</version>
34+
</dependency>
35+
```
1036

1137
## 快速开始
1238

@@ -18,3 +44,58 @@ val args = execProgramArgs { kFilenameList += "schema.k" }
1844
val api = API()
1945
val result = api.execProgram(args)
2046
```
47+
48+
## API Reference
49+
50+
### execProgram
51+
52+
Execute KCL file with arguments and return the JSON/YAML result.
53+
54+
<details><summary>Example</summary>
55+
<p>
56+
57+
The content of `schema.k` is
58+
59+
```python
60+
schema AppConfig:
61+
replicas: int
62+
63+
app: AppConfig {
64+
replicas: 2
65+
}
66+
```
67+
68+
Kotlin Code
69+
70+
```kotlin
71+
import com.kcl.api.API
72+
import com.kcl.api.execProgramArgs
73+
74+
val args = execProgramArgs { kFilenameList += "schema.k" }
75+
val api = API()
76+
val result = api.execProgram(args)
77+
```
78+
79+
</p>
80+
</details>
81+
82+
### validateCode
83+
84+
Validate code using schema and JSON/YAML data strings.
85+
86+
<details><summary>Example</summary>
87+
<p>
88+
89+
Kotlin Code
90+
91+
```kotlin
92+
val args = validateCodeArgs {
93+
code = "schema Person:\n" + " name: str\n" + " age: int\n" + " check:\n" + " 0 < age < 120\n"
94+
data = "{\"name\": \"Alice\", \"age\": 10}"
95+
}
96+
val apiInstance = API();
97+
val result = apiInstance.validateCode(args);
98+
```
99+
100+
</p>
101+
</details>

i18n/zh-CN/docusaurus-plugin-content-docs/current/reference/xlang-api/python-api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ assert list(result.symbols.values())[0].ty.schema_name == "AppConfig"
174174
</p>
175175
</details>
176176
177-
### list_variable
177+
### list_variables
178178
179179
list_variables provides users with the ability to parse KCL program and get all variables by specs.
180180

i18n/zh-CN/docusaurus-plugin-content-docs/version-0.9/reference/xlang-api/python-api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ assert list(result.symbols.values())[0].ty.schema_name == "AppConfig"
174174
</p>
175175
</details>
176176
177-
### list_variable
177+
### list_variables
178178
179179
list_variables provides users with the ability to parse KCL program and get all variables by specs.
180180

versioned_docs/version-0.9/reference/xlang-api/python-api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ assert list(result.symbols.values())[0].ty.schema_name == "AppConfig"
174174
</p>
175175
</details>
176176
177-
### list_variable
177+
### list_variables
178178
179179
list_variables provides users with the ability to parse KCL program and get all variables by specs.
180180

0 commit comments

Comments
 (0)