|
| 1 | +from typing import Any |
| 2 | + |
| 3 | +import pytest |
| 4 | + |
| 5 | +from openapi_parser.builders.schema import SchemaFactory |
| 6 | +from openapi_parser.enumeration import DataType |
| 7 | +from openapi_parser.specification import ( |
| 8 | + AnyOf, |
| 9 | + Array, |
| 10 | + Boolean, |
| 11 | + Integer, |
| 12 | + Number, |
| 13 | + Object, |
| 14 | + Property, |
| 15 | + Schema, |
| 16 | + String, |
| 17 | +) |
| 18 | + |
| 19 | +data_provider = ( |
| 20 | + ( |
| 21 | + { |
| 22 | + "type": "string", |
| 23 | + "not": {"type": "integer"}, |
| 24 | + }, |
| 25 | + String( |
| 26 | + type=DataType.STRING, |
| 27 | + not_schema=Integer(type=DataType.INTEGER), |
| 28 | + ), |
| 29 | + ), |
| 30 | + ( |
| 31 | + { |
| 32 | + "type": "object", |
| 33 | + "properties": { |
| 34 | + "name": {"type": "string"}, |
| 35 | + }, |
| 36 | + "not": {"type": "integer"}, |
| 37 | + }, |
| 38 | + Object( |
| 39 | + type=DataType.OBJECT, |
| 40 | + properties=[ |
| 41 | + Property(name="name", schema=String(type=DataType.STRING)), |
| 42 | + ], |
| 43 | + not_schema=Integer(type=DataType.INTEGER), |
| 44 | + ), |
| 45 | + ), |
| 46 | + ( |
| 47 | + { |
| 48 | + "not": {"type": "integer"}, |
| 49 | + }, |
| 50 | + AnyOf( |
| 51 | + type=DataType.ANY_OF, |
| 52 | + schemas=[ |
| 53 | + Integer(type=DataType.INTEGER), |
| 54 | + Number(type=DataType.NUMBER), |
| 55 | + String(type=DataType.STRING), |
| 56 | + Boolean(type=DataType.BOOLEAN), |
| 57 | + Array(type=DataType.ARRAY), |
| 58 | + Object(type=DataType.OBJECT), |
| 59 | + ], |
| 60 | + not_schema=Integer(type=DataType.INTEGER), |
| 61 | + ), |
| 62 | + ), |
| 63 | + ( |
| 64 | + { |
| 65 | + "type": "string", |
| 66 | + }, |
| 67 | + String(type=DataType.STRING), |
| 68 | + ), |
| 69 | +) |
| 70 | + |
| 71 | + |
| 72 | +@pytest.mark.parametrize(["data", "expected"], data_provider) |
| 73 | +def test_not_builder(data: dict[str, Any], expected: Schema) -> None: |
| 74 | + factory = SchemaFactory() |
| 75 | + assert expected == factory.create(data) |
0 commit comments