Skip to content

Commit

Permalink
fix: validation functions throw unexpected errors
Browse files Browse the repository at this point in the history
  • Loading branch information
d1snin committed Sep 4, 2023
1 parent cab85c5 commit 08a5cc8
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
this[definition.name]
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ internal object ContentEntityParametersValidator : ContentEntityValidator<Nothin
private fun ValidationBuilder<ContentEntity>.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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ internal object SpaceContentEntityValidator :

override fun ValidationBuilder<ContentEntity>.validate() {
addTypedConstraint("parameter ${definition.identifier.name} is invalid") { entity ->
entity.parameters[definition.identifier]?.isNotBlank() != false
entity.parameters[definition.identifier]?.isBlank() != true
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@ internal object TextContentEntityValidator :
private fun ValidationBuilder<ContentEntity>.requireNotBlankValue() {
addTypedConstraint("parameter \"${definition.value.name}\" must not be blank") { entity ->
val value = entity.parameters[definition.value]
requireNotNull(value)

value.isNotBlank()
value?.isBlank() != true
}
}

Expand Down

0 comments on commit 08a5cc8

Please sign in to comment.