def check_schema(self, filename): try: tableschema.validate(self.filepath(filename)) except tableschema.exceptions.ValidationError as e: errors = "; ".join([repr(e) for e in e.errors]) message = "Schema %s is not a valid TableSchema schema. Errors: %s" % ( filename, errors, ) raise exceptions.InvalidSchemaException(self.repo, message) except: message = "Schema %s is not a valid TableSchema schema." % ( filename ) raise exceptions.InvalidSchemaException(self.repo, message)
def check_schema(self, filename): try: _ = self.schema_data except yaml.error.YAMLError as e: message = "Yaml file not valid. Error: %s" % ( repr(e), ) raise exceptions.InvalidSchemaException(self.repo, message)
def check_extra_keys(self): keys = ["title", "description", "homepage", "version"] for key in [k for k in keys if k not in self.schema_data]: message = "Key `%s` is a required key and is missing from %s" % ( key, self.SCHEMA_FILENAME, ) raise exceptions.InvalidSchemaException(self.repo, message)
def check_schema(self, path, title): try: etree.XMLSchema(etree.parse(self.filepath(path))) except Exception as e: message = "XSD schema %s at `%s` is not valid. Errors: %s" % ( title, path, repr(e), ) raise exceptions.InvalidSchemaException(self.repo, message)
def check_schema(self, path, title): try: with open(self.filepath(path)) as f: schema_data = json.load(f) validator = jsonschema.validators.validator_for(schema_data) validator.check_schema(schema_data) except Exception as e: message = "JSON Schema %s at `%s` is not valid. Errors: %s" % ( title, path, repr(e), ) raise exceptions.InvalidSchemaException(self.repo, message)
def validate(self): super(XsdSchemaValidator, self).validate() self.check_file_exists("schemas.yml") try: with open(self.filepath("schemas.yml"), "r") as f: config = yaml.safe_load(f) self.schemas_config = config["schemas"] self.title = config["title"] self.description = config["description"] self.homepage = config["homepage"] for schema in config["schemas"]: self.check_schema(schema["path"], schema["title"]) except Exception as e: message = "`schemas.yml` has not the required format: " + repr(e) raise exceptions.InvalidSchemaException(self.repo, message)