Skip to content

Commit b1714aa

Browse files
committed
Add note about collecting elements to set. Use collection instead of set for enum assertion
1 parent e5cf619 commit b1714aa

File tree

1 file changed

+5
-2
lines changed
  • json-schema-validator/src/commonMain/kotlin/io/github/optimumcode/json/schema/internal/factories/general

1 file changed

+5
-2
lines changed

json-schema-validator/src/commonMain/kotlin/io/github/optimumcode/json/schema/internal/factories/general/EnumAssertionFactory.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,18 @@ internal object EnumAssertionFactory : AbstractAssertionFactory("enum") {
2020
): JsonSchemaAssertion {
2121
require(element is JsonArray) { "$property must be an array" }
2222
require(element.isNotEmpty()) { "$property must have at least one element" }
23+
// NOTE: when migrate to abstract element for loading schema
24+
// we need to use `io.github.optimumcode.json.schema.internal.util.areEqual`
25+
// to remove duplicated elements
2326
val uniqueElements = element.toSet()
2427
require(uniqueElements.size == element.size) { "$property must consist of unique elements" }
25-
return EnumAssertion(context.schemaPath, uniqueElements.mapTo(hashSetOf()) { it.wrap() })
28+
return EnumAssertion(context.schemaPath, uniqueElements.map { it.wrap() })
2629
}
2730
}
2831

2932
private class EnumAssertion(
3033
private val path: JsonPointer,
31-
private val possibleElements: Set<AbstractElement>,
34+
private val possibleElements: Collection<AbstractElement>,
3235
) : JsonSchemaAssertion {
3336
init {
3437
require(possibleElements.isNotEmpty()) { "at least one element must be set" }

0 commit comments

Comments
 (0)