Skip to content
Snippets Groups Projects

Draft: F json schema

Open Alexander Schlemmer requested to merge f-json-schema into dev

Files

@@ -17,10 +17,12 @@ Parents can be provided under the 'inherit_from_xxxx' keywords. The value needs
@@ -17,10 +17,12 @@ Parents can be provided under the 'inherit_from_xxxx' keywords. The value needs
to be a list with the names. Here, NO NEW entities can be defined.
to be a list with the names. Here, NO NEW entities can be defined.
"""
"""
import re
import re
 
import os
import sys
import sys
import caosdb as db
import caosdb as db
import yaml
import yaml
 
from jsonschema import validate
from .data_model import DataModel
from .data_model import DataModel
@@ -128,6 +130,8 @@ class Parser(object):
@@ -128,6 +130,8 @@ class Parser(object):
with open(filename, 'r') as outfile:
with open(filename, 'r') as outfile:
ymlmodel = yaml.load(outfile, Loader=SafeLineLoader)
ymlmodel = yaml.load(outfile, Loader=SafeLineLoader)
 
self._validate(ymlmodel)
 
return self._create_model_from_dict(ymlmodel)
return self._create_model_from_dict(ymlmodel)
def parse_model_from_string(self, string):
def parse_model_from_string(self, string):
@@ -144,9 +148,21 @@ class Parser(object):
@@ -144,9 +148,21 @@ class Parser(object):
The created DataModel
The created DataModel
"""
"""
ymlmodel = yaml.load(string, Loader=SafeLineLoader)
ymlmodel = yaml.load(string, Loader=SafeLineLoader)
 
self._validate(ymlmodel)
return self._create_model_from_dict(ymlmodel)
return self._create_model_from_dict(ymlmodel)
 
def _validate(self, valobj):
 
"""Run validation of the profile against schema-model.yml residing
 
in the linkahead script folder.
 
 
"""
 
 
with open(os.path.join(os.path.dirname(__file__), "schema-model.yml")) as f:
 
schema = yaml.load(f, Loader=yaml.SafeLoader)
 
validate(instance=valobj,
 
schema=schema)
 
def _create_model_from_dict(self, ymlmodel):
def _create_model_from_dict(self, ymlmodel):
"""Create and return a data model out of the YAML dict `ymlmodel`.
"""Create and return a data model out of the YAML dict `ymlmodel`.
Loading