|
9 | 9 | SPECIAL_FIELD_FLAG = "__"
|
10 | 10 | EXTENDS_FIELD = SPECIAL_FIELD_FLAG+"extends"
|
11 | 11 |
|
12 |
| - |
| 12 | +def set_type(object, to_type): |
| 13 | + # TODO: implement type serialization |
| 14 | + return object |
13 | 15 | def load_json_as_dict(file_name):
|
14 | 16 | with open(file_name, "r") as f:
|
15 | 17 | return json.load(f)
|
@@ -67,16 +69,25 @@ def cosntruct_replace(main_object, arg_replace, value):
|
67 | 69 | response_json[attribute_new_name] = attribute_new_value
|
68 | 70 | return response_json
|
69 | 71 | 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") |
71 | 73 | response_json = copy.deepcopy(json_dict)
|
72 | 74 | args_to_check = copy.deepcopy(args)
|
73 | 75 | args_to_check.pop(SPECIAL_FIELD_FLAG+"from")
|
74 | 76 | if SPECIAL_FIELD_FLAG+"excludes" in args_to_check:
|
75 | 77 | args_to_check.pop(SPECIAL_FIELD_FLAG+"excludes")
|
76 | 78 | if SPECIAL_FIELD_FLAG+"includes" in args_to_check:
|
77 | 79 | 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]) |
80 | 91 | response_json = new_value
|
81 | 92 | return response_json
|
82 | 93 | def special_flags_processing(json_dict, *, args = {}, base_folder=None, base_dict={}, object_route=""):
|
|
0 commit comments