forked from elastic/ml-json-schemas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
validate.py
28 lines (23 loc) · 963 Bytes
/
validate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#
# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
# or more contributor license agreements. Licensed under the Elastic License;
# you may not use this file except in compliance with the Elastic License.
#
import jsonschema
from jsonschema.validators import Draft4Validator
import simplejson as json
import os
if __name__ == '__main__':
with open("schemas/model_definition.schema.json", 'r') as f:
data = f.read()
definition = json.loads(data)
validator = Draft4Validator(schema=definition)
validator.check_schema(definition)
with open("examples/ensemble_example.json", "r") as f:
example_data = f.read()
ensemble_example = json.loads(example_data)
validator.validate(ensemble_example, definition)
with open("examples/tree_example.json", "r") as f:
example_data = f.read()
tree_example = json.loads(example_data)
validator.validate(tree_example, definition)