From 08a5cc86f105bcfa71be129931d7011a5e32cd27 Mon Sep 17 00:00:00 2001 From: d1snin Date: Tue, 5 Sep 2023 00:04:39 +0300 Subject: [PATCH] fix: validation functions throw unexpected errors --- .../dev/d1s/beam/commons/contententity/ContentEntity.kt | 6 +----- .../commons/validation/ContentEntityParametersValidator.kt | 3 +-- .../beam/commons/validation/SpaceContentEntityValidator.kt | 2 +- .../beam/commons/validation/TextContentEntityValidator.kt | 3 +-- 4 files changed, 4 insertions(+), 10 deletions(-) diff --git a/beam-common/src/commonMain/kotlin/dev/d1s/beam/commons/contententity/ContentEntity.kt b/beam-common/src/commonMain/kotlin/dev/d1s/beam/commons/contententity/ContentEntity.kt index 46ec8bc7..ac44fcf9 100644 --- a/beam-common/src/commonMain/kotlin/dev/d1s/beam/commons/contententity/ContentEntity.kt +++ b/beam-common/src/commonMain/kotlin/dev/d1s/beam/commons/contententity/ContentEntity.kt @@ -34,8 +34,4 @@ public data class ContentEntity( ) public operator fun ContentEntityParameters.get(definition: ContentEntityParameterDefinition): ContentEntityParameterValue? = - this[definition.name].also { - if (definition.required && it == null) { - error("Parameter isn't specified: $definition") - } - } \ No newline at end of file + this[definition.name] \ No newline at end of file diff --git a/beam-common/src/commonMain/kotlin/dev/d1s/beam/commons/validation/ContentEntityParametersValidator.kt b/beam-common/src/commonMain/kotlin/dev/d1s/beam/commons/validation/ContentEntityParametersValidator.kt index 7dbddd34..3ad53e0d 100644 --- a/beam-common/src/commonMain/kotlin/dev/d1s/beam/commons/validation/ContentEntityParametersValidator.kt +++ b/beam-common/src/commonMain/kotlin/dev/d1s/beam/commons/validation/ContentEntityParametersValidator.kt @@ -36,9 +36,8 @@ internal object ContentEntityParametersValidator : ContentEntityValidator.requireParameters() { addConstraint("missing parameters") { entity -> val definition = entity.definition() - requireNotNull(definition) - definition.parameters.forEach { parameterDefinition -> + definition?.parameters?.forEach { parameterDefinition -> if (parameterDefinition.required) { val name = parameterDefinition.name entity.parameters[name] ?: return@addConstraint false diff --git a/beam-common/src/commonMain/kotlin/dev/d1s/beam/commons/validation/SpaceContentEntityValidator.kt b/beam-common/src/commonMain/kotlin/dev/d1s/beam/commons/validation/SpaceContentEntityValidator.kt index 7909bed1..1a11aa7c 100644 --- a/beam-common/src/commonMain/kotlin/dev/d1s/beam/commons/validation/SpaceContentEntityValidator.kt +++ b/beam-common/src/commonMain/kotlin/dev/d1s/beam/commons/validation/SpaceContentEntityValidator.kt @@ -26,7 +26,7 @@ internal object SpaceContentEntityValidator : override fun ValidationBuilder.validate() { addTypedConstraint("parameter ${definition.identifier.name} is invalid") { entity -> - entity.parameters[definition.identifier]?.isNotBlank() != false + entity.parameters[definition.identifier]?.isBlank() != true } } } \ No newline at end of file diff --git a/beam-common/src/commonMain/kotlin/dev/d1s/beam/commons/validation/TextContentEntityValidator.kt b/beam-common/src/commonMain/kotlin/dev/d1s/beam/commons/validation/TextContentEntityValidator.kt index c586345e..136f0008 100644 --- a/beam-common/src/commonMain/kotlin/dev/d1s/beam/commons/validation/TextContentEntityValidator.kt +++ b/beam-common/src/commonMain/kotlin/dev/d1s/beam/commons/validation/TextContentEntityValidator.kt @@ -46,9 +46,8 @@ internal object TextContentEntityValidator : private fun ValidationBuilder.requireNotBlankValue() { addTypedConstraint("parameter \"${definition.value.name}\" must not be blank") { entity -> val value = entity.parameters[definition.value] - requireNotNull(value) - value.isNotBlank() + value?.isBlank() != true } }