|
4 | 4 | from lapidary_render.model.stack import Stack |
5 | 5 |
|
6 | 6 |
|
| 7 | +def test_normalize_allof_type_intersection(): |
| 8 | + # docs/json-schema.md#allof-and-type — allOf applies set intersection to type |
| 9 | + schema = MetaModel( |
| 10 | + stack=Stack.from_str('#/components/schemas/obj'), |
| 11 | + all_of=[ |
| 12 | + MetaModel( |
| 13 | + stack=Stack.from_str('#/components/schemas/obj/allOf/0'), |
| 14 | + type_={DataType.INTEGER, DataType.STRING}, |
| 15 | + ), |
| 16 | + MetaModel( |
| 17 | + stack=Stack.from_str('#/components/schemas/obj/allOf/1'), |
| 18 | + type_={DataType.INTEGER, DataType.BOOLEAN}, |
| 19 | + ), |
| 20 | + ], |
| 21 | + ) |
| 22 | + |
| 23 | + result = schema.normalize_model() |
| 24 | + |
| 25 | + assert result == MetaModel( |
| 26 | + stack=Stack.from_str('#/components/schemas/obj'), |
| 27 | + type_={DataType.INTEGER}, |
| 28 | + ) |
| 29 | + |
| 30 | + |
| 31 | +def test_normalize_nested_allof(): |
| 32 | + # docs/json-schema.md#nested-allof — nested allOf is flattened into a single allOf |
| 33 | + root = Stack.from_str('#/components/schemas/obj') |
| 34 | + schema = MetaModel( |
| 35 | + stack=root, |
| 36 | + all_of=[ |
| 37 | + MetaModel( |
| 38 | + stack=root.push('allOf/0'), |
| 39 | + all_of=[ |
| 40 | + MetaModel( |
| 41 | + stack=root.push('allOf/0'), |
| 42 | + type_={DataType.INTEGER}, |
| 43 | + ), |
| 44 | + MetaModel( |
| 45 | + stack=root.push('allOf/1'), |
| 46 | + ge=10.0, |
| 47 | + ), |
| 48 | + ], |
| 49 | + ), |
| 50 | + MetaModel( |
| 51 | + stack=root.push('allOf/1'), |
| 52 | + multiple_of=2, |
| 53 | + ), |
| 54 | + ], |
| 55 | + ) |
| 56 | + |
| 57 | + result = schema.normalize_model() |
| 58 | + |
| 59 | + assert result == MetaModel( |
| 60 | + stack=Stack.from_str('#/components/schemas/obj'), |
| 61 | + type_={DataType.INTEGER}, |
| 62 | + ge=10.0, |
| 63 | + multiple_of=2, |
| 64 | + ) |
| 65 | + |
| 66 | + |
7 | 67 | def test_normalize_allof_scalar_constraints(): |
8 | 68 | # docs/json-schema.md#allof-and-scalar-constraints — most restrictive value wins: max for ge/gt, min for le/lt |
9 | 69 | schema = MetaModel( |
|
0 commit comments