Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] add the ability to generate validation documentation or allow inspection for the validation rules #62

Open
alphaho opened this issue Feb 2, 2025 · 0 comments

Comments

@alphaho
Copy link

alphaho commented Feb 2, 2025

Problem Statement

Akkurate's declarative syntax makes validation rules clear and maintainable for developers. However, non-technical stakeholders often need to understand these validation rules without reading code. Currently, there's no built-in way to generate human-readable documentation from the validation rules.

Feature Request

Add support for programmatically inspecting validation rules to enable automatic documentation generation. This would allow teams to create clear, non-technical documentation of their validation rules in formats like Markdown tables.

Example

Using the official showcase as an example:

@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" }
        }
    }
}

// iterating through the rules

for (rule in validateBook.rules) {
    println("${rule.pathDescription}: ${rule.definition}")
}

Expected output

title: must not be empty
releaseDate: must be in the past
authors: must have size between 1 and 10
each authors' firstName and lastName: must not be empty
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant