MCPcopy
hub / github.com/PyGithub/PyGithub / create_method

Method create_method

scripts/openapi.py:1695–1872  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1693 return (function_name,)
1694
1695 def create_method(self) -> cst.FunctionDef:
1696 url_params = [
1697 elem[1:-1] for elem in self.relative_path.split("/") if elem.startswith("{") and elem.endswith("}")
1698 ]
1699 if url_params:
1700 raise ValueError(f"URL parameter not implemented: {', '.join(url_params)}")
1701
1702 request_schema = (
1703 self.api.get("requestBody", {}).get("content", {}).get("application/json", {}).get("schema", None)
1704 )
1705 schema_path = (
1706 "paths",
1707 self.api_path,
1708 self.api_verb,
1709 "requestBody",
1710 "content",
1711 "application/json",
1712 "schema",
1713 "properties",
1714 )
1715 request_properties = (
1716 {
1717 prop: as_python_type(
1718 desc, list(schema_path + (prop,)), self.schema_to_class, self.classes, self.spec, verbose=True
1719 )
1720 for prop, desc in request_schema.get("properties", {}).items()
1721 }
1722 if request_schema
1723 else {}
1724 )
1725 required_properties = request_schema.get("required") if request_schema else []
1726 # TODO: ignore parameters:
1727 # - those covered by prefix_path
1728 # - those referring to pagination
1729 # - add all others to method name, e.g dir in /repos/{owner}/{repo}/readme/{dir}
1730
1731 stmts = []
1732
1733 docstrings = []
1734 docstrings.append('"""')
1735 if self.api_docs:
1736 docstrings.append(f":calls: `{self.api_verb.upper()} {self.api_path} <{self.api_docs}>`_")
1737 else:
1738 docstrings.append(f":calls: {self.api_verb.upper()} {self.api_path}")
1739 for prop_name, prop_type in request_properties.items():
1740 docstrings.append(f":param {prop_name}: {prop_type}")
1741 if self.api_content:
1742 docstrings.append(f":rtype: {self.api_content}")
1743 if self.api_descr:
1744 docstrings.append("")
1745 docstrings.append(self.api_descr)
1746 docstrings.append('"""')
1747 docstring = "\n ".join(docstrings)
1748 stmts.append(cst.SimpleStatementLine([cst.Expr(cst.SimpleString(docstring))]))
1749
1750 assertion_stmts = [
1751 cst.SimpleStatementLine(
1752 body=[

Callers 1

leave_ClassDefMethod · 0.95

Calls 5

as_python_typeFunction · 0.85
PythonTypeClass · 0.85
getMethod · 0.80
create_typeMethod · 0.80
create_attributeMethod · 0.80

Tested by

no test coverage detected