def build_resource_params(api_info, all_models, custom_configs): properties = mm_param.build(api_info["get"]["body"], all_models) for _, v in properties.items(): v.traverse(lambda n: _set_property(n, {"crud": "r", "required": None})) print("------ start to merge create parameters to get ------") r = mm_param.build(api_info["create"]["body"], all_models) parameters = _build_create_params(properties, r, custom_configs) if "update" in api_info: print("------ start to merge update parameters to get ------") r = mm_param.build(api_info["update"]["body"], all_models) _build_update_params(properties, parameters, r, custom_configs) def _output(n): p = n.parent if n.get_item("crud") == 'r' and (p is None or p.get_item("crud") != 'r'): n.set_item("output", True) for k, v in properties.items(): v.traverse(_output) return properties, parameters
def _build_params(api_info, all_models): read = mm_param.build(api_info["read"]["body"], all_models) for v in read.values(): v.traverse(lambda n: _set_property(n, "r", {"required": None})) create = mm_param.build(api_info["create"]["body"], all_models) for v in create.values(): v.traverse(lambda n: _set_property(n, 'c')) update = None if "update" in api_info: update = mm_param.build(api_info["update"]["body"], all_models) for k, v in update.items(): v.traverse( lambda n: _set_property(n, "u", {"required": None})) return create, update, read
def build_mm_params(doc_dir): structs = word_to_params(doc_dir + "get.docx") struct = structs.get('get_rsp') if struct is None: raise Exception( "The struct name of get response should be \'get_rsp\'") properties = mm_param.build(struct, structs) for _, v in properties.items(): v.traverse(lambda n: n.set_item("crud", "r")) f = doc_dir + "create_rsp.docx" if os.path.exists(f): structs = word_to_params(f) struct = structs.get("create_rsp") if struct is None: raise Exception( "The struct name of create response should be \'create_rsp\'") create_rsp = mm_param.build(struct, structs) for k, v in create_rsp.items(): if k not in properties: v.set_item("output", True) properties[k] = v # check the items with same key f = doc_dir + "update_rsp.docx" if os.path.exists(f): structs = word_to_params(f) struct = structs.get("update_rsp") if struct is None: raise Exception( "The struct name of update response should be \'update_rsp\'") update_rsp = mm_param.build(struct, structs) for k, v in update_rsp.items(): if k not in properties: v.set_item("output", True) properties[k] = v # check the items with same key structs = word_to_params(doc_dir + "create.docx") struct = structs.get("CreateOpts") if struct is None: raise Exception( "The struct name of create request should be \'create\'") print("------ start to merge create parameters to get ------") r = mm_param.build(struct, structs) parameters = {} for k, v in r.items(): v.traverse(lambda n: n.set_item("crud", 'c')) if k in properties: properties[k].merge(v, _merge_create_to_get, mm_param.Merge_Level_Root) else: v.set_item("input", True) parameters[k] = v f = doc_dir + "update.docx" if os.path.exists(f): structs = word_to_params(f) struct = structs.get("UpdateOpts") if struct is None: raise Exception( "The struct name of update request should be \'update\'") print("------ start to merge update parameters to get ------") r = mm_param.build(struct, structs) for k, v in r.items(): v.traverse(lambda n: n.set_item("crud", 'u')) if k in properties: properties[k].merge(v, _merge_update_to_get, mm_param.Merge_Level_Root) elif k in parameters: parameters[k].merge(v, _merge_update_to_create, mm_param.Merge_Level_Root) else: parameters[k] = v def output(n): p = n.parent if n.get_item("crud") == 'r' and (p is None or p.get_item("crud") != 'r'): n.set_item("output", True) for k, v in properties.items(): v.traverse(output) return properties, parameters
def build_mm_params(doc_dir): structs = word_to_params(doc_dir + "get.docx") struct = structs.get('get_rsp') if struct is None: raise Exception( "The struct name of get response should be \'get_rsp\'") properties = mm_param.build(struct, structs) for _, v in properties.items(): v.set_item("Computed", True) f = doc_dir + "create_rsp.docx" if os.path.exists(f): structs = word_to_params(f) struct = structs.get("create_rsp") if struct is None: raise Exception( "The struct name of create response should be \'create_rsp\'") create_rsp = mm_param.build(struct, structs) for k, v in create_rsp.items(): if k not in properties: v.set_item("Computed", True) properties[k] = v # check the items with same key f = doc_dir + "update_rsp.docx" if os.path.exists(f): structs = word_to_params(f) struct = structs.get("update_rsp") if struct is None: raise Exception( "The struct name of update response should be \'update_rsp\'") update_rsp = mm_param.build(struct, structs) for k, v in update_rsp.items(): if k not in properties: v.set_item("Computed", True) properties[k] = v # check the items with same key structs = word_to_params(doc_dir + "create.docx") struct = structs.get("CreateOpts") if struct is None: raise Exception( "The struct name of create request should be \'create\'") print("------ start to merge create parameters to get ------") r = mm_param.build(struct, structs) parameters = {} for k, v in r.items(): v.set_item("create_update", 'c') if k in properties: properties[k].merge(v, _create_merge_to_get) else: parameters[k] = v f = doc_dir + "update.docx" if os.path.exists(f): structs = word_to_params(f) struct = structs.get("UpdateOpts") if struct is None: raise Exception( "The struct name of update request should be \'update\'") print("------ start to merge update parameters to get ------") r = mm_param.build(struct, structs) for k, v in r.items(): v.set_item("create_update", 'u') if k in properties: properties[k].merge(v, _update_merge_to_get) else: parameters[k] = v return properties, parameters