|
@@ -51,15 +51,17 @@ class ParseJsonSchema(ParseDbSchema):
|
|
with open(schema_path, "r") as f:
|
|
with open(schema_path, "r") as f:
|
|
schema = json.load(f)
|
|
schema = json.load(f)
|
|
|
|
|
|
- ref_flag = self._analyze_schema(schema)
|
|
|
|
-
|
|
|
|
- if ref_flag:
|
|
|
|
- schema = self._format_schema_for_mongo(schema)
|
|
|
|
|
|
+ definitions_flag = self._analyze_schema(schema)
|
|
|
|
+
|
|
|
|
+ if definitions_flag:
|
|
|
|
+ schema = self._clean_desciptions_tags_from_single_quotes(schema)
|
|
schema = self._dereference_schema(schema)
|
|
schema = self._dereference_schema(schema)
|
|
- schema = self._format_schema_for_mongo(schema)
|
|
|
|
|
|
+ # Need to do it again since sub schema could also contain
|
|
|
|
+ # single quotes
|
|
|
|
+ schema = self._clean_desciptions_tags_from_single_quotes(schema)
|
|
self.schemas.append(schema)
|
|
self.schemas.append(schema)
|
|
|
|
+
|
|
else:
|
|
else:
|
|
- schema = self._format_schema_for_mongo(schema)
|
|
|
|
self.schemas.append(schema)
|
|
self.schemas.append(schema)
|
|
|
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
@@ -199,7 +201,7 @@ class ParseJsonSchema(ParseDbSchema):
|
|
required_only=required_only)
|
|
required_only=required_only)
|
|
|
|
|
|
for schema in schemas[1:]:
|
|
for schema in schemas[1:]:
|
|
-
|
|
|
|
|
|
+
|
|
next_result = self._parse_one(schema=schema,
|
|
next_result = self._parse_one(schema=schema,
|
|
field_info=field_info,
|
|
field_info=field_info,
|
|
required_only=required_only)
|
|
required_only=required_only)
|
|
@@ -340,7 +342,7 @@ class ParseJsonSchema(ParseDbSchema):
|
|
|
|
|
|
return already_parsed
|
|
return already_parsed
|
|
|
|
|
|
- def read_schema_and_parse_for_mongodb(self, schema_path: str) -> dict:
|
|
|
|
|
|
+ def load_and_parse_schema_for_mongodb(self, schema_path: str) -> dict:
|
|
'''
|
|
'''
|
|
We need to deference json before import to Mongo DB pymongo can't deal with references
|
|
We need to deference json before import to Mongo DB pymongo can't deal with references
|
|
:param str schema_path: path to the schema file.
|
|
:param str schema_path: path to the schema file.
|
|
@@ -353,10 +355,15 @@ class ParseJsonSchema(ParseDbSchema):
|
|
schema = json.load(json_file)
|
|
schema = json.load(json_file)
|
|
|
|
|
|
definitions_flag = self._analyze_schema(schema)
|
|
definitions_flag = self._analyze_schema(schema)
|
|
-
|
|
|
|
|
|
+
|
|
if definitions_flag:
|
|
if definitions_flag:
|
|
- schema = self._format_schema_for_mongo(schema)
|
|
|
|
|
|
+ schema = self._clean_desciptions_tags_from_single_quotes(schema)
|
|
schema = self._dereference_schema(schema)
|
|
schema = self._dereference_schema(schema)
|
|
|
|
+ # Need to do it again since sub schema could also contain
|
|
|
|
+ # single quotes
|
|
|
|
+ schema = self._clean_desciptions_tags_from_single_quotes(schema)
|
|
|
|
+ schema = self._format_schema_for_mongo(schema)
|
|
|
|
+ else:
|
|
schema = self._format_schema_for_mongo(schema)
|
|
schema = self._format_schema_for_mongo(schema)
|
|
|
|
|
|
return schema
|
|
return schema
|
|
@@ -373,12 +380,11 @@ class ParseJsonSchema(ParseDbSchema):
|
|
definitions_flag = self._analyze_schema(schema[key], definitions_flag)
|
|
definitions_flag = self._analyze_schema(schema[key], definitions_flag)
|
|
|
|
|
|
return definitions_flag
|
|
return definitions_flag
|
|
-
|
|
|
|
- def _format_schema_for_mongo(self, schema: dict) -> dict:
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ def _clean_desciptions_tags_from_single_quotes(self, schema: dict) -> dict:
|
|
'''
|
|
'''
|
|
- We use in the schema tags whih are not supported by mongo an threfore
|
|
|
|
- must be taken care of before setting the schema for mongo.
|
|
|
|
- :param str schema_path: path to the schema file.
|
|
|
|
|
|
+ :param dict schema: dictonary containing schema
|
|
'''
|
|
'''
|
|
|
|
|
|
for key in list(schema):
|
|
for key in list(schema):
|
|
@@ -388,14 +394,27 @@ class ParseJsonSchema(ParseDbSchema):
|
|
schema[key] = cleaned_description
|
|
schema[key] = cleaned_description
|
|
|
|
|
|
if type(schema[key]) == dict:
|
|
if type(schema[key]) == dict:
|
|
- self._format_schema_for_mongo(schema[key])
|
|
|
|
|
|
+ self._clean_desciptions_tags_from_single_quotes(schema[key])
|
|
|
|
+
|
|
|
|
+ return schema
|
|
|
|
|
|
- if key == 'examples':
|
|
|
|
- self._remove_examples(schema)
|
|
|
|
|
|
+ def _format_schema_for_mongo(self, schema: dict) -> dict:
|
|
|
|
+ '''
|
|
|
|
+ We use in the schema tags whih are not supported by mongo an threfore
|
|
|
|
+ must be taken care of before setting the schema for mongo.
|
|
|
|
+ :param str schema_path: path to the schema file.
|
|
|
|
+ '''
|
|
|
|
|
|
|
|
+ for key in list(schema):
|
|
|
|
+
|
|
|
|
+ if type(schema[key]) == dict:
|
|
|
|
+ self._format_schema_for_mongo(schema[key])
|
|
|
|
|
|
if key == 'default' or key == 'default_values':
|
|
if key == 'default' or key == 'default_values':
|
|
self._remove_defaults(schema)
|
|
self._remove_defaults(schema)
|
|
|
|
+
|
|
|
|
+ if key == 'examples':
|
|
|
|
+ self._remove_examples(schema)
|
|
|
|
|
|
return schema
|
|
return schema
|
|
|
|
|
|
@@ -413,7 +432,7 @@ class ParseJsonSchema(ParseDbSchema):
|
|
schema = str(schema).replace("'", "\"")
|
|
schema = str(schema).replace("'", "\"")
|
|
schema = jsonref.loads(schema, base_uri=base_dir_url)
|
|
schema = jsonref.loads(schema, base_uri=base_dir_url)
|
|
schema = deepcopy(schema)
|
|
schema = deepcopy(schema)
|
|
- #schema.pop('definitions', None)
|
|
|
|
|
|
+
|
|
return schema
|
|
return schema
|
|
|
|
|
|
def _remove_defaults(self, schema: dict) -> dict:
|
|
def _remove_defaults(self, schema: dict) -> dict:
|