Resolve "m_to_json_schema fails with self referential subsections"
Closes #2584 (closed)
Added handling for self referencing nomad sections by preventing recursion for sections which already have definitions, and added a test for it.
baseclasses.solution.Solution.m_def.m_to_json_schema() no longer results in a recursion error and gives a valid jsonschema.
Also tested data validation using the json schema:
import jsonschema
from nomad.metainfo.metainfo import MSection, Quantity, Section, SubSection, SectionProxy
class SectionWithSelfReference(MSection):
m_def = Section(description='Test MSection with self reference.')
quantity = Quantity(type=str, description='Quantity for test.')
subsection = SubSection(sub_section=SectionProxy('SectionWithSelfReference'), repeats=False)
schema=SectionWithSelfReference.m_def.m_to_json_schema()
jsonschema.Draft202012Validator.check_schema(schema)
data=SectionWithSelfReference.m_from_dict({'quantity':'test1','subsection':{'quantity':'test2'}})
jsonschema.validate(data.m_to_dict(),schema)
Edited by Sharat Patil