Skip to content

Commit 06533c4

Browse files
constructor default values
1 parent 692e23b commit 06533c4

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

blueprints/global/communication/chat/models/message.model.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"__constructor":{
33
"user":{
4-
"description":"user to be used"
4+
"type":"str",
5+
"description":"route to user to be used"
56
}
67
},
78
"attributes":{

compiler/json_compiler/Compiler.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
SPECIAL_FIELD_FLAG = "__"
1010
EXTENDS_FIELD = SPECIAL_FIELD_FLAG+"extends"
1111

12-
12+
def set_type(object, to_type):
13+
# TODO: implement type serialization
14+
return object
1315
def load_json_as_dict(file_name):
1416
with open(file_name, "r") as f:
1517
return json.load(f)
@@ -67,16 +69,25 @@ def cosntruct_replace(main_object, arg_replace, value):
6769
response_json[attribute_new_name] = attribute_new_value
6870
return response_json
6971
def cosntructor(json_dict, *, args = {}, object_route=""):
70-
json_dict.pop(SPECIAL_FIELD_FLAG+"constructor")
72+
constructor_dict = json_dict.pop(SPECIAL_FIELD_FLAG+"constructor")
7173
response_json = copy.deepcopy(json_dict)
7274
args_to_check = copy.deepcopy(args)
7375
args_to_check.pop(SPECIAL_FIELD_FLAG+"from")
7476
if SPECIAL_FIELD_FLAG+"excludes" in args_to_check:
7577
args_to_check.pop(SPECIAL_FIELD_FLAG+"excludes")
7678
if SPECIAL_FIELD_FLAG+"includes" in args_to_check:
7779
args_to_check.pop(SPECIAL_FIELD_FLAG+"includes")
78-
for arg in args:
79-
new_value = cosntruct_replace(response_json, SPECIAL_FIELD_FLAG+arg, args[arg])
80+
for arg_to_check in args_to_check:
81+
if arg_to_check not in constructor_dict:
82+
CustomLogging.warning(f"error in constructor: invalid parameter {arg_to_check}")
83+
else:
84+
constructor_dict.pop(arg_to_check) # remove argument so we know it already was defined
85+
for default_attribute in constructor_dict:
86+
if default_attribute.startswith(SPECIAL_FIELD_FLAG):
87+
continue
88+
args_to_check[default_attribute] = set_type(constructor_dict[default_attribute]["default"], constructor_dict[default_attribute]["type"])
89+
for arg in args_to_check:
90+
new_value = cosntruct_replace(response_json, SPECIAL_FIELD_FLAG+arg, args_to_check[arg])
8091
response_json = new_value
8192
return response_json
8293
def special_flags_processing(json_dict, *, args = {}, base_folder=None, base_dict={}, object_route=""):

compiler/sample_blueprints/samples/construct.app.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
"__extends":{
66
"__from":"utils.models.human",
77
"name":"nombre",
8-
"birth":"nacimiento",
9-
"sector":"sector"
8+
"birth":"nacimiento"
109
}
1110
}
1211
},

compiler/sample_blueprints/samples/utils/models/human.model.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2+
"__description": "a human model",
23
"__constructor":{
3-
"__description": "a human model",
44
"name":{"type":"str", "default":"name"},
5-
"birth":{"type":"date", "default":"birth"},
5+
"birth":{"type":"str", "default":"birth"},
66
"sector":{"type":"str", "default":"sector"}
77
},
88
"attributes":{

0 commit comments

Comments
 (0)