Last active
November 27, 2017 18:02
-
-
Save eagafonov/01014d9b1bd41eb2f0dcaeb4c31bba0b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example with https://github.com/eagafonov/json_schema_helpers | |
import json_schema_helpers as jsh | |
heading_loc_schema = { | |
"$schema": "http://json-schema.org/draft-04/schema#", | |
"title": "heading_loc object", | |
"type": "object", | |
"additionalProperties": False, # properties must contains a complete list of supported languages | |
"properties": { | |
"en": jsh.ref_id("lang_obj"), # Refernece to `/definitions/lang_obj` | |
"de": jsh.ref_id("lang_obj"), | |
# Add more language properties as `"lng": jsh.ref_id("lang")` | |
}, | |
"definitions": { | |
# definition for Language object | |
"lang_obj": { | |
"type": "object", | |
"additionalProperties": False, | |
"properties": { | |
"type": jsh.string, | |
"default": jsh.string, | |
} | |
} | |
} | |
} | |
# validate something | |
import json | |
import jsonschema | |
object2validate = '''{ | |
"type": "object", | |
"properties": { | |
"cz": { | |
"type": "string", | |
"default": "" | |
}, | |
"de": { | |
"type": "string", | |
"default": "" | |
}, | |
"en": { | |
"type": "string", | |
"default": "" | |
} | |
} | |
}''' | |
jsonschema.validate(json.loads(object2validate), heading_loc_schema) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment