Beispiel #1
0
def test_union_with_compatible_elements() -> None:
    union1 = parse_jsonschema_definition(
        '{"oneOf":[{"type":"array","items":{"type":"object",'
        '"additionalProperties":false,"properties":{"a":{"type":"integer","default":1},"b":{"type":"number"}}}}]}'
    )
    union2 = parse_jsonschema_definition(
        '{"oneOf":[{"type":"array","items":{"type":"object",'
        '"properties":{"b":{"type":"number"},"c":{"type":"integer","default":0}}}}]}'
    )
    assert compatibility(reader=union2, writer=union1) == COMPATIBLE
Beispiel #2
0
from karapace.schema_reader import parse_jsonschema_definition

# boolean schemas
NOT_OF_EMPTY_SCHEMA = parse_jsonschema_definition('{"not":{}}')
NOT_OF_TRUE_SCHEMA = parse_jsonschema_definition('{"not":true}')
FALSE_SCHEMA = parse_jsonschema_definition('false')
TRUE_SCHEMA = parse_jsonschema_definition('true')
EMPTY_SCHEMA = parse_jsonschema_definition('{}')

# simple instance schemas
BOOLEAN_SCHEMA = parse_jsonschema_definition('{"type":"boolean"}')
INT_SCHEMA = parse_jsonschema_definition('{"type":"integer"}')
NUMBER_SCHEMA = parse_jsonschema_definition('{"type":"number"}')
STRING_SCHEMA = parse_jsonschema_definition('{"type":"string"}')
OBJECT_SCHEMA = parse_jsonschema_definition('{"type":"object"}')
ARRAY_SCHEMA = parse_jsonschema_definition('{"type":"array"}')

# negation of simple schemas
NOT_BOOLEAN_SCHEMA = parse_jsonschema_definition('{"not":{"type":"boolean"}}')
NOT_INT_SCHEMA = parse_jsonschema_definition('{"not":{"type":"integer"}}')
NOT_NUMBER_SCHEMA = parse_jsonschema_definition('{"not":{"type":"number"}}')
NOT_STRING_SCHEMA = parse_jsonschema_definition('{"not":{"type":"string"}}')
NOT_OBJECT_SCHEMA = parse_jsonschema_definition('{"not":{"type":"object"}}')
NOT_ARRAY_SCHEMA = parse_jsonschema_definition('{"not":{"type":"array"}}')

