Skip to content

Commit b788129

Browse files
committed
relax duplicate keys constraint
1 parent 6c48530 commit b788129

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

core/src/main/kotlin/gropius/service/template/BaseTemplateService.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,12 @@ abstract class BaseTemplateService<T : BaseTemplate<*, *>, R : GropiusRepository
4848
val derivedFields =
4949
extendedTemplates.flatMap { it.templateFieldSpecifications.entries }.map { it.toPair() }.toSet()
5050
val allFields = derivedFields + additionalFields
51-
val duplicates = allFields.groupingBy { it.first }.eachCount().filter { it.value > 1 }.keys
52-
if (duplicates.isNotEmpty()) {
53-
throw IllegalArgumentException("Duplicate names found: $duplicates")
51+
val groupedByName = allFields.groupBy { it.first }
52+
val duplicatesWithDifferentValues = groupedByName.filter { (_, values) ->
53+
values.map { it.second }.toSet().size > 1
54+
}.keys
55+
if (duplicatesWithDifferentValues.isNotEmpty()) {
56+
throw IllegalArgumentException("Duplicate names with different values found: $duplicatesWithDifferentValues")
5457
}
5558
for ((name, value) in allFields) {
5659
template.templateFieldSpecifications[name] = value

0 commit comments

Comments
 (0)