keon94 commented on code in PR #4976: URL: https://github.com/apache/incubator-devlake/pull/4976#discussion_r1172958554
########## backend/python/pydevlake/pydevlake/extractor.py: ########## @@ -15,15 +15,45 @@ from typing import Type + +from jsonpointer import resolve_pointer, JsonPointerException + from pydevlake import ToolModel def autoextract(json: dict, model_cls: Type[ToolModel]) -> ToolModel: - annotations = dict(model_cls.__annotations__) - for key, value in json.items(): - if key in annotations: - expected_type = annotations[key] - if isinstance(expected_type, type) and issubclass(expected_type, ToolModel): - # TODO: replace with actual foreign key - json[key] = value["id"] - return model_cls(**json) + """ + Automatically extract a tool model from a json object. + The tool model class can define fields with a source argument to specify the JSON pointer (RFC 6901) to the value. + + Example: + class DummyModel(ToolModel): + name: str + version: str = Field(source='/version/number') Review Comment: how would we specify array paths with this scheme? e.g. "/a/b/c[index]/d/e". -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
