Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: get all full schema types when schema name is empty #914

Merged
merged 2 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions kclvm/api/src/capi_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,20 @@ fn test_c_api_get_full_schema_type() {
);
}

#[test]
fn test_c_api_get_all_full_schema_types() {
test_c_api::<GetFullSchemaTypeArgs, GetSchemaTypeResult, _>(
"KclvmService.GetFullSchemaType",
"get-all-full-schema-types.json",
"get-all-full-schema-types.response.json",
|r| {
for s_ty in &mut r.schema_type_list {
s_ty.filename = s_ty.filename.replace("/", "").replace("\\", "")
}
},
);
}

#[test]
fn test_c_api_get_schema_type_mapping() {
test_c_api_without_wrapper::<GetSchemaTypeMappingArgs, GetSchemaTypeMappingResult>(
Expand Down
19 changes: 19 additions & 0 deletions kclvm/api/src/testdata/get-all-full-schema-types.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"exec_args": {
"work_dir" : "./src/testdata/get_schema_ty/aaa",
"k_filename_list":[
"./src/testdata/get_schema_ty/aaa/main.k"
],
"external_pkgs": [
{
"pkg_name": "bbb",
"pkg_path": "./src/testdata/get_schema_ty/bbb"
},
{
"pkg_name": "ccc",
"pkg_path": "./src/testdata/get_schema_ty/ccc"
}
]
},
"schema_name": ""
}
78 changes: 78 additions & 0 deletions kclvm/api/src/testdata/get-all-full-schema-types.response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"schema_type_list": [
{
"type": "schema",
"union_types": [],
"default": "",
"schema_name": "B",
"schema_doc": "",
"properties": {
"name": {
"type": "str",
"union_types": [],
"default": "",
"schema_name": "",
"schema_doc": "",
"properties": {},
"required": [],
"key": null,
"item": null,
"line": 1,
"decorators": [],
"filename": "",
"pkg_path": "",
"description": "",
"examples": {}
}
},
"required": [
"name"
],
"key": null,
"item": null,
"line": 0,
"decorators": [],
"filename": "./src/testdata/get_schema_ty/bbb/main.k",
"pkg_path": "bbb",
"description": "",
"examples": {}
},
{
"type": "schema",
"union_types": [],
"default": "",
"schema_name": "C",
"schema_doc": "",
"properties": {
"name": {
"type": "str",
"union_types": [],
"default": "",
"schema_name": "",
"schema_doc": "",
"properties": {},
"required": [],
"key": null,
"item": null,
"line": 1,
"decorators": [],
"filename": "",
"pkg_path": "",
"description": "",
"examples": {}
}
},
"required": [
"name"
],
"key": null,
"item": null,
"line": 0,
"decorators": [],
"filename": "./src/testdata/get_schema_ty/ccc/main.k",
"pkg_path": "ccc",
"description": "",
"examples": {}
}
]
}
5 changes: 5 additions & 0 deletions kclvm/api/src/testdata/get_schema_ty/aaa/main.k
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import bbb as b
import ccc as c

a = b.B {
name: "b instance in a"
}

a_c = c.C {
name: "c instance in a"
}
5 changes: 5 additions & 0 deletions kclvm/api/src/testdata/get_schema_ty/ccc/kcl.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
name = "ccc"
edition = "0.0.1"
version = "0.0.1"

2 changes: 2 additions & 0 deletions kclvm/api/src/testdata/get_schema_ty/ccc/main.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
schema C:
name: str
2 changes: 1 addition & 1 deletion kclvm/query/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ pub fn get_full_schema_type(
// Schema name filter
match schema_name {
Some(schema_name) => {
if schema_name == name {
if schema_name.is_empty() || schema_name == name {
result.insert(name.to_string(), schema_ty);
}
}
Expand Down
Loading