Skip to content

Commit

Permalink
doc: improve readability of the wiring part in the ktor tutorial (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
nesk committed Nov 14, 2023
1 parent 1d5e70e commit 46eb871
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 5 additions & 2 deletions documentation/topics/ktor-validation-tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -304,12 +304,15 @@ This plugin allows configuring a validation function for a specific class; it wi
A validation result must be returned, we can generate it from %product%'s own result:

```kotlin
import dev.nesk.akkurate.ValidationResult.Failure as AkkurateFailure
import dev.nesk.akkurate.ValidationResult.Success as AkkurateSuccess

fun Application.configureValidation() {
install(RequestValidation) {
validate<Book> { book ->
when (val result = validateBook(bookDao, book)) {
is dev.nesk.akkurate.ValidationResult.Success -> ValidationResult.Valid
is dev.nesk.akkurate.ValidationResult.Failure -> {
is AkkurateSuccess -> ValidationResult.Valid
is AkkurateFailure -> {
val reasons = result.violations.map {
"${it.path.joinToString(".")}: ${it.message}"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ import dev.nesk.akkurate.examples.ktor.server.plugins.validation.accessors.isbn
import dev.nesk.akkurate.examples.ktor.server.plugins.validation.accessors.title
import io.ktor.server.application.*
import io.ktor.server.plugins.requestvalidation.*
import dev.nesk.akkurate.ValidationResult.Failure as AkkurateFailure
import dev.nesk.akkurate.ValidationResult.Success as AkkurateSuccess

fun Application.configureValidation() {
install(RequestValidation) {
validate<Book> { book ->
when (val result = validateBook(bookDao, book)) {
is dev.nesk.akkurate.ValidationResult.Success -> ValidationResult.Valid
is dev.nesk.akkurate.ValidationResult.Failure -> {
is AkkurateSuccess -> ValidationResult.Valid
is AkkurateFailure -> {
val reasons = result.violations.map {
"${it.path.joinToString(".")}: ${it.message}"
}
Expand Down

0 comments on commit 46eb871

Please sign in to comment.