Beispiel #1
0
def main():

    assert len(
        sys.argv
    ) == 3, "jsonsubschema cli takes exactly two arguments lhs_schema and rhs_schema"

    s1_file = sys.argv[1]
    s2_file = sys.argv[2]

    s1 = load_json_file(s1_file, "LHS file:")
    s2 = load_json_file(s2_file, "RHS file:")

    print("LHS <: RHS", isSubschema(s1, s2))
    print("RHS <: LHS", isSubschema(s2, s1))
Beispiel #2
0
def main():
    ''' CLI entry point for jsonsubschema '''

    parser = argparse.ArgumentParser(
        description=
        'CLI for ssonsubschema tool which checks whether a LHS JSON schema is a subschema (<:) of another RHS JSON schema.'
    )
    parser.add_argument(
        'LHS',
        metavar='lhs',
        type=str,
        help='Path to the JSON file which has the LHS JSON schema')
    parser.add_argument(
        'RHS',
        metavar='rhs',
        type=str,
        help='Path to the JSON file which has the RHS JSON schema')

    args = parser.parse_args()
    s1_file_path = args.LHS
    s2_file_path = args.RHS

    s1 = load_json_file(s1_file_path, "LHS file:")
    s2 = load_json_file(s2_file_path, "RHS file:")

    print("LHS <: RHS", isSubschema(s1, s2))
def main():

    assert len(
        sys.argv) == 3, "jsonsubschema cli takes exactly two arguments lhs_schema and rhs_schema"

    s1_file = sys.argv[1]
    s2_file = sys.argv[2]

    with open(s1_file, 'r') as f1:
        # s1 = json.load(f1)
        s1 = jsonref.load(f1)
    with open(s2_file, 'r') as f2:
        # s2 = json.load(f2)
        s2 = jsonref.load(f2)

    print("LHS <: RHS", isSubschema(s1, s2))
    print("RHS <: LHS", isSubschema(s2, s1))
Beispiel #4
0
def compare(path1: str, path2: str, result: str):
    """
    Compares two JSON schemas and stores the result at the specified path.

    Args:
        path1: The path to the first JSON schema presented as a .json file.
        path2: The path to the second JSON schema presented as a .json file.
        result: The path to the result .json file.

    Returns:
        A message indicating success or failure of the process.

    Raises:
        IOError:
            
    """

    try:
        json_schema1 = _load_json_schema(path1)
        json_schema2 = _load_json_schema(path2)
    except IOError as error:
        return "Failure while loading the schemas.", error

    # evaluate the schemas.
    s1_sub_s2 = jss.isSubschema(json_schema1, json_schema2)
    s1_sup_s2 = jss.isSubschema(json_schema2, json_schema1)

    # The most strict scalar result of the containment check is chosen.
    if s1_sub_s2 and s1_sup_s2:
        msg = 'equivalent'
    elif s1_sub_s2:
        msg = 'subset'
    elif s1_sup_s2:
        msg = 'superset'
    else:
        msg = 'incomparable'

    try:
        _write_result(msg, result)
        return "Success."
    except IOError as error:
        return "Failure while saving the result " + msg + ".", error