Skip to content
项目

关于

表达力丰富的 Kotlin 验证库。

开发工具

这些数字如何统计

可以做什么

  • Beautiful DSL and API Write crystal clear validation code and keep it DRY. Use loops and conditions when needed; forget about annotation hell.
  • Bundled with all the essential constraints Write custom constraints for your business logic and nothing more. The rest? It's on us!
  • Easily and highly extendable No need to write verbose code to create custom constraints, within Akkurate they're as simple as a lambda with parameters.
  • Contextual and asynchronous Query sync/async data sources whenever you need to, like a database, or a REST API. Everything can happen inside validation.

实测星标增长

24小时
0
7天
0
15天
-1
1个月
正在收集历史

各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。

README.md

原文

Akkurate

Get started by reading the documentation

Akkurate is a validation library taking advantage of the expressive power of Kotlin. No need
for 30+ annotations or complicated custom constraints; write your validation code in Kotlin with a beautiful declarative API.

Designed from scratch to handle complex business logic, its role is to help you write qualitative and maintainable validation code.

A code example of Akkurate used to showcase the library on social networks.

[!WARNING] Akkurate is under development and, despite being heavily tested, its API isn't yet stabilized; breaking changes might happen on minor releases. However, we will always provide migration guides.

Report any issue or bug in the GitHub repository.

Showcase

Here's an example showcasing how you can constrain a book and its list of authors.

// Define your classes

@Validate
data class Book(
    val title: String,
    val releaseDate: LocalDateTime,
    val authors: List<Author>,
)

@Validate
data class Author(val firstName: String, val lastName: String)

// Write your validation rules

val validateBook = Validator<Book> {
    // First the property, then the constraint, finally the message.
    title.isNotEmpty() otherwise { "Missing title" }

    releaseDate.isInPast() otherwise { "Release date must be in past" }

    authors.hasSizeBetween(1..10) otherwise { "Wrong author count" }

    authors.each { // Apply constraints to each author
        (firstName and lastName) {
            // Apply the same constraint to both properties
            isNotEmpty() otherwise { "Missing name" }
        }
    }
}

// Validate your data

when (val result = validateBook(someBook)) {
    is Success -> println("Success: ${result.value}")
    is Failure -> {
        val list = result.violations
            .joinToString("\n") { "${it.path}: ${it.message}" }
        println("Failures:\n$list")
    }
}

Notice how each constraint applied to a property can be read like a sentence. This code:

title.isNotEmpty() otherwise { "Missing title" }

can be read:

Check if 'title' is not empty otherwise write "Missing title".

Features

探索相关项目

加载中…