|
6 | 6 | package io.openapiprocessor.core.model.datatypes |
7 | 7 |
|
8 | 8 | import io.kotest.core.spec.style.StringSpec |
| 9 | +import io.kotest.matchers.collections.shouldContainAll |
9 | 10 | import io.kotest.matchers.shouldBe |
10 | 11 | import io.openapiprocessor.core.support.datatypes.ObjectDataType |
11 | 12 |
|
@@ -68,4 +69,36 @@ class ComposedObjectDataTypeSpec : StringSpec({ |
68 | 69 | composed.referencedImports shouldBe setOf("java.lang.String") |
69 | 70 | } |
70 | 71 |
|
| 72 | + "allOf handles 'required' constraint of all items" { |
| 73 | + val composed = AllOfObjectDataType(DataTypeName("AllOf"), "pkg", listOf( |
| 74 | + ObjectDataType("Foo", "pkg", linkedMapOf( |
| 75 | + "foo" to StringDataType(), |
| 76 | + "fux" to StringDataType() |
| 77 | + ), constraints = DataTypeConstraints(required = listOf("foo", "fux"))), |
| 78 | + ObjectDataType( |
| 79 | + "Bar", "pkg", linkedMapOf( |
| 80 | + "bar" to StringDataType(), |
| 81 | + "bux" to StringDataType() |
| 82 | + ), constraints = DataTypeConstraints(required = listOf("bar", "bux"))) |
| 83 | + )) |
| 84 | + |
| 85 | + composed.constraints!!.required shouldContainAll listOf("foo", "fux", "bar", "bux") |
| 86 | + } |
| 87 | + |
| 88 | + "allOf without 'required' has null constraints" { |
| 89 | + val composed = AllOfObjectDataType(DataTypeName("AllOf"), "pkg", listOf( |
| 90 | + ObjectDataType("Foo", "pkg", linkedMapOf( |
| 91 | + "foo" to StringDataType(), |
| 92 | + "fux" to StringDataType() |
| 93 | + ), constraints = DataTypeConstraints()), |
| 94 | + ObjectDataType( |
| 95 | + "Bar", "pkg", linkedMapOf( |
| 96 | + "bar" to StringDataType(), |
| 97 | + "bux" to StringDataType() |
| 98 | + ), constraints = null) |
| 99 | + )) |
| 100 | + |
| 101 | + composed.constraints shouldBe null |
| 102 | + } |
| 103 | + |
71 | 104 | }) |
0 commit comments