# structural validation
MAX_LENGTH_SCHEMA = parse_jsonschema_definition('{"type":"string","maxLength":3}')
MAX_LENGTH_DECREASED_SCHEMA = parse_jsonschema_definition('{"type":"string","maxLength":2}')
MIN_LENGTH_SCHEMA = parse_jsonschema_definition('{"type":"string","minLength":5}')
MIN_LENGTH_INCREASED_SCHEMA = parse_jsonschema_definition('{"type":"string","minLength":7}')
MIN_PATTERN_SCHEMA = parse_jsonschema_definition('{"type":"string","pattern":"a*"}')
Beispiel #3
0
def test_reflexivity() -> None:
    schema = parse_jsonschema_definition(
        '{"type":"object","required":["boolF","intF","numberF","stringF","enumF","arrayF","recordF"],'
        '"properties":{"recordF":{"type":"object","properties":{"f":{"type":"number"}}},"stringF":{"type":"string"},'
        '"boolF":{"type":"boolean"},"intF":{"type":"integer"},"enumF":{"enum":["S"]},'
        '"arrayF":{"type":"array","items":{"type":"string"}},"numberF":{"type":"number"},"bool0":{"type":"boolean"}}}'
    )
    assert compatibility(reader=schema, writer=schema) == COMPATIBLE

    assert compatibility(NOT_OF_EMPTY_SCHEMA,
                         NOT_OF_EMPTY_SCHEMA) == COMPATIBLE
    assert compatibility(NOT_OF_TRUE_SCHEMA, NOT_OF_TRUE_SCHEMA) == COMPATIBLE
    assert compatibility(FALSE_SCHEMA, FALSE_SCHEMA) == COMPATIBLE
    assert compatibility(TRUE_SCHEMA, TRUE_SCHEMA) == COMPATIBLE
    assert compatibility(EMPTY_SCHEMA, EMPTY_SCHEMA) == COMPATIBLE
    assert compatibility(BOOLEAN_SCHEMA, BOOLEAN_SCHEMA) == COMPATIBLE
    assert compatibility(INT_SCHEMA, INT_SCHEMA) == COMPATIBLE
    assert compatibility(NUMBER_SCHEMA, NUMBER_SCHEMA) == COMPATIBLE
    assert compatibility(STRING_SCHEMA, STRING_SCHEMA) == COMPATIBLE
    assert compatibility(OBJECT_SCHEMA, OBJECT_SCHEMA) == COMPATIBLE
    assert compatibility(ARRAY_SCHEMA, ARRAY_SCHEMA) == COMPATIBLE
    assert compatibility(NOT_BOOLEAN_SCHEMA, NOT_BOOLEAN_SCHEMA) == COMPATIBLE
    assert compatibility(NOT_INT_SCHEMA, NOT_INT_SCHEMA) == COMPATIBLE
    assert compatibility(NOT_NUMBER_SCHEMA, NOT_NUMBER_SCHEMA) == COMPATIBLE
    assert compatibility(NOT_STRING_SCHEMA, NOT_STRING_SCHEMA) == COMPATIBLE
    assert compatibility(NOT_OBJECT_SCHEMA, NOT_OBJECT_SCHEMA) == COMPATIBLE
    assert compatibility(NOT_ARRAY_SCHEMA, NOT_ARRAY_SCHEMA) == COMPATIBLE
    assert compatibility(MAX_LENGTH_SCHEMA, MAX_LENGTH_SCHEMA) == COMPATIBLE
    assert compatibility(MAX_LENGTH_DECREASED_SCHEMA,
                         MAX_LENGTH_DECREASED_SCHEMA) == COMPATIBLE
    assert compatibility(MIN_LENGTH_SCHEMA, MIN_LENGTH_SCHEMA) == COMPATIBLE
    assert compatibility(MIN_LENGTH_INCREASED_SCHEMA,
                         MIN_LENGTH_INCREASED_SCHEMA) == COMPATIBLE
    assert compatibility(MIN_PATTERN_SCHEMA, MIN_PATTERN_SCHEMA) == COMPATIBLE
    assert compatibility(MIN_PATTERN_STRICT_SCHEMA,
                         MIN_PATTERN_STRICT_SCHEMA) == COMPATIBLE
    assert compatibility(MAXIMUM_INTEGER_SCHEMA,
                         MAXIMUM_INTEGER_SCHEMA) == COMPATIBLE
    assert compatibility(MAXIMUM_NUMBER_SCHEMA,
                         MAXIMUM_NUMBER_SCHEMA) == COMPATIBLE
    assert compatibility(MAXIMUM_DECREASED_INTEGER_SCHEMA,
                         MAXIMUM_DECREASED_INTEGER_SCHEMA) == COMPATIBLE
    assert compatibility(MAXIMUM_DECREASED_NUMBER_SCHEMA,
                         MAXIMUM_DECREASED_NUMBER_SCHEMA) == COMPATIBLE
    assert compatibility(MINIMUM_INTEGER_SCHEMA,
                         MINIMUM_INTEGER_SCHEMA) == COMPATIBLE
    assert compatibility(MINIMUM_NUMBER_SCHEMA,
                         MINIMUM_NUMBER_SCHEMA) == COMPATIBLE
    assert compatibility(MINIMUM_INCREASED_INTEGER_SCHEMA,
                         MINIMUM_INCREASED_INTEGER_SCHEMA) == COMPATIBLE
    assert compatibility(MINIMUM_INCREASED_NUMBER_SCHEMA,
                         MINIMUM_INCREASED_NUMBER_SCHEMA) == COMPATIBLE
    assert compatibility(EXCLUSIVE_MAXIMUM_INTEGER_SCHEMA,
                         EXCLUSIVE_MAXIMUM_INTEGER_SCHEMA) == COMPATIBLE
    assert compatibility(EXCLUSIVE_MAXIMUM_NUMBER_SCHEMA,
                         EXCLUSIVE_MAXIMUM_NUMBER_SCHEMA) == COMPATIBLE
    assert compatibility(
        EXCLUSIVE_MAXIMUM_DECREASED_INTEGER_SCHEMA,
        EXCLUSIVE_MAXIMUM_DECREASED_INTEGER_SCHEMA,
    ) == COMPATIBLE
    assert compatibility(
        EXCLUSIVE_MAXIMUM_DECREASED_NUMBER_SCHEMA,
        EXCLUSIVE_MAXIMUM_DECREASED_NUMBER_SCHEMA) == COMPATIBLE
    assert compatibility(EXCLUSIVE_MINIMUM_INTEGER_SCHEMA,
                         EXCLUSIVE_MINIMUM_INTEGER_SCHEMA) == COMPATIBLE
    assert compatibility(EXCLUSIVE_MINIMUM_NUMBER_SCHEMA,
                         EXCLUSIVE_MINIMUM_NUMBER_SCHEMA) == COMPATIBLE
    assert compatibility(
        EXCLUSIVE_MINIMUM_INCREASED_INTEGER_SCHEMA,
        EXCLUSIVE_MINIMUM_INCREASED_INTEGER_SCHEMA,
    ) == COMPATIBLE
    assert compatibility(
        EXCLUSIVE_MINIMUM_INCREASED_NUMBER_SCHEMA,
        EXCLUSIVE_MINIMUM_INCREASED_NUMBER_SCHEMA) == COMPATIBLE
    assert compatibility(MAX_PROPERTIES_SCHEMA,
                         MAX_PROPERTIES_SCHEMA) == COMPATIBLE
    assert compatibility(MAX_PROPERTIES_DECREASED_SCHEMA,
                         MAX_PROPERTIES_DECREASED_SCHEMA) == COMPATIBLE
    assert compatibility(MIN_PROPERTIES_SCHEMA,
                         MIN_PROPERTIES_SCHEMA) == COMPATIBLE
    assert compatibility(MIN_PROPERTIES_INCREASED_SCHEMA,
                         MIN_PROPERTIES_INCREASED_SCHEMA) == COMPATIBLE
    assert compatibility(MAX_ITEMS_SCHEMA, MAX_ITEMS_SCHEMA) == COMPATIBLE
    assert compatibility(MAX_ITEMS_DECREASED_SCHEMA,
                         MAX_ITEMS_DECREASED_SCHEMA) == COMPATIBLE
    assert compatibility(MIN_ITEMS_SCHEMA, MIN_ITEMS_SCHEMA) == COMPATIBLE
    assert compatibility(MIN_ITEMS_INCREASED_SCHEMA,
                         MIN_ITEMS_INCREASED_SCHEMA) == COMPATIBLE
    assert compatibility(TUPLE_OF_INT_INT_SCHEMA,
                         TUPLE_OF_INT_INT_SCHEMA) == COMPATIBLE
    assert compatibility(TUPLE_OF_INT_SCHEMA,
                         TUPLE_OF_INT_SCHEMA) == COMPATIBLE
    assert compatibility(TUPLE_OF_INT_WITH_ADDITIONAL_INT_SCHEMA,
                         TUPLE_OF_INT_WITH_ADDITIONAL_INT_SCHEMA) == COMPATIBLE
    assert compatibility(TUPLE_OF_INT_INT_OPEN_SCHEMA,
                         TUPLE_OF_INT_INT_OPEN_SCHEMA) == COMPATIBLE
    assert compatibility(TUPLE_OF_INT_OPEN_SCHEMA,
                         TUPLE_OF_INT_OPEN_SCHEMA) == COMPATIBLE
    assert compatibility(ARRAY_OF_INT_SCHEMA,
                         ARRAY_OF_INT_SCHEMA) == COMPATIBLE
    assert compatibility(ARRAY_OF_NUMBER_SCHEMA,
                         ARRAY_OF_NUMBER_SCHEMA) == COMPATIBLE
    assert compatibility(ARRAY_OF_STRING_SCHEMA,
                         ARRAY_OF_STRING_SCHEMA) == COMPATIBLE
    assert compatibility(ENUM_AB_SCHEMA, ENUM_AB_SCHEMA) == COMPATIBLE
    assert compatibility(ENUM_ABC_SCHEMA, ENUM_ABC_SCHEMA) == COMPATIBLE
    assert compatibility(ENUM_BC_SCHEMA, ENUM_BC_SCHEMA) == COMPATIBLE
    assert compatibility(ONEOF_STRING_SCHEMA,
                         ONEOF_STRING_SCHEMA) == COMPATIBLE
    assert compatibility(ONEOF_STRING_INT_SCHEMA,
                         ONEOF_STRING_INT_SCHEMA) == COMPATIBLE
    assert compatibility(EMPTY_OBJECT_SCHEMA,
                         EMPTY_OBJECT_SCHEMA) == COMPATIBLE
    assert compatibility(A_INT_OBJECT_SCHEMA,
                         A_INT_OBJECT_SCHEMA) == COMPATIBLE
    assert compatibility(A_INT_OPEN_OBJECT_SCHEMA,
                         A_INT_OPEN_OBJECT_SCHEMA) == COMPATIBLE
    assert compatibility(A_INT_B_INT_OBJECT_SCHEMA,
                         A_INT_B_INT_OBJECT_SCHEMA) == COMPATIBLE
    assert compatibility(A_INT_B_INT_REQUIRED_OBJECT_SCHEMA,
                         A_INT_B_INT_REQUIRED_OBJECT_SCHEMA) == COMPATIBLE
    assert compatibility(A_INT_B_DINT_OBJECT_SCHEMA,
                         A_INT_B_DINT_OBJECT_SCHEMA) == COMPATIBLE
    assert compatibility(A_INT_B_DINT_REQUIRED_OBJECT_SCHEMA,
                         A_INT_B_DINT_REQUIRED_OBJECT_SCHEMA) == COMPATIBLE
    assert compatibility(A_DINT_B_DINT_OBJECT_SCHEMA,
                         A_DINT_B_DINT_OBJECT_SCHEMA) == COMPATIBLE
    assert compatibility(A_DINT_B_NUM_OBJECT_SCHEMA,
                         A_DINT_B_NUM_OBJECT_SCHEMA) == COMPATIBLE
    assert compatibility(A_DINT_B_NUM_C_DINT_OBJECT_SCHEMA,
                         A_DINT_B_NUM_C_DINT_OBJECT_SCHEMA) == COMPATIBLE
    assert compatibility(B_NUM_C_DINT_OPEN_OBJECT_SCHEMA,
                         B_NUM_C_DINT_OPEN_OBJECT_SCHEMA) == COMPATIBLE
    assert compatibility(B_NUM_C_INT_OBJECT_SCHEMA,
                         B_NUM_C_INT_OBJECT_SCHEMA) == COMPATIBLE
    assert compatibility(ARRAY_OF_POSITIVE_INTEGER,
                         ARRAY_OF_POSITIVE_INTEGER) == COMPATIBLE
    assert compatibility(ARRAY_OF_POSITIVE_INTEGER_THROUGH_REF,
                         ARRAY_OF_POSITIVE_INTEGER_THROUGH_REF) == COMPATIBLE