@@ -69,6 +69,24 @@ def prune_properties_if_not_exist_in_path(output_model, input_model, paths):
69
69
return output_document ["properties" ]
70
70
71
71
72
+ def prune_properties_which_dont_exist_in_path (model , paths ):
73
+ """Prunes model to properties present in path. This method removes any property
74
+ from the model which does not exists in the paths
75
+
76
+ This assumes properties will always have an object (dict) as a parent.
77
+ The function returns the model after pruning all but the path which exists
78
+ in the paths tuple from the input_model
79
+ """
80
+ document = {"properties" : model .copy ()}
81
+ for model_path in model .keys ():
82
+ path_tuple = ("properties" , model_path )
83
+ if path_tuple not in paths :
84
+ _prop , resolved_path , parent = traverse (document , path_tuple )
85
+ key = resolved_path [- 1 ]
86
+ del parent [key ]
87
+ return document ["properties" ]
88
+
89
+
72
90
def path_exists (document , path ):
73
91
try :
74
92
_prop , _resolved_path , _parent = traverse (document , path )
@@ -426,7 +444,12 @@ def generate_update_example(self, create_model):
426
444
if self .create_only_paths :
427
445
self .validate_update_example_keys (unique_identifiers , update_example )
428
446
update_example .update (unique_identifiers )
429
- return update_example
447
+ create_model_with_read_only_properties = (
448
+ prune_properties_which_dont_exist_in_path (
449
+ create_model , self .read_only_paths
450
+ )
451
+ )
452
+ return {** create_model_with_read_only_properties , ** update_example }
430
453
overrides = self ._overrides .get ("UPDATE" , self ._overrides .get ("CREATE" , {}))
431
454
example = override_properties (self .update_strategy .example (), overrides )
432
455
return {** create_model , ** example }
0 commit comments