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

Method create_class_for_schema

scripts/openapi.py:3008–3048  ·  view source on GitHub ↗
(
        self,
        github_path: str,
        spec_file: str,
        index_filename: str,
        spec: dict[str, Any],
        classes: dict[str, Any],
        tests: bool,
        schema: str,
    )

Source from the content-addressed store, hash-verified

3006 return True
3007
3008 def create_class_for_schema(
3009 self,
3010 github_path: str,
3011 spec_file: str,
3012 index_filename: str,
3013 spec: dict[str, Any],
3014 classes: dict[str, Any],
3015 tests: bool,
3016 schema: str,
3017 ) -> None:
3018 item = schema.split("/")[-1]
3019 if item.startswith("_"):
3020 return None
3021 new_class_name = "".join([term[0].upper() + term[1:] for term in re.split("[-_]", item)])
3022 if new_class_name in classes:
3023 # we probably created that class in an earlier iteration, or we have a name collision here
3024 return
3025 is_completable = "url" in self.get_schema(spec, schema)[1].get("properties", [])
3026 parent_name = "CompletableGithubObject" if is_completable else "NonCompletableGithubObject"
3027 # TODO: get path from schema via indices.path_to_return_classes, get docs from spec.paths.PATH.get.externalDocs.url
3028 docs_url = "https://docs.github.com/en/rest"
3029 print(f"Drafting class {new_class_name} for new schema {schema}")
3030 self.create_class(
3031 github_path,
3032 spec_file,
3033 index_filename,
3034 new_class_name,
3035 parent_name,
3036 docs_url,
3037 [schema],
3038 dry_run=False,
3039 tests=tests,
3040 handle_new_schemas=HandleNewSchemas.create_class,
3041 )
3042
3043 # update index
3044 self.index(github_path, spec_file, index_filename, check_verbs=False, dry_run=False)
3045 with open(index_filename) as r:
3046 index = json.load(r)
3047 classes.clear()
3048 classes.update(**index.get("classes", {}))
3049
3050 def create_method(
3051 self,

Callers 2

applyMethod · 0.95
create_new_classMethod · 0.95

Calls 6

get_schemaMethod · 0.95
create_classMethod · 0.95
indexMethod · 0.95
getMethod · 0.80
loadMethod · 0.80
updateMethod · 0.45

Tested by

no test coverage detected