Browse Source

minor fix in schema dereferencing: solved the problem with ' in schemas

tanja 4 years ago
parent
commit
97e3e26d61
1 changed files with 5 additions and 6 deletions
  1. 5 6
      cdplib/db_migration/ParseJsonSchema.py

+ 5 - 6
cdplib/db_migration/ParseJsonSchema.py

@@ -49,9 +49,8 @@ class ParseJsonSchema(ParseDbSchema):
         for schema_path in schema_paths:
             try:
                 with open(schema_path, "r") as f:
-                   schema = json.load(f)
                 # Load schmea dereferenced and cleaned by default values
-                self.schemas.append(self._dereference_schema(schema))
+                self.schemas.append(self._dereference_schema(schema_path))
 
             except Exception as e:
                 err = ("Could not load json schema {0}, "
@@ -331,16 +330,16 @@ class ParseJsonSchema(ParseDbSchema):
 
         return already_parsed
 
-    def _dereference_schema(self, schema: dict) -> dict:
+    def _dereference_schema(self, schema_path: str) -> dict:
         '''
         :param dict schema: dictionary containing a schema which uses references.
         '''
 
-        assert(isinstance(schema, dict)),\
-            "Parameter 'schema' must be a dictionary type"
+        assert(isinstance(schema_path, str)),\
+            "Parameter 'schema_path' must be a string type"
 
         base_dir_url = Path(os.path.join(os.getcwd(), "mongo_schema")).as_uri() + '/'
-        schema = jsonref.loads(str(schema).replace("'", "\""), base_uri=base_dir_url)
+        schema = jsonref.loads(open(schema_path,"r").read(), base_uri=base_dir_url)
         schema = deepcopy(schema)
         schema.pop('definitions', None)
         return schema