| 1926 | |
| 1927 | |
| 1928 | class OpenApi: |
| 1929 | def __init__(self, args: argparse.Namespace): |
| 1930 | self.args = args |
| 1931 | self.subcommand = args.subcommand |
| 1932 | self.dry_run = args.dry_run |
| 1933 | self.verbose = args.verbose |
| 1934 | |
| 1935 | index = ( |
| 1936 | OpenApi.read_json(args.index_filename) if self.subcommand != "index" and "index_filename" in args else {} |
| 1937 | ) |
| 1938 | self.classes = index.get("classes", {}) |
| 1939 | self.schema_to_class = index.get("indices", {}).get("schema_to_classes", {}) |
| 1940 | self.schema_to_class["default"] = ["GithubObject"] |
| 1941 | self.spec = OpenApi.read_json(args.spec) if "spec" in args and self.subcommand not in ["fetch", "index"] else {} |
| 1942 | self.ignored_schemas = set(index.get("config", {}).get("ignored_schemas", {})) |
| 1943 | |
| 1944 | def as_python_type( |
| 1945 | self, |
| 1946 | schema_type: dict[str, Any], |
| 1947 | schema_path: list[str], |
| 1948 | *, |
| 1949 | collect_new_schemas: list[str] | None = None, |
| 1950 | ) -> PythonType | GithubClass | None: |
| 1951 | return as_python_type( |
| 1952 | schema_type, |
| 1953 | schema_path, |
| 1954 | self.schema_to_class, |
| 1955 | self.classes, |
| 1956 | self.spec, |
| 1957 | verbose=self.verbose, |
| 1958 | collect_new_schemas=collect_new_schemas, |
| 1959 | ) |
| 1960 | |
| 1961 | @staticmethod |
| 1962 | def read_json(filename: str) -> dict[str, Any]: |
| 1963 | with open(filename) as r: |
| 1964 | return json.load(r) |
| 1965 | |
| 1966 | @staticmethod |
| 1967 | def get_schema(spec: dict[str, Any], path: str) -> (list[str], dict[str, Any]): |
| 1968 | steps = [] |
| 1969 | source_path = path.strip("/") |
| 1970 | while True: |
| 1971 | if source_path.startswith('"'): |
| 1972 | if '"' not in source_path[1:]: |
| 1973 | raise ValueError(f"Unclosed quote in path: {path}") |
| 1974 | start = source_path.index('"', 1) |
| 1975 | if "/" not in source_path[start:]: |
| 1976 | steps.append(source_path) |
| 1977 | break |
| 1978 | split = source_path[start:].index("/") + start |
| 1979 | step = source_path[1 : split - 1] |
| 1980 | source_path = source_path[split + 1 :] |
| 1981 | else: |
| 1982 | if "/" not in source_path: |
| 1983 | steps.append(source_path) |
| 1984 | break |
| 1985 | step, source_path = source_path.split("/", maxsplit=1) |
no outgoing calls
no test coverage detected
searching dependent graphs…