|
19 | 19 | from openapi_schema_validator import OAS30Validator |
20 | 20 | from openapi_schema_validator import OAS30WriteValidator |
21 | 21 | from openapi_schema_validator import OAS31Validator |
| 22 | +from openapi_schema_validator import OAS32Validator |
22 | 23 | from openapi_schema_validator import oas30_format_checker |
23 | 24 | from openapi_schema_validator import oas30_strict_format_checker |
24 | 25 | from openapi_schema_validator import oas31_format_checker |
| 26 | +from openapi_schema_validator import oas32_format_checker |
25 | 27 |
|
26 | 28 |
|
27 | 29 | class TestOAS30ValidatorFormatChecker: |
@@ -1003,6 +1005,71 @@ def test_array_prefixitems_invalid(self, validator_class, value): |
1003 | 1005 | assert any(error in str(excinfo.value) for error in errors) |
1004 | 1006 |
|
1005 | 1007 |
|
| 1008 | +class TestOAS32ValidatorValidate(BaseTestOASValidatorValidate): |
| 1009 | + """OAS 3.2 uses the same JSON Schema dialect as 3.1.""" |
| 1010 | + |
| 1011 | + @pytest.fixture |
| 1012 | + def validator_class(self): |
| 1013 | + return OAS32Validator |
| 1014 | + |
| 1015 | + @pytest.fixture |
| 1016 | + def format_checker(self): |
| 1017 | + return oas32_format_checker |
| 1018 | + |
| 1019 | + def test_validator_is_distinct_from_oas31(self): |
| 1020 | + assert OAS32Validator is not OAS31Validator |
| 1021 | + |
| 1022 | + def test_validator_shares_oas31_behavior(self): |
| 1023 | + assert ( |
| 1024 | + OAS32Validator.VALIDATORS == OAS31Validator.VALIDATORS |
| 1025 | + ) |
| 1026 | + |
| 1027 | + @pytest.mark.parametrize("value", [b"test"]) |
| 1028 | + def test_string_disallow_binary(self, validator_class, value): |
| 1029 | + schema = {"type": "string"} |
| 1030 | + validator = validator_class(schema) |
| 1031 | + |
| 1032 | + with pytest.raises(ValidationError): |
| 1033 | + validator.validate(value) |
| 1034 | + |
| 1035 | + @pytest.mark.parametrize( |
| 1036 | + "schema_type", |
| 1037 | + [ |
| 1038 | + "boolean", |
| 1039 | + "array", |
| 1040 | + "integer", |
| 1041 | + "number", |
| 1042 | + "string", |
| 1043 | + ], |
| 1044 | + ) |
| 1045 | + def test_null(self, validator_class, schema_type): |
| 1046 | + schema = {"type": schema_type} |
| 1047 | + validator = validator_class(schema) |
| 1048 | + value = None |
| 1049 | + |
| 1050 | + with pytest.raises(ValidationError): |
| 1051 | + validator.validate(value) |
| 1052 | + |
| 1053 | + @pytest.mark.parametrize( |
| 1054 | + "schema_type", |
| 1055 | + [ |
| 1056 | + "boolean", |
| 1057 | + "array", |
| 1058 | + "integer", |
| 1059 | + "number", |
| 1060 | + "string", |
| 1061 | + ], |
| 1062 | + ) |
| 1063 | + def test_nullable(self, validator_class, schema_type): |
| 1064 | + schema = {"type": [schema_type, "null"]} |
| 1065 | + validator = validator_class(schema) |
| 1066 | + value = None |
| 1067 | + |
| 1068 | + result = validator.validate(value) |
| 1069 | + |
| 1070 | + assert result is None |
| 1071 | + |
| 1072 | + |
1006 | 1073 | class TestOAS30StrictValidator: |
1007 | 1074 | """ |
1008 | 1075 | Tests for OAS30StrictValidator which follows OAS spec strictly: |
|
0 commit comments