Skip to content

Commit b0064bf

Browse files
committed
docs: update java sdk documents
Signed-off-by: peefy <[email protected]>
1 parent c486b7d commit b0064bf

File tree

13 files changed

+111
-34
lines changed

13 files changed

+111
-34
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ This way you'll be able to import the above dependency to use the SDK.
3030
<dependency>
3131
<groupId>com.kcl</groupId>
3232
<artifactId>kcl-lib</artifactId>
33-
<version>0.8.5</version>
33+
<version>0.8.6</version>
3434
</dependency>
3535
```
3636

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

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,45 @@ sidebar_position: 5
66

77
## 添加依赖
88

9-
```shell
10-
npm install kcl-lib
11-
```
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。
1210

1311
### Maven
1412

15-
## 快速开始
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+
```
1626

17-
```typescript
18-
import { execProgram, ExecProgramArgs } from "kcl-lib";
27+
通过这种方式,您将能够导入上述依赖以使用 Java SDK。
1928

20-
function main() {
21-
const result = execProgram(new ExecProgramArgs(["path/to/kcl.k"]));
22-
console.log(result.yamlResult);
23-
}
29+
```xml
30+
<dependency>
31+
<groupId>com.kcl</groupId>
32+
<artifactId>kcl-lib</artifactId>
33+
<version>0.8.6</version>
34+
</dependency>
35+
```
36+
37+
## 快速开始
2438

25-
main();
39+
import com.kcl.api.API;
40+
import com.kcl.api.Spec.ExecProgram_Args;
41+
import com.kcl.api.Spec.ExecProgram_Result;
42+
public class ExecProgramTest {
43+
public static void main(String[] args) throws Exception {
44+
API api = new API();
45+
ExecProgram_Result result = api
46+
.execProgram(ExecProgram_Args.newBuilder().addKFilenameList("path/to/kcl.k").build());
47+
System.out.println(result.getYamlResult());
48+
}
49+
}
2650
```

i18n/zh-CN/docusaurus-plugin-content-docs/version-0.8/reference/xlang-api/java-api.md

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,45 @@ sidebar_position: 5
66

77
## 添加依赖
88

9-
```shell
10-
npm install kcl-lib
11-
```
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。
1210

1311
### Maven
1412

15-
## 快速开始
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+
```
1626

17-
```typescript
18-
import { execProgram, ExecProgramArgs } from "kcl-lib";
27+
通过这种方式,您将能够导入上述依赖以使用 Java SDK。
1928

20-
function main() {
21-
const result = execProgram(new ExecProgramArgs(["path/to/kcl.k"]));
22-
console.log(result.yamlResult);
23-
}
29+
```xml
30+
<dependency>
31+
<groupId>com.kcl</groupId>
32+
<artifactId>kcl-lib</artifactId>
33+
<version>0.8.6</version>
34+
</dependency>
35+
```
36+
37+
## 快速开始
2438

25-
main();
39+
import com.kcl.api.API;
40+
import com.kcl.api.Spec.ExecProgram_Args;
41+
import com.kcl.api.Spec.ExecProgram_Result;
42+
public class ExecProgramTest {
43+
public static void main(String[] args) throws Exception {
44+
API api = new API();
45+
ExecProgram_Result result = api
46+
.execProgram(ExecProgram_Args.newBuilder().addKFilenameList("path/to/kcl.k").build());
47+
System.out.println(result.getYamlResult());
48+
}
49+
}
2650
```

i18n/zh-CN/docusaurus-plugin-content-docs/version-0.8/user_docs/guides/working-with-k8s/3-mutate-manifests/1-kubectl-kcl-plugin.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,11 @@ Ingress should be https. The `kubernetes.io/ingress.allow-http: "false"` annotat
195195

196196
Here's what you can do in the KCL code:
197197

198-
- Read resources from `option("resource_list")`. The `option("resource_list")` complies with the [KRM Functions Specification](https://kpt.dev/book/05-developing-functions/01-functions-specification). You can read the input resources from `option("resource_list")["items"]` and the `functionConfig` from `option("resource_list")["functionConfig"]`.
198+
- Read resources from `option("items")`. The `option("items")` complies with the [KRM Functions Specification](https://kpt.dev/book/05-developing-functions/01-functions-specification).
199199
- Return a KRM list for output resources.
200200
- Return an error using `assert {condition}, {error_message}`.
201+
- Read the PATH variables. e.g. `option("PATH")`.
202+
- Read the environment variables. e.g. `option("env")`.
201203

202204
## More Resources
203205

versioned_docs/version-0.8/reference/xlang-api/java-api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ This way you'll be able to import the above dependency to use the SDK.
3030
<dependency>
3131
<groupId>com.kcl</groupId>
3232
<artifactId>kcl-lib</artifactId>
33-
<version>0.8.5</version>
33+
<version>0.8.6</version>
3434
</dependency>
3535
```
3636

