+ +The content of `schema.k` is + +```python +schema AppConfig: + replicas: int + +app: AppConfig { + replicas: 2 +} +``` + +Java Code + +```java +import com.kcl.api.*; + +ExecProgram_Args args = ExecProgram_Args.newBuilder().addKFilenameList("schema.k").build(); +API apiInstance = new API(); +ExecProgram_Result result = apiInstance.execProgram(args); +``` + +
++ +The content of `schema.k` is + +```python +schema AppConfig: + replicas: int + +app: AppConfig { + replicas: 2 +} +``` + +Java Code + +```java +import com.kcl.api.*; +import com.kcl.ast.*; +import com.kcl.util.JsonUtil; + +API api = new API(); +ParseProgram_Result result = api.parseProgram( + ParseProgram_Args.newBuilder().addPaths("schema.k").build() +); +System.out.println(result.getAstJson()); +Program program = JsonUtil.deserializeProgram(result.getAstJson()); +``` + +
++ +The content of `schema.k` is + +```python +schema AppConfig: + replicas: int + +app: AppConfig { + replicas: 2 +} +``` + +Java Code + +```java +import com.kcl.api.*; + +ParseFile_Args args = ParseFile_Args.newBuilder().setPath("schema.k").build(); +API apiInstance = new API(); +ParseFile_Result result = apiInstance.parseFile(args); +``` + +
++ +The content of `schema.k` is + +```python +schema AppConfig: + replicas: int + +app: AppConfig { + replicas: 2 +} +``` + +Java Code + +```java +import com.kcl.api.*; +import com.kcl.ast.*; +import com.kcl.util.JsonUtil; + +API api = new API(); +ParseProgram_Result result = api.parseProgram( + ParseProgram_Args.newBuilder().addPaths("path/to/kcl.k").build() +); +System.out.println(result.getAstJson()); +Program program = JsonUtil.deserializeProgram(result.getAstJson()); +``` + +
++ +The content of `schema.k` is + +```python +schema AppConfig: + replicas: int + +app: AppConfig { + replicas: 2 +} +``` + +Java Code + +```python +import kcl_lib.api as api + +args = api.LoadPackage_Args( + parse_args=api.ParseProgram_Args(paths=["schema.k"]), resolve_ast=True +) +api = api.API() +result = api.load_package(args) +assert list(result.symbols.values())[0].ty.schema_name == "AppConfig" +``` + +
++ +The content of `schema.k` is + +```python +schema AppConfig: + replicas: int + +app: AppConfig { + replicas: 2 +} +``` + +Java Code + +```java +import com.kcl.api.*; + +API api = new API(); +ListVariables_Result result = api.listVariables( + ListVariables_Args.newBuilder().setResolveAst(true).setParseArgs( + ParseProgram_Args.newBuilder().addPaths("/path/to/kcl.k").build()) + .build()); +result.getSymbolsMap().values().forEach(s -> System.out.println(s)); +``` + +
++ +The content of `options.k` is + +```python +a = option("key1") +b = option("key2", required=True) +c = { + metadata.key = option("metadata-key") +} +``` + +Java Code + +```java +import com.kcl.api.*; + +ParseProgram_Args args = ParseProgram_Args.newBuilder().addPaths("./src/test_data/option/main.k").build(); +API apiInstance = new API(); +ListOptions_Result result = apiInstance.listOptions(args); +``` + +
++ +The content of `schema.k` is + +```python +schema AppConfig: + replicas: int + +app: AppConfig { + replicas: 2 +} +``` + +Java Code + +```java +import com.kcl.api.*; + +ExecProgram_Args execArgs = ExecProgram_Args.newBuilder().addKFilenameList("schema.k").build(); +GetSchemaTypeMapping_Args args = GetSchemaTypeMapping_Args.newBuilder().setExecArgs(execArgs).build(); +API apiInstance = new API(); +GetSchemaTypeMapping_Result result = apiInstance.getSchemaTypeMapping(args); +KclType appSchemaType = result.getSchemaTypeMappingMap().get("app"); +String replicasType = appSchemaType.getPropertiesOrThrow("replicas").getType(); +``` + +
++ +The content of `main.k` is + +```python +a = 1 + +b = { + "a": 1 + "b": 2 +} +``` + +Java Code + +```java +import com.kcl.api.*; + +API api = new API(); +String spec = "a=2"; +OverrideFile_Result result = api.overrideFile(OverrideFile_Args.newBuilder() + .setFile("./src/test_data/override_file/main.k").addSpecs(spec).build()); +``` + +
++ +Java Code + +```java +import com.kcl.api.*; + +String sourceCode = "schema Person:\n" + " name: str\n" + " age: int\n" + " check:\n" + + " 0 < age < 120\n"; +FormatCode_Args args = FormatCode_Args.newBuilder().setSource(sourceCode).build(); +API apiInstance = new API(); +FormatCode_Result result = apiInstance.formatCode(args); +String expectedFormattedCode = "schema Person:\n" + " name: str\n" + " age: int\n\n" + " check:\n" + + " 0 < age < 120\n\n"; +``` + +
++ +The content of `format_path.k` is + +```python +schema Person: + name: str + age: int + + check: + 0 < age < 120 +``` + +Java Code + +```java +import com.kcl.api.*; + +FormatPath_Args args = FormatPath_Args.newBuilder().setPath("format_path.k").build(); +API apiInstance = new API(); +FormatPath_Result result = apiInstance.formatPath(args); +Assert.assertTrue(result.getChangedPathsList().isEmpty()); +``` + +
++ +The content of `lint_path.k` is + +```python +import math + +a = 1 +``` + +Java Code + +```java +import com.kcl.api.*; + +LintPath_Args args = LintPath_Args.newBuilder().addPaths("lint_path.k").build(); +API apiInstance = new API(); +LintPath_Result result = apiInstance.lintPath(args); +boolean foundWarning = result.getResultsList().stream() + .anyMatch(warning -> warning.contains("Module 'math' imported but unused")); +``` + +
++ +Java Code + +```java +import com.kcl.api.*; + +String code = "schema Person:\n" + " name: str\n" + " age: int\n" + " check:\n" + + " 0 < age < 120\n"; +String data = "{\"name\": \"Alice\", \"age\": 10}"; +ValidateCode_Args args = ValidateCode_Args.newBuilder().setCode(code).setData(data).setFormat("json").build(); +API apiInstance = new API(); +ValidateCode_Result result = apiInstance.validateCode(args); +``` + +
++ +The content of `main.k` is + +```python +a = 1 +b = a +``` + +Java Code + +```java +import com.kcl.api.*; + +Rename_Args args = Rename_Args.newBuilder().setPackageRoot(".").setSymbolPath("a") + .addFilePaths("main.k").setNewName("a2").build(); +API apiInstance = new API(); +Rename_Result result = apiInstance.rename(args); +``` + +
++ +Java Code + +```java +import com.kcl.api.*; + +API api = new API(); +RenameCode_Args args = RenameCode_Args.newBuilder().setPackageRoot("/mock/path").setSymbolPath("a") + .putSourceCodes("/mock/path/main.k", "a = 1\nb = a").setNewName("a2").build(); +RenameCode_Result result = api.renameCode(args); +``` + +
++ +Java Code + +```java +import com.kcl.api.*; + +API apiInstance = new API(); +Test_Args args = Test_Args.newBuilder().addPkgList("/path/to/test/package").build(); +Test_Result result = apiInstance.test(args); +``` + +
++ +The content of `kcl.yaml` is + +```yaml +kcl_cli_configs: + strict_range_check: true +kcl_options: + - key: key + value: value +``` + +Java Code + +```java +import com.kcl.api.*; + +API api = new API(); +LoadSettingsFiles_Args args = LoadSettingsFiles_Args.newBuilder().addFiles("kcl.yaml") + .build(); +LoadSettingsFiles_Result result = api.loadSettingsFiles(args); +``` + +
++ +The content of `module/kcl.mod` is + +```yaml +[package] +name = "mod_update" +edition = "0.0.1" +version = "0.0.1" + +[dependencies] +helloworld = { oci = "oci://ghcr.io/kcl-lang/helloworld", tag = "0.1.0" } +flask = { git = "https://github.com/kcl-lang/flask-demo-kcl-manifests", commit = "ade147b" } +``` + +Java Code + +```java +import com.kcl.api.*; + +API api = new API(); + +UpdateDependencies_Result result = api.updateDependencies( + UpdateDependencies_Args.newBuilder().setManifestPath("module").build()); +``` + +
++ +The content of `module/kcl.mod` is + +```yaml +[package] +name = "mod_update" +edition = "0.0.1" +version = "0.0.1" + +[dependencies] +helloworld = { oci = "oci://ghcr.io/kcl-lang/helloworld", tag = "0.1.0" } +flask = { git = "https://github.com/kcl-lang/flask-demo-kcl-manifests", commit = "ade147b" } +``` + +The content of `module/main.k` is + +```python +import helloworld +import flask + +a = helloworld.The_first_kcl_program +``` + +Java Code + +```java +import com.kcl.api.*; + +API api = new API(); + +UpdateDependencies_Result result = api.updateDependencies( + UpdateDependencies_Args.newBuilder().setManifestPath("./src/test_data/update_dependencies").build()); + +ExecProgram_Args execArgs = ExecProgram_Args.newBuilder(). addAllExternalPkgs(result.getExternalPkgsList()) + .addKFilenameList("./src/test_data/update_dependencies/main.k").build(); + +ExecProgram_Result execResult = api.execProgram(execArgs); +``` + +
++ +Java Code + +```java +import com.kcl.api.*; + +API api = new API(); +GetVersion_Args version_args = GetVersion_Args.newBuilder().build(); +GetVersion_Result result = api.getVersion(version_args); +``` + +
++ +The content of `schema.k` is + +```python +schema AppConfig: + replicas: int + +app: AppConfig { + replicas: 2 +} +``` + +Java Code + +```java +import com.kcl.api.*; + +ExecProgram_Args args = ExecProgram_Args.newBuilder().addKFilenameList("schema.k").build(); +API apiInstance = new API(); +ExecProgram_Result result = apiInstance.execProgram(args); +``` + +
++ +The content of `schema.k` is + +```python +schema AppConfig: + replicas: int + +app: AppConfig { + replicas: 2 +} +``` + +Java Code + +```java +import com.kcl.api.*; +import com.kcl.ast.*; +import com.kcl.util.JsonUtil; + +API api = new API(); +ParseProgram_Result result = api.parseProgram( + ParseProgram_Args.newBuilder().addPaths("schema.k").build() +); +System.out.println(result.getAstJson()); +Program program = JsonUtil.deserializeProgram(result.getAstJson()); +``` + +
++ +The content of `schema.k` is + +```python +schema AppConfig: + replicas: int + +app: AppConfig { + replicas: 2 +} +``` + +Java Code + +```java +import com.kcl.api.*; + +ParseFile_Args args = ParseFile_Args.newBuilder().setPath("schema.k").build(); +API apiInstance = new API(); +ParseFile_Result result = apiInstance.parseFile(args); +``` + +
++ +The content of `schema.k` is + +```python +schema AppConfig: + replicas: int + +app: AppConfig { + replicas: 2 +} +``` + +Java Code + +```java +import com.kcl.api.*; +import com.kcl.ast.*; +import com.kcl.util.JsonUtil; + +API api = new API(); +ParseProgram_Result result = api.parseProgram( + ParseProgram_Args.newBuilder().addPaths("path/to/kcl.k").build() +); +System.out.println(result.getAstJson()); +Program program = JsonUtil.deserializeProgram(result.getAstJson()); +``` + +
++ +The content of `schema.k` is + +```python +schema AppConfig: + replicas: int + +app: AppConfig { + replicas: 2 +} +``` + +Java Code + +```python +import kcl_lib.api as api + +args = api.LoadPackage_Args( + parse_args=api.ParseProgram_Args(paths=["schema.k"]), resolve_ast=True +) +api = api.API() +result = api.load_package(args) +assert list(result.symbols.values())[0].ty.schema_name == "AppConfig" +``` + +
++ +The content of `schema.k` is + +```python +schema AppConfig: + replicas: int + +app: AppConfig { + replicas: 2 +} +``` + +Java Code + +```java +import com.kcl.api.*; + +API api = new API(); +ListVariables_Result result = api.listVariables( + ListVariables_Args.newBuilder().setResolveAst(true).setParseArgs( + ParseProgram_Args.newBuilder().addPaths("/path/to/kcl.k").build()) + .build()); +result.getSymbolsMap().values().forEach(s -> System.out.println(s)); +``` + +
++ +The content of `options.k` is + +```python +a = option("key1") +b = option("key2", required=True) +c = { + metadata.key = option("metadata-key") +} +``` + +Java Code + +```java +import com.kcl.api.*; + +ParseProgram_Args args = ParseProgram_Args.newBuilder().addPaths("./src/test_data/option/main.k").build(); +API apiInstance = new API(); +ListOptions_Result result = apiInstance.listOptions(args); +``` + +
++ +The content of `schema.k` is + +```python +schema AppConfig: + replicas: int + +app: AppConfig { + replicas: 2 +} +``` + +Java Code + +```java +import com.kcl.api.*; + +ExecProgram_Args execArgs = ExecProgram_Args.newBuilder().addKFilenameList("schema.k").build(); +GetSchemaTypeMapping_Args args = GetSchemaTypeMapping_Args.newBuilder().setExecArgs(execArgs).build(); +API apiInstance = new API(); +GetSchemaTypeMapping_Result result = apiInstance.getSchemaTypeMapping(args); +KclType appSchemaType = result.getSchemaTypeMappingMap().get("app"); +String replicasType = appSchemaType.getPropertiesOrThrow("replicas").getType(); +``` + +
++ +The content of `main.k` is + +```python +a = 1 + +b = { + "a": 1 + "b": 2 +} +``` + +Java Code + +```java +import com.kcl.api.*; + +API api = new API(); +String spec = "a=2"; +OverrideFile_Result result = api.overrideFile(OverrideFile_Args.newBuilder() + .setFile("./src/test_data/override_file/main.k").addSpecs(spec).build()); +``` + +
++ +Java Code + +```java +import com.kcl.api.*; + +String sourceCode = "schema Person:\n" + " name: str\n" + " age: int\n" + " check:\n" + + " 0 < age < 120\n"; +FormatCode_Args args = FormatCode_Args.newBuilder().setSource(sourceCode).build(); +API apiInstance = new API(); +FormatCode_Result result = apiInstance.formatCode(args); +String expectedFormattedCode = "schema Person:\n" + " name: str\n" + " age: int\n\n" + " check:\n" + + " 0 < age < 120\n\n"; +``` + +
++ +The content of `format_path.k` is + +```python +schema Person: + name: str + age: int + + check: + 0 < age < 120 +``` + +Java Code + +```java +import com.kcl.api.*; + +FormatPath_Args args = FormatPath_Args.newBuilder().setPath("format_path.k").build(); +API apiInstance = new API(); +FormatPath_Result result = apiInstance.formatPath(args); +Assert.assertTrue(result.getChangedPathsList().isEmpty()); +``` + +
++ +The content of `lint_path.k` is + +```python +import math + +a = 1 +``` + +Java Code + +```java +import com.kcl.api.*; + +LintPath_Args args = LintPath_Args.newBuilder().addPaths("lint_path.k").build(); +API apiInstance = new API(); +LintPath_Result result = apiInstance.lintPath(args); +boolean foundWarning = result.getResultsList().stream() + .anyMatch(warning -> warning.contains("Module 'math' imported but unused")); +``` + +
++ +Java Code + +```java +import com.kcl.api.*; + +String code = "schema Person:\n" + " name: str\n" + " age: int\n" + " check:\n" + + " 0 < age < 120\n"; +String data = "{\"name\": \"Alice\", \"age\": 10}"; +ValidateCode_Args args = ValidateCode_Args.newBuilder().setCode(code).setData(data).setFormat("json").build(); +API apiInstance = new API(); +ValidateCode_Result result = apiInstance.validateCode(args); +``` + +
++ +The content of `main.k` is + +```python +a = 1 +b = a +``` + +Java Code + +```java +import com.kcl.api.*; + +Rename_Args args = Rename_Args.newBuilder().setPackageRoot(".").setSymbolPath("a") + .addFilePaths("main.k").setNewName("a2").build(); +API apiInstance = new API(); +Rename_Result result = apiInstance.rename(args); +``` + +
++ +Java Code + +```java +import com.kcl.api.*; + +API api = new API(); +RenameCode_Args args = RenameCode_Args.newBuilder().setPackageRoot("/mock/path").setSymbolPath("a") + .putSourceCodes("/mock/path/main.k", "a = 1\nb = a").setNewName("a2").build(); +RenameCode_Result result = api.renameCode(args); +``` + +
++ +Java Code + +```java +import com.kcl.api.*; + +API apiInstance = new API(); +Test_Args args = Test_Args.newBuilder().addPkgList("/path/to/test/package").build(); +Test_Result result = apiInstance.test(args); +``` + +
++ +The content of `kcl.yaml` is + +```yaml +kcl_cli_configs: + strict_range_check: true +kcl_options: + - key: key + value: value +``` + +Java Code + +```java +import com.kcl.api.*; + +API api = new API(); +LoadSettingsFiles_Args args = LoadSettingsFiles_Args.newBuilder().addFiles("kcl.yaml") + .build(); +LoadSettingsFiles_Result result = api.loadSettingsFiles(args); +``` + +
++ +The content of `module/kcl.mod` is + +```yaml +[package] +name = "mod_update" +edition = "0.0.1" +version = "0.0.1" + +[dependencies] +helloworld = { oci = "oci://ghcr.io/kcl-lang/helloworld", tag = "0.1.0" } +flask = { git = "https://github.com/kcl-lang/flask-demo-kcl-manifests", commit = "ade147b" } +``` + +Java Code + +```java +import com.kcl.api.*; + +API api = new API(); + +UpdateDependencies_Result result = api.updateDependencies( + UpdateDependencies_Args.newBuilder().setManifestPath("module").build()); +``` + +
++ +The content of `module/kcl.mod` is + +```yaml +[package] +name = "mod_update" +edition = "0.0.1" +version = "0.0.1" + +[dependencies] +helloworld = { oci = "oci://ghcr.io/kcl-lang/helloworld", tag = "0.1.0" } +flask = { git = "https://github.com/kcl-lang/flask-demo-kcl-manifests", commit = "ade147b" } +``` + +The content of `module/main.k` is + +```python +import helloworld +import flask + +a = helloworld.The_first_kcl_program +``` + +Java Code + +```java +import com.kcl.api.*; + +API api = new API(); + +UpdateDependencies_Result result = api.updateDependencies( + UpdateDependencies_Args.newBuilder().setManifestPath("./src/test_data/update_dependencies").build()); + +ExecProgram_Args execArgs = ExecProgram_Args.newBuilder(). addAllExternalPkgs(result.getExternalPkgsList()) + .addKFilenameList("./src/test_data/update_dependencies/main.k").build(); + +ExecProgram_Result execResult = api.execProgram(execArgs); +``` + +
++ +Java Code + +```java +import com.kcl.api.*; + +API api = new API(); +GetVersion_Args version_args = GetVersion_Args.newBuilder().build(); +GetVersion_Result result = api.getVersion(version_args); +``` + +
++ +The content of `schema.k` is + +```python +schema AppConfig: + replicas: int + +app: AppConfig { + replicas: 2 +} +``` + +Java Code + +```java +import com.kcl.api.*; + +ExecProgram_Args args = ExecProgram_Args.newBuilder().addKFilenameList("schema.k").build(); +API apiInstance = new API(); +ExecProgram_Result result = apiInstance.execProgram(args); +``` + +
++ +The content of `schema.k` is + +```python +schema AppConfig: + replicas: int + +app: AppConfig { + replicas: 2 +} +``` + +Java Code + +```java +import com.kcl.api.*; +import com.kcl.ast.*; +import com.kcl.util.JsonUtil; + +API api = new API(); +ParseProgram_Result result = api.parseProgram( + ParseProgram_Args.newBuilder().addPaths("schema.k").build() +); +System.out.println(result.getAstJson()); +Program program = JsonUtil.deserializeProgram(result.getAstJson()); +``` + +
++ +The content of `schema.k` is + +```python +schema AppConfig: + replicas: int + +app: AppConfig { + replicas: 2 +} +``` + +Java Code + +```java +import com.kcl.api.*; + +ParseFile_Args args = ParseFile_Args.newBuilder().setPath("schema.k").build(); +API apiInstance = new API(); +ParseFile_Result result = apiInstance.parseFile(args); +``` + +
++ +The content of `schema.k` is + +```python +schema AppConfig: + replicas: int + +app: AppConfig { + replicas: 2 +} +``` + +Java Code + +```java +import com.kcl.api.*; +import com.kcl.ast.*; +import com.kcl.util.JsonUtil; + +API api = new API(); +ParseProgram_Result result = api.parseProgram( + ParseProgram_Args.newBuilder().addPaths("path/to/kcl.k").build() +); +System.out.println(result.getAstJson()); +Program program = JsonUtil.deserializeProgram(result.getAstJson()); +``` + +
++ +The content of `schema.k` is + +```python +schema AppConfig: + replicas: int + +app: AppConfig { + replicas: 2 +} +``` + +Java Code + +```python +import kcl_lib.api as api + +args = api.LoadPackage_Args( + parse_args=api.ParseProgram_Args(paths=["schema.k"]), resolve_ast=True +) +api = api.API() +result = api.load_package(args) +assert list(result.symbols.values())[0].ty.schema_name == "AppConfig" +``` + +
++ +The content of `schema.k` is + +```python +schema AppConfig: + replicas: int + +app: AppConfig { + replicas: 2 +} +``` + +Java Code + +```java +import com.kcl.api.*; + +API api = new API(); +ListVariables_Result result = api.listVariables( + ListVariables_Args.newBuilder().setResolveAst(true).setParseArgs( + ParseProgram_Args.newBuilder().addPaths("/path/to/kcl.k").build()) + .build()); +result.getSymbolsMap().values().forEach(s -> System.out.println(s)); +``` + +
++ +The content of `options.k` is + +```python +a = option("key1") +b = option("key2", required=True) +c = { + metadata.key = option("metadata-key") +} +``` + +Java Code + +```java +import com.kcl.api.*; + +ParseProgram_Args args = ParseProgram_Args.newBuilder().addPaths("./src/test_data/option/main.k").build(); +API apiInstance = new API(); +ListOptions_Result result = apiInstance.listOptions(args); +``` + +
++ +The content of `schema.k` is + +```python +schema AppConfig: + replicas: int + +app: AppConfig { + replicas: 2 +} +``` + +Java Code + +```java +import com.kcl.api.*; + +ExecProgram_Args execArgs = ExecProgram_Args.newBuilder().addKFilenameList("schema.k").build(); +GetSchemaTypeMapping_Args args = GetSchemaTypeMapping_Args.newBuilder().setExecArgs(execArgs).build(); +API apiInstance = new API(); +GetSchemaTypeMapping_Result result = apiInstance.getSchemaTypeMapping(args); +KclType appSchemaType = result.getSchemaTypeMappingMap().get("app"); +String replicasType = appSchemaType.getPropertiesOrThrow("replicas").getType(); +``` + +
++ +The content of `main.k` is + +```python +a = 1 + +b = { + "a": 1 + "b": 2 +} +``` + +Java Code + +```java +import com.kcl.api.*; + +API api = new API(); +String spec = "a=2"; +OverrideFile_Result result = api.overrideFile(OverrideFile_Args.newBuilder() + .setFile("./src/test_data/override_file/main.k").addSpecs(spec).build()); +``` + +
++ +Java Code + +```java +import com.kcl.api.*; + +String sourceCode = "schema Person:\n" + " name: str\n" + " age: int\n" + " check:\n" + + " 0 < age < 120\n"; +FormatCode_Args args = FormatCode_Args.newBuilder().setSource(sourceCode).build(); +API apiInstance = new API(); +FormatCode_Result result = apiInstance.formatCode(args); +String expectedFormattedCode = "schema Person:\n" + " name: str\n" + " age: int\n\n" + " check:\n" + + " 0 < age < 120\n\n"; +``` + +
++ +The content of `format_path.k` is + +```python +schema Person: + name: str + age: int + + check: + 0 < age < 120 +``` + +Java Code + +```java +import com.kcl.api.*; + +FormatPath_Args args = FormatPath_Args.newBuilder().setPath("format_path.k").build(); +API apiInstance = new API(); +FormatPath_Result result = apiInstance.formatPath(args); +Assert.assertTrue(result.getChangedPathsList().isEmpty()); +``` + +
++ +The content of `lint_path.k` is + +```python +import math + +a = 1 +``` + +Java Code + +```java +import com.kcl.api.*; + +LintPath_Args args = LintPath_Args.newBuilder().addPaths("lint_path.k").build(); +API apiInstance = new API(); +LintPath_Result result = apiInstance.lintPath(args); +boolean foundWarning = result.getResultsList().stream() + .anyMatch(warning -> warning.contains("Module 'math' imported but unused")); +``` + +
++ +Java Code + +```java +import com.kcl.api.*; + +String code = "schema Person:\n" + " name: str\n" + " age: int\n" + " check:\n" + + " 0 < age < 120\n"; +String data = "{\"name\": \"Alice\", \"age\": 10}"; +ValidateCode_Args args = ValidateCode_Args.newBuilder().setCode(code).setData(data).setFormat("json").build(); +API apiInstance = new API(); +ValidateCode_Result result = apiInstance.validateCode(args); +``` + +
++ +The content of `main.k` is + +```python +a = 1 +b = a +``` + +Java Code + +```java +import com.kcl.api.*; + +Rename_Args args = Rename_Args.newBuilder().setPackageRoot(".").setSymbolPath("a") + .addFilePaths("main.k").setNewName("a2").build(); +API apiInstance = new API(); +Rename_Result result = apiInstance.rename(args); +``` + +
++ +Java Code + +```java +import com.kcl.api.*; + +API api = new API(); +RenameCode_Args args = RenameCode_Args.newBuilder().setPackageRoot("/mock/path").setSymbolPath("a") + .putSourceCodes("/mock/path/main.k", "a = 1\nb = a").setNewName("a2").build(); +RenameCode_Result result = api.renameCode(args); +``` + +
++ +Java Code + +```java +import com.kcl.api.*; + +API apiInstance = new API(); +Test_Args args = Test_Args.newBuilder().addPkgList("/path/to/test/package").build(); +Test_Result result = apiInstance.test(args); +``` + +
++ +The content of `kcl.yaml` is + +```yaml +kcl_cli_configs: + strict_range_check: true +kcl_options: + - key: key + value: value +``` + +Java Code + +```java +import com.kcl.api.*; + +API api = new API(); +LoadSettingsFiles_Args args = LoadSettingsFiles_Args.newBuilder().addFiles("kcl.yaml") + .build(); +LoadSettingsFiles_Result result = api.loadSettingsFiles(args); +``` + +
++ +The content of `module/kcl.mod` is + +```yaml +[package] +name = "mod_update" +edition = "0.0.1" +version = "0.0.1" + +[dependencies] +helloworld = { oci = "oci://ghcr.io/kcl-lang/helloworld", tag = "0.1.0" } +flask = { git = "https://github.com/kcl-lang/flask-demo-kcl-manifests", commit = "ade147b" } +``` + +Java Code + +```java +import com.kcl.api.*; + +API api = new API(); + +UpdateDependencies_Result result = api.updateDependencies( + UpdateDependencies_Args.newBuilder().setManifestPath("module").build()); +``` + +
++ +The content of `module/kcl.mod` is + +```yaml +[package] +name = "mod_update" +edition = "0.0.1" +version = "0.0.1" + +[dependencies] +helloworld = { oci = "oci://ghcr.io/kcl-lang/helloworld", tag = "0.1.0" } +flask = { git = "https://github.com/kcl-lang/flask-demo-kcl-manifests", commit = "ade147b" } +``` + +The content of `module/main.k` is + +```python +import helloworld +import flask + +a = helloworld.The_first_kcl_program +``` + +Java Code + +```java +import com.kcl.api.*; + +API api = new API(); + +UpdateDependencies_Result result = api.updateDependencies( + UpdateDependencies_Args.newBuilder().setManifestPath("./src/test_data/update_dependencies").build()); + +ExecProgram_Args execArgs = ExecProgram_Args.newBuilder(). addAllExternalPkgs(result.getExternalPkgsList()) + .addKFilenameList("./src/test_data/update_dependencies/main.k").build(); + +ExecProgram_Result execResult = api.execProgram(execArgs); +``` + +
++ +Java Code + +```java +import com.kcl.api.*; + +API api = new API(); +GetVersion_Args version_args = GetVersion_Args.newBuilder().build(); +GetVersion_Result result = api.getVersion(version_args); +``` + +
++ +The content of `schema.k` is + +```python +schema AppConfig: + replicas: int + +app: AppConfig { + replicas: 2 +} +``` + +Java Code + +```java +import com.kcl.api.*; + +ExecProgram_Args args = ExecProgram_Args.newBuilder().addKFilenameList("schema.k").build(); +API apiInstance = new API(); +ExecProgram_Result result = apiInstance.execProgram(args); +``` + +
++ +The content of `schema.k` is + +```python +schema AppConfig: + replicas: int + +app: AppConfig { + replicas: 2 +} +``` + +Java Code + +```java +import com.kcl.api.*; +import com.kcl.ast.*; +import com.kcl.util.JsonUtil; + +API api = new API(); +ParseProgram_Result result = api.parseProgram( + ParseProgram_Args.newBuilder().addPaths("schema.k").build() +); +System.out.println(result.getAstJson()); +Program program = JsonUtil.deserializeProgram(result.getAstJson()); +``` + +
++ +The content of `schema.k` is + +```python +schema AppConfig: + replicas: int + +app: AppConfig { + replicas: 2 +} +``` + +Java Code + +```java +import com.kcl.api.*; + +ParseFile_Args args = ParseFile_Args.newBuilder().setPath("schema.k").build(); +API apiInstance = new API(); +ParseFile_Result result = apiInstance.parseFile(args); +``` + +
++ +The content of `schema.k` is + +```python +schema AppConfig: + replicas: int + +app: AppConfig { + replicas: 2 +} +``` + +Java Code + +```java +import com.kcl.api.*; +import com.kcl.ast.*; +import com.kcl.util.JsonUtil; + +API api = new API(); +ParseProgram_Result result = api.parseProgram( + ParseProgram_Args.newBuilder().addPaths("path/to/kcl.k").build() +); +System.out.println(result.getAstJson()); +Program program = JsonUtil.deserializeProgram(result.getAstJson()); +``` + +
++ +The content of `schema.k` is + +```python +schema AppConfig: + replicas: int + +app: AppConfig { + replicas: 2 +} +``` + +Java Code + +```python +import kcl_lib.api as api + +args = api.LoadPackage_Args( + parse_args=api.ParseProgram_Args(paths=["schema.k"]), resolve_ast=True +) +api = api.API() +result = api.load_package(args) +assert list(result.symbols.values())[0].ty.schema_name == "AppConfig" +``` + +
++ +The content of `schema.k` is + +```python +schema AppConfig: + replicas: int + +app: AppConfig { + replicas: 2 +} +``` + +Java Code + +```java +import com.kcl.api.*; + +API api = new API(); +ListVariables_Result result = api.listVariables( + ListVariables_Args.newBuilder().setResolveAst(true).setParseArgs( + ParseProgram_Args.newBuilder().addPaths("/path/to/kcl.k").build()) + .build()); +result.getSymbolsMap().values().forEach(s -> System.out.println(s)); +``` + +
++ +The content of `options.k` is + +```python +a = option("key1") +b = option("key2", required=True) +c = { + metadata.key = option("metadata-key") +} +``` + +Java Code + +```java +import com.kcl.api.*; + +ParseProgram_Args args = ParseProgram_Args.newBuilder().addPaths("./src/test_data/option/main.k").build(); +API apiInstance = new API(); +ListOptions_Result result = apiInstance.listOptions(args); +``` + +
++ +The content of `schema.k` is + +```python +schema AppConfig: + replicas: int + +app: AppConfig { + replicas: 2 +} +``` + +Java Code + +```java +import com.kcl.api.*; + +ExecProgram_Args execArgs = ExecProgram_Args.newBuilder().addKFilenameList("schema.k").build(); +GetSchemaTypeMapping_Args args = GetSchemaTypeMapping_Args.newBuilder().setExecArgs(execArgs).build(); +API apiInstance = new API(); +GetSchemaTypeMapping_Result result = apiInstance.getSchemaTypeMapping(args); +KclType appSchemaType = result.getSchemaTypeMappingMap().get("app"); +String replicasType = appSchemaType.getPropertiesOrThrow("replicas").getType(); +``` + +
++ +The content of `main.k` is + +```python +a = 1 + +b = { + "a": 1 + "b": 2 +} +``` + +Java Code + +```java +import com.kcl.api.*; + +API api = new API(); +String spec = "a=2"; +OverrideFile_Result result = api.overrideFile(OverrideFile_Args.newBuilder() + .setFile("./src/test_data/override_file/main.k").addSpecs(spec).build()); +``` + +
++ +Java Code + +```java +import com.kcl.api.*; + +String sourceCode = "schema Person:\n" + " name: str\n" + " age: int\n" + " check:\n" + + " 0 < age < 120\n"; +FormatCode_Args args = FormatCode_Args.newBuilder().setSource(sourceCode).build(); +API apiInstance = new API(); +FormatCode_Result result = apiInstance.formatCode(args); +String expectedFormattedCode = "schema Person:\n" + " name: str\n" + " age: int\n\n" + " check:\n" + + " 0 < age < 120\n\n"; +``` + +
++ +The content of `format_path.k` is + +```python +schema Person: + name: str + age: int + + check: + 0 < age < 120 +``` + +Java Code + +```java +import com.kcl.api.*; + +FormatPath_Args args = FormatPath_Args.newBuilder().setPath("format_path.k").build(); +API apiInstance = new API(); +FormatPath_Result result = apiInstance.formatPath(args); +Assert.assertTrue(result.getChangedPathsList().isEmpty()); +``` + +
++ +The content of `lint_path.k` is + +```python +import math + +a = 1 +``` + +Java Code + +```java +import com.kcl.api.*; + +LintPath_Args args = LintPath_Args.newBuilder().addPaths("lint_path.k").build(); +API apiInstance = new API(); +LintPath_Result result = apiInstance.lintPath(args); +boolean foundWarning = result.getResultsList().stream() + .anyMatch(warning -> warning.contains("Module 'math' imported but unused")); +``` + +
++ +Java Code + +```java +import com.kcl.api.*; + +String code = "schema Person:\n" + " name: str\n" + " age: int\n" + " check:\n" + + " 0 < age < 120\n"; +String data = "{\"name\": \"Alice\", \"age\": 10}"; +ValidateCode_Args args = ValidateCode_Args.newBuilder().setCode(code).setData(data).setFormat("json").build(); +API apiInstance = new API(); +ValidateCode_Result result = apiInstance.validateCode(args); +``` + +
++ +The content of `main.k` is + +```python +a = 1 +b = a +``` + +Java Code + +```java +import com.kcl.api.*; + +Rename_Args args = Rename_Args.newBuilder().setPackageRoot(".").setSymbolPath("a") + .addFilePaths("main.k").setNewName("a2").build(); +API apiInstance = new API(); +Rename_Result result = apiInstance.rename(args); +``` + +
++ +Java Code + +```java +import com.kcl.api.*; + +API api = new API(); +RenameCode_Args args = RenameCode_Args.newBuilder().setPackageRoot("/mock/path").setSymbolPath("a") + .putSourceCodes("/mock/path/main.k", "a = 1\nb = a").setNewName("a2").build(); +RenameCode_Result result = api.renameCode(args); +``` + +
++ +Java Code + +```java +import com.kcl.api.*; + +API apiInstance = new API(); +Test_Args args = Test_Args.newBuilder().addPkgList("/path/to/test/package").build(); +Test_Result result = apiInstance.test(args); +``` + +
++ +The content of `kcl.yaml` is + +```yaml +kcl_cli_configs: + strict_range_check: true +kcl_options: + - key: key + value: value +``` + +Java Code + +```java +import com.kcl.api.*; + +API api = new API(); +LoadSettingsFiles_Args args = LoadSettingsFiles_Args.newBuilder().addFiles("kcl.yaml") + .build(); +LoadSettingsFiles_Result result = api.loadSettingsFiles(args); +``` + +
++ +The content of `module/kcl.mod` is + +```yaml +[package] +name = "mod_update" +edition = "0.0.1" +version = "0.0.1" + +[dependencies] +helloworld = { oci = "oci://ghcr.io/kcl-lang/helloworld", tag = "0.1.0" } +flask = { git = "https://github.com/kcl-lang/flask-demo-kcl-manifests", commit = "ade147b" } +``` + +Java Code + +```java +import com.kcl.api.*; + +API api = new API(); + +UpdateDependencies_Result result = api.updateDependencies( + UpdateDependencies_Args.newBuilder().setManifestPath("module").build()); +``` + +
++ +The content of `module/kcl.mod` is + +```yaml +[package] +name = "mod_update" +edition = "0.0.1" +version = "0.0.1" + +[dependencies] +helloworld = { oci = "oci://ghcr.io/kcl-lang/helloworld", tag = "0.1.0" } +flask = { git = "https://github.com/kcl-lang/flask-demo-kcl-manifests", commit = "ade147b" } +``` + +The content of `module/main.k` is + +```python +import helloworld +import flask + +a = helloworld.The_first_kcl_program +``` + +Java Code + +```java +import com.kcl.api.*; + +API api = new API(); + +UpdateDependencies_Result result = api.updateDependencies( + UpdateDependencies_Args.newBuilder().setManifestPath("./src/test_data/update_dependencies").build()); + +ExecProgram_Args execArgs = ExecProgram_Args.newBuilder(). addAllExternalPkgs(result.getExternalPkgsList()) + .addKFilenameList("./src/test_data/update_dependencies/main.k").build(); + +ExecProgram_Result execResult = api.execProgram(execArgs); +``` + +
++ +Java Code + +```java +import com.kcl.api.*; + +API api = new API(); +GetVersion_Args version_args = GetVersion_Args.newBuilder().build(); +GetVersion_Result result = api.getVersion(version_args); +``` + +
+