The diagrams in https://linkml.io/linkml-model/docs/SchemaDefinition/ and https://linkml.io/linkml-model/docs/ClassDefinition/ show no operations.
Since i didn't find an add operation i am accessing the classes dict directly.
Is this approach of adding classes to a SchemaDefinition the "official" way?
'''
Created on 2023-02-20
@author: wf
'''
from meta.metamodel import Context
from linkml_runtime.linkml_model import SchemaDefinition, ClassDefinition
import yaml
class SiDIF2LinkML:
"""
converter between SiDIF and LINKML
"""
def __init__(self,context:Context):
self.context=context
def asYaml(self)->str:
"""
convert my context
"""
# https://linkml.io/linkml-model/docs/SchemaDefinition/
sd=SchemaDefinition(id=self.context.name,name=self.context.name)
for topic in self.context.topics.values():
cd=ClassDefinition(name=topic.name)
sd.classes[topic.name]=cd
pass
yaml_text=yaml.dump(self.context.did)
return yaml_text
sd.classes[topic.name]=cd

Yes, this is currently the canonical way to do this. The LinkML python framework generates dataclasses that intentionally avoid any behavior, including getters and setters, and this applies to the metamodel as well as any domain models. There is a valid use case for adding helper behavior for collections, we opened an issue for this here: https://github.com/linkml/linkml/issues/1302