-
Notifications
You must be signed in to change notification settings - Fork 164
Description
Bug Report
1. Minimal reproduce step (Required)
${workspace}/models/class_models.k
schema classmate:
classname: str
students: [[student]] # Group data using two-dimensional arrays
schema student:
name: str
age: int
kcl data file, ${workspace}/json_2_array.k:
import models.class_models as c_model
cm = c_model.classmate {
classname = "一年级一班"
students = [
[
c_model.student {
name = "xiaoming"
age = 6
},
c_model.student {
name = "xiaohua"
age = 5
},
],
[
c_model.student {
name = "xiaohong"
age = 6
},
]
]
}
execute kcl json_2_array.k -o json_2_array.json, convert json result success!
get json file, ${workspace}/json_2_array.json:
{
"cm": {
"classname": "一年级一班",
"students": [
[
{
"name": "xiaoming",
"age": 6
},
{
"name": "xiaohua",
"age": 5
}
],
[
{
"name": "xiaohong",
"age": 6
}
]
]
}
}
Then, execute kcl import -m json json_2_array.json -o json_2_import.k -p ./models/, convert json data to KCL data
2. What did you expect to see? (Required)
I hope convert models like json_2_array.k
maybe like:
"""
This file was generated by the KCL auto-gen tool. DO NOT EDIT.
Editing this file might prove futile when you re-run the KCL auto-gen generate command.
"""
# question1: I hope the generated KCL data can automatically include the imported model relationships.
import models.class_models as c
classmate = c.classmate {
classname = "一年级一班"
# question2: I hope to support the import of two-dimensional arrays.
students = [
[
c.student {
name = "xiaoming"
age = 6
},
c.student {
name = "xiaohua"
age = 5
},
],
[
c.student {
name = "xiaohong"
age = 6
},
]
]
}
3. What did you see instead (Required)
it(kcl import json_2_array.json -o json_2_import.k --force) works, but I get json_2_import.k is :
"""
This file was generated by the KCL auto-gen tool. DO NOT EDIT.
Editing this file might prove futile when you re-run the KCL auto-gen generate command.
"""
{
classmate = {
classname = "一年级一班"
students = [
[{"name" = "xiaoming", "age" = 6}[{Key = "name", Value = "xiaoming"}, {Key = "age", Value = 6}], {"name" = "xiaohua", "age" = 5}[{Key = "name", Value = "xiaohua"}, {Key = "age", Value = 5}]]
[{"name" = "xiaohong", "age" = 6}[{Key = "name", Value = "xiaohong"}, {Key = "age", Value = 6}]]
]
}
}
looks like two-dimensional arrays not work.
4. What is your KCL components version? (Required)
kcl version 0.12.3
BTW:
ust kcl import, convert (json, yaml...)data to KCL data, Can the generated KCL data file automatically identify the dependent models and supplement the import information?
pseudocode:
1、design models in ${workspace}/models/
2、file.k which import models.xxx as x, then use model x.yyy, the file.k define custom default value.
3、kcl file.k --format json, get file_1.json, use to parsing and generating UIs, give to customer configuration.
4、after step3, UI -> file_2.json, which contains custom's modify. I can use kcl import file_2.json -o file_2.k. get KCL data. I hope save file.k and file_2.k, if Show in UI's, just kcl run it again.
All of this, If file.k, execute run get file.json, then execute kcl import get file_import.k, file.k == file.import.k (Is this possible?), then run file_import.k -> file_import.json, file_import.json == file.json.
No data will be lost through any of these conversions.(Include Import Imported Dependencies)