|
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,66 @@ 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(TestOAS31ValidatorValidate): |
| 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_format_checker_is_distinct_from_oas31(self): |
| 1023 | + assert oas32_format_checker is not oas31_format_checker |
| 1024 | + |
| 1025 | + def test_validator_shares_oas31_behavior(self): |
| 1026 | + assert OAS32Validator.VALIDATORS == OAS31Validator.VALIDATORS |
| 1027 | + |
| 1028 | + def test_format_validation_int32(self, validator_class): |
| 1029 | + schema = {"type": "integer", "format": "int32"} |
| 1030 | + validator = validator_class( |
| 1031 | + schema, format_checker=oas32_format_checker |
| 1032 | + ) |
| 1033 | + |
| 1034 | + result = validator.validate(42) |
| 1035 | + assert result is None |
| 1036 | + |
| 1037 | + with pytest.raises(ValidationError): |
| 1038 | + validator.validate(9999999999) |
| 1039 | + |
| 1040 | + def test_format_validation_date(self, validator_class): |
| 1041 | + schema = {"type": "string", "format": "date"} |
| 1042 | + validator = validator_class( |
| 1043 | + schema, format_checker=oas32_format_checker |
| 1044 | + ) |
| 1045 | + |
| 1046 | + result = validator.validate("2024-01-15") |
| 1047 | + assert result is None |
| 1048 | + |
| 1049 | + with pytest.raises(ValidationError): |
| 1050 | + validator.validate("not-a-date") |
| 1051 | + |
| 1052 | + def test_schema_with_allof(self, validator_class): |
| 1053 | + schema = { |
| 1054 | + "allOf": [ |
| 1055 | + {"type": "object", "properties": {"id": {"type": "integer"}}}, |
| 1056 | + {"type": "object", "properties": {"name": {"type": "string"}}}, |
| 1057 | + ] |
| 1058 | + } |
| 1059 | + validator = validator_class(schema) |
| 1060 | + |
| 1061 | + result = validator.validate({"id": 1, "name": "test"}) |
| 1062 | + assert result is None |
| 1063 | + |
| 1064 | + with pytest.raises(ValidationError): |
| 1065 | + validator.validate({"id": "not-an-integer"}) |
| 1066 | + |
| 1067 | + |
1006 | 1068 | class TestOAS30StrictValidator: |
1007 | 1069 | """ |
1008 | 1070 | Tests for OAS30StrictValidator which follows OAS spec strictly: |
|
0 commit comments