Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
#-- 3. extraAttributes
if "extraAttributes" in js:
for thetype in js["extraAttributes"]:
for ea in js["extraAttributes"][thetype]:
jtmp = {}
jtmp["$schema"] = "http://json-schema.org/draft-07/schema#"
jtmp["type"] = "object"
jtmp["$ref"] = "file://%s#/extraAttributes/%s/%s" % (schemapath, thetype, ea)
jsotf = jsonref.loads(json.dumps(jtmp), jsonschema=True, base_uri=base_uri)
for theid in self.j["CityObjects"]:
if ( (self.j["CityObjects"][theid]["type"] == thetype) and
("attributes" in self.j["CityObjects"][theid]) and
(ea in self.j["CityObjects"][theid]["attributes"]) ):
a = self.j["CityObjects"][theid]["attributes"][ea]
v, errs = validation.validate_against_schema(a, jsotf)
if (v == False):
isValid = False
es += errs
#-- 4. check if there are CityObjects that do not have a schema
for theid in self.j["CityObjects"]:
if ( (self.j["CityObjects"][theid]["type"][0] == "+") and
(self.j["CityObjects"][theid]["type"] not in allnewco) ):
s = "ERROR: CityObject " + self.j["CityObjects"][theid]["type"] + " doesn't have a schema."
es.append(s)
isValid = False
return (isValid, es)
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)
if (v == False):
isValid = False
es += errs
#-- 3. extraAttributes
if "extraAttributes" in js:
for thetype in js["extraAttributes"]:
for ea in js["extraAttributes"][thetype]:
jtmp = {}
jtmp["$schema"] = "http://json-schema.org/draft-07/schema#"
jtmp["type"] = "object"
jtmp["$ref"] = "file://%s#/extraAttributes/%s/%s" % (schemapath, thetype, ea)
jsotf = jsonref.loads(json.dumps(jtmp), jsonschema=True, base_uri=base_uri)
for theid in self.j["CityObjects"]:
if ( (self.j["CityObjects"][theid]["type"] == thetype) and
("attributes" in self.j["CityObjects"][theid]) and
def read(self, file, ignore_duplicate_keys=False):
if ignore_duplicate_keys == True:
self.j = json.loads(file.read())
else:
try:
self.j = json.loads(file.read(), object_pairs_hook=validation.dict_raise_on_duplicates)
except ValueError as err:
raise ValueError(err)
#-- a CityJSON file?
if "type" in self.j and self.j["type"] == "CityJSON":
pass
else:
self.j = {}
raise ValueError("Not a CityJSON file")