示例#1
0
def python_jsonsubschema(path1, path2):
    """
    The execution of the containment check using jsonsubschema. The containment is only checked in one!
    direction (path1 \sub path2).
    :param path1: Path to the first file.
    :param path2: Path to the second file.
    :return:
    """
    from _model import SubschemaComparison
    logger.info("Compare S1 %s sub S2 %s python jsonsubschema" %
                (path1, path2))

    s1_json_content = util.load_json(path1)[1]
    s2_json_content = util.load_json(path2)[1]

    is_sub = None
    sub_exception = None

    start = time.time()
    try:
        is_sub = jsonsubschema.isSubschema(s1_json_content, s2_json_content)
    except BaseException as e:
        sub_exception = (str(type(e)), str(e))
    finally:
        end = time.time()

    logger.info("End compare S1 %s sub S1 %s" % (path1, path2))
    return SubschemaComparison(is_sub, sub_exception, start, end)
示例#2
0
 def _valid_all_drafts(cls, git_history_file: GitHistoryFile):
     """
     Loads the file and checks whether the content is valid to all drafts specified in _drafts_to_validate.
     :param git_history_file: The file to check.
     :return: True if the file is valid to all drafts, false otherwise.
     """
     json_content = util.load_json(git_history_file.full_path)[1]  # [1] is the json_content
     return cls._valid_all_drafts_json(json_content)
示例#3
0
def check_history_file(git_history_file: GitHistoryFile):
    """
    Loads the specific file and checks to content if some keywords added or changed after Draft4 are contained.
    :param git_history_file: The specific file to check.
    :return: The added keywords and incompatible keywords found and the schema tag.
    """
    logger.info("Checking file {}".format(git_history_file.full_path))
    content, json_content = util.load_json(git_history_file.full_path)[0:2]
    return check_history_json(json_content)
示例#4
0
 def schema_tag(self):
     """
     Loads the JSON Schema document and returns the specified schema tag ($schema).
     :return:
     """
     if not hasattr(self, '_schema_tag'):
         self._schema_tag = util.schema_tag(
             util.load_json(self.full_path)[1])
     return self._schema_tag
示例#5
0
def check_file(git_history_file: GitHistoryFile):
    """
    Checks the file for different schema drafts. The file is loaded and validated against each available draft-
    validator (Draft 3, 4 ,6 and 7). If the schema is valid to at least on draft, the schema will be derferenced and
    this schema will be checked again with each validator. If the schema is invalid to all validators in the first step,
    this check will not be performed.
    :param git_history_file: The file to check
    :param check_jsonsubschema: Whether jsonsubschema should be checked (if maybe canonicalization results an invalid schema)
    :return: A SchemaDrafts-object containing all information.
    """
    logger.info("Check file: " + git_history_file.full_path)
    schema_drafts_result = SchemaDrafts(git_history_file)

    content, json_content, encoding, error = util.load_json(
        git_history_file.full_path)
    if error:
        return schema_drafts_result

    # NORMAL
    if not _check_drafts_and_add(schema_drafts_result, json_content,
                                 ORIGINAL_SCHEMA_NAME):
        return schema_drafts_result

    try:
        # Dereference
        json_content_refs = jsonref.JsonRef.replace_refs(json_content)
    except Exception:
        logger.info("End check file - abort refs: {}".format(
            git_history_file.full_path))
        return schema_drafts_result

    # NORMAL REFS
    if not _check_drafts_and_add(schema_drafts_result, json_content_refs,
                                 DEREFERENCED_SCHEMA_NAME):
        return schema_drafts_result

    logger.info("End check file: {}".format(git_history_file.full_path))
    return schema_drafts_result
示例#6
0
 def is_valid(self, git_history_file: GitHistoryFile):
     logger.info("File: {}".format(git_history_file.full_path))
     json_content = util.load_json(git_history_file.full_path)[1]
     return self._is_valid(json_content)