linkml / schema-automator

Automated assistance for the schema development lifecycle
https://linkml.io/schema-automator/
BSD 3-Clause "New" or "Revised" License
33 stars 12 forks source link

Write a pydantic-importer (pydantic class -> LinkML YAML) #88

Open cmungall opened 1 year ago

cmungall commented 1 year ago

From discussion with @ialarmedalien on slack

Approach 1: can convert to json schema and convert from that https://pydantic-docs.helpmanual.io/usage/schema/ --- but that’s not very satisfactory as there would be loss eg inheritance

Approach 2: write something specific to pydantic using https://pydantic-docs.helpmanual.io/usage/exporting_models/

ialarmedalien commented 1 year ago

It would be preferable to avoid using the Schema Builder to assemble a set of classes and fields as other formats do, because we already have the class/field set up via pydantic or dataclasses.

Ideally there would be a generator to output an object/class as linkml, so that converting a schema comprising pydantic (or dataclass) classes would be a matter of running the classes through the generator / mixing the generator function into the classes / whatever specific mechanism was chosen. A simple solution could be having the classes be subclasses of YAMLRoot, but without a way to save the transformed schema as linkml, you'd have to do this transform every time you worked with that schema and you would not have the rest of the linkml tools to play with.