MCPcopy Index your code
hub / github.com/PyGithub/PyGithub / suggest_method_names

Method suggest_method_names

scripts/openapi.py:2523–2567  ·  view source on GitHub ↗
(self, verb: str, prefix_path: str, path: str, spec: dict[str, Any])

Source from the content-addressed store, hash-verified

2521 print()
2522
2523 def suggest_method_names(self, verb: str, prefix_path: str, path: str, spec: dict[str, Any]) -> list[str]:
2524 suffix_path = path.replace("-", "_")[len(prefix_path) + 1 :]
2525 fields = suffix_path.split("/")
2526 context = "_".join(fields[:-1])
2527 last_field = fields[-1]
2528
2529 # download API paths respond with a 302 status and a Location header
2530 responses = spec.get("paths", {}).get(path, {}).get(verb, {}).get("responses", {})
2531 if sorted(list(responses.keys()))[0] == "302" and "Location" in responses.get("302").get("headers", {}):
2532 return ["download", "get_download_link"]
2533
2534 # verb == "get": get_ method on the nearst object
2535 # verb == "patch": .edit method on the object that is constructed by the url (get)
2536 # verb == "put": .set_ method on the nearst object
2537 # verb == "post": .create_ method on the nearst object
2538 # verb == "delete": .delete method on the object that is constructed by the url (get)
2539 if verb == "post":
2540 actions = ["create", ""]
2541 elif verb == "put":
2542 actions = ["set"]
2543 else:
2544 actions = [verb]
2545
2546 method_names = []
2547 for action in actions:
2548 action = f"{action}_" if action else ""
2549 context = f"{context}_" if context else ""
2550 if last_field.startswith("{") and last_field.endswith("}"):
2551 last_field = last_field[1:-1]
2552 if last_field.endswith("_id"):
2553 method_names.append(f"{action}{context}{last_field[:-3]}(id)")
2554 continue
2555 if len(fields) > 1 and not fields[-2].startswith("{"):
2556 object_name = fields[-2]
2557 if object_name.endswith("es"):
2558 object_name = object_name[:-2]
2559 elif object_name.endswith("s"):
2560 object_name = object_name[:-1]
2561 method_names.append(f"{action}{context}{object_name}({last_field})")
2562 continue
2563 method_names.append(f"{action}{context}({last_field})")
2564 continue
2565 method_names.append(f"{action}{context}{fields[-1]}")
2566
2567 return method_names
2568
2569 def suggest_schemas(
2570 self, spec_file: str, index_filename: str, class_names: list[str] | None, add: bool, dry_run: bool

Callers 1

suggest_pathsMethod · 0.95

Calls 1

getMethod · 0.80

Tested by

no test coverage detected