How to use the cjio.validation.validate_against_schema function in cjio

To help you get started, we’ve selected a few cjio examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cityjson / cjio / cjio / cityjson.py View on Github external
def validate(self, skip_schema=False, folder_schemas=None):
        #-- only latest version, otherwise a mess with versions and different schemas
        #-- this is it, sorry people
        if (self.j["version"] != CITYJSON_VERSIONS_SUPPORTED[-1]):
            return (False, False, ["Only files with version v%s can be validated." % (CITYJSON_VERSIONS_SUPPORTED[-1])], "")
        es = []
        ws = []
        #-- 1. schema
        if skip_schema == False:
            print ('-- Validating the syntax of the file')
            b, js, v = self.fetch_schema(folder_schemas)
            if b == False:
                return (False, False, ["Can't find the schema."], [])
            else:
                print ('\t(using the schemas %s)' % (v))
                isValid, errs = validation.validate_against_schema(self.j, js)
                if (isValid == False):
                    es += errs
                    return (False, False, es, [])
        #-- 2. schema for Extensions
        if "extensions" in self.j:
            b, es = self.validate_extensions(folder_schemas)
            if b == False:
                return (b, True, es, [])


        #-- 3. ERRORS
        print ('-- Validating the internal consistency of the file (see docs for list)')
        isValid = True

        if float(self.j["version"]) == 0.6:
            b, errs = validation.building_parts(self.j)
github cityjson / cjio / cjio / cityjson.py View on Github external
return (False, ["Schema file '%s' can't be found" % s])
            js = json.loads(open(schemapath).read())

            #-- 1. extraCityObjects
            if "extraCityObjects" in js:
                for nco in js["extraCityObjects"]:
                    allnewco.add(nco)
                    jtmp = {}
                    jtmp["$schema"] = "http://json-schema.org/draft-07/schema#"
                    jtmp["type"] = "object"
                    jtmp["$ref"] = "file://%s#/extraCityObjects/%s" % (schemapath, nco)
                    jsotf = jsonref.loads(json.dumps(jtmp), jsonschema=True, base_uri=base_uri)
                    for theid in self.j["CityObjects"]:
                        if self.j["CityObjects"][theid]["type"] == nco:
                            nco1 = self.j["CityObjects"][theid]
                            v, errs = validation.validate_against_schema(nco1, jsotf)
                            if (v == False):
                                isValid = False
                                es += errs

            #-- 2. extraRootProperties
            if "extraRootProperties" in js:
                for nrp in js["extraRootProperties"]:
                    jtmp = {}
                    jtmp["$schema"] = "http://json-schema.org/draft-07/schema#"
                    jtmp["type"] = "object"
                    jtmp["$ref"] = "file://%s#/extraRootProperties/%s" % (schemapath, nrp)
                    jsotf = jsonref.loads(json.dumps(jtmp), jsonschema=True, base_uri=base_uri)
                    for p in self.j:
                        if p == nrp:
                            thep = self.j[p]
                            v, errs = validation.validate_against_schema(thep, jsotf)