versioned_docs/version-0.8/user_docs/guides/working-with-k8s/3-mutate-manifests/1-kubectl-kcl-plugin.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,11 @@ Ingress should be https. The `kubernetes.io/ingress.allow-http: "false"` annotat
195195

196196
Here's what you can do in the KCL code:
197197

198-
- Read resources from `option("resource_list")`. The `option("resource_list")` complies with the [KRM Functions Specification](https://kpt.dev/book/05-developing-functions/01-functions-specification). You can read the input resources from `option("resource_list")["items"]` and the `functionConfig` from `option("resource_list")["functionConfig"]`.
198+
- Read resources from `option("items")`. The `option("items")` complies with the [KRM Functions Specification](https://kpt.dev/book/05-developing-functions/01-functions-specification).
199199
- Return a KRM list for output resources.
200200
- Return an error using `assert {condition}, {error_message}`.
201+
- Read the PATH variables. e.g. `option("PATH")`.
202+
- Read the environment variables. e.g. `option("env")`.
201203

202204
## More Resources
203205

versioned_docs/version-0.8/user_docs/guides/working-with-k8s/3-mutate-manifests/2-helm-kcl-plugin.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,11 @@ spec:
9191
9292
Here's what you can do in the KCL code:
9393
94-
- Read resources from `option("resource_list")`. The `option("resource_list")` complies with the [KRM Functions Specification](https://kpt.dev/book/05-developing-functions/01-functions-specification). You can read the input resources from `option("resource_list")["items"]` and the `functionConfig` from `option("resource_list")["functionConfig"]`.
94+
- Read resources from `option("items")`. The `option("items")` complies with the [KRM Functions Specification](https://kpt.dev/book/05-developing-functions/01-functions-specification).
9595
- Return a KRM list for output resources.
9696
- Return an error using `assert {condition}, {error_message}`.
97+
- Read the PATH variables. e.g. `option("PATH")`.
98+
- Read the environment variables. e.g. `option("env")`.
9799

98100
## More Documents and Examples
99101

versioned_docs/version-0.8/user_docs/guides/working-with-k8s/3-mutate-manifests/3-kustomize-kcl-plugin.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,11 @@ spec:
9696
9797
Here's what you can do in the KCL code:
9898
99-
- Read resources from `option("resource_list")`. The `option("resource_list")` complies with the [KRM Functions Specification](https://kpt.dev/book/05-developing-functions/01-functions-specification). You can read the input resources from `option("resource_list")["items"]` and the `functionConfig` from `option("resource_list")["functionConfig"]`.
99+
- Read resources from `option("items")`. The `option("items")` complies with the [KRM Functions Specification](https://kpt.dev/book/05-developing-functions/01-functions-specification).
100100
- Return a KRM list for output resources.
101101
- Return an error using `assert {condition}, {error_message}`.
102+
- Read the PATH variables. e.g. `option("PATH")`.
103+
- Read the environment variables. e.g. `option("env")`.
102104

103105
## More Documents and Examples
104106

versioned_docs/version-0.8/user_docs/guides/working-with-k8s/3-mutate-manifests/4-kpt-kcl-sdk.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,11 @@ It can be seen that we have indeed added the annotation `managed-by=kpt`.
8787

8888
Here's what you can do in the KCL code:
8989

90-
- Read resources from `option("resource_list")`. The `option("resource_list")` complies with the [KRM Functions Specification](https://kpt.dev/book/05-developing-functions/01-functions-specification). You can read the input resources from `option("resource_list")["items"]` and the `functionConfig` from `option("resource_list")["functionConfig"]`.
90+
- Read resources from `option("items")`. The `option("items")` complies with the [KRM Functions Specification](https://kpt.dev/book/05-developing-functions/01-functions-specification).
9191
- Return a KRM list for output resources.
9292
- Return an error using `assert {condition}, {error_message}`.
93+
- Read the PATH variables. e.g. `option("PATH")`.
94+
- Read the environment variables. e.g. `option("env")`.
9395

9496
## More Documents and Examples
9597

versioned_docs/version-0.8/user_docs/guides/working-with-k8s/3-mutate-manifests/5-helmfile-kcl-plugin.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,11 @@ Adding repo prometheus-community https://prometheus-community.github.io/helm-cha
104104

105105
Here's what you can do in the KCL code:
106106

107-
- Read resources from `option("resource_list")`. The `option("resource_list")` complies with the [KRM Functions Specification](https://kpt.dev/book/05-developing-functions/01-functions-specification). You can read the input resources from `option("resource_list")["items"]` and the `functionConfig` from `option("resource_list")["functionConfig"]`.
107+
- Read resources from `option("items")`. The `option("items")` complies with the [KRM Functions Specification](https://kpt.dev/book/05-developing-functions/01-functions-specification).
108108
- Return a KRM list for output resources.
109109
- Return an error using `assert {condition}, {error_message}`.
110+
- Read the PATH variables. e.g. `option("PATH")`.
111+
- Read the environment variables. e.g. `option("env")`.
110112

111113
## More Documents and Examples
112114

versioned_docs/version-0.8/user_docs/guides/working-with-k8s/3-mutate-manifests/6-kcl-operator.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,11 @@ The output is
8383

8484
Here's what you can do in the KCL code:
8585

86-
- Read resources from `option("resource_list")`. The `option("resource_list")` complies with the [KRM Functions Specification](https://kpt.dev/book/05-developing-functions/01-functions-specification). You can read the input resources from `option("items")` and the params from `option("params")`.
86+
- Read resources from `option("items")`. The `option("items")` complies with the [KRM Functions Specification](https://kpt.dev/book/05-developing-functions/01-functions-specification).
8787
- Return a KRM list for output resources.
8888
- Return an error using `assert {condition}, {error_message}`.
89+
- Read the PATH variables. e.g. `option("PATH")`.
90+
- Read the environment variables. e.g. `option("env")`.
8991

9092
## More Documents and Examples
9193

versioned_docs/version-0.8/user_docs/guides/working-with-k8s/3-mutate-manifests/7-crossplane-kcl-function.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,18 +221,20 @@ spec:
221221
222222
Here's what you can do in the KCL script:
223223
224-
- Return an error using `assert {condition}, {error_message}`.
225224
- Read the `ObservedCompositeResource` from `option("params").oxr`.
226225
- Read the `ObservedComposedResources` from `option("params").ocds`.
227226
- Read the `DesiredCompositeResource` from `option("params").dxr`.
228227
- Read the `DesiredComposedResources` from `option("params").dcds`.
229-
- Read the environment variables. e.g. `option("PATH")` (**Not yet implemented**).
228+
- Read the function pipeline's context from `option("params").ctx`.
229+
- Return an error using `assert {condition}, {error_message}`.
230+
- Read the PATH variables. e.g. `option("PATH")`.
231+
- Read the environment variables. e.g. `option("env")`.
230232

231233
## Library
232234

233235
You can directly use [KCL standard libraries](https://kcl-lang.io/docs/reference/model/overview) such as `regex.match`, `math.log`.
234236

235237
## More Documents and Examples
236238

239+
- [Crossplane KCL](https://github.com/crossplane-contrib/function-kcl/)
237240
- [KRM KCL Spec](https://github.com/kcl-lang/krm-kcl)
238-
- [Crossplane KCL](https://github.com/crossplane-contrib/function-kcl/examples)

versioned_docs/version-0.8/user_docs/support/faq-kcl.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2586,3 +2586,16 @@ The command to validate the JSON data below gives the output `Validate success!`
25862586
```bash
25872587
kcl vet data.json schema.k
25882588
```
2589+
2590+
## 63. How can i extend an array's default value in a given schema?
2591+
2592+
We use the += operator to extend the default values in an array.
2593+
2594+
```python
2595+
schema MyApp:
2596+
args: [str] = ["default", "args"]
2597+
2598+
app = MyApp {
2599+
args += ["additional", "args"]
2600+
}
2601+
```

0 commit comments

Comments
 (0)