question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Annotations for validations

See original GitHub issue

Hello everyone!

Recently faced the need for validation and would like to be able to embed annotations in your code-generating library. Actually, an idea for development

For example: proto:

message Test {
    // Validated:min=4,regexp=[a-d_1-5]+,max=145
    string field1 = 1;
}

kotlin:

data class Test (
    @field:Size(min=4, max=145)
    @field:Pattern(regexp="[a-d_1-5]+")
    val field1: String?
) {
....
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
garypcommented, Aug 11, 2020

Hi @kubitre. We have the exact same need for validation in our REST API backend and are currently working on this. This will probably be available in the 0.9.0 release.

It’ll be implemented using protobuf custom options (see https://github.com/streem/pbandk/issues/65). You can see an example of using custom options for validation in https://github.com/envoyproxy/protoc-gen-validate. That tool doesn’t support Kotlin or pbandk, but it should give you an idea for how the validation rules could be implemented once #65 is done.

0reactions
garypcommented, May 8, 2021

Closing this issue since the initial support for annotations has been implemented. Please open a new issue with additional details if what’s implemented does not fully address your needs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Java Bean Validation Basics - Baeldung
4. Using Validation Annotations · @NotEmpty validates that the property is not null or empty; can be applied to String, Collection, Map or...
Read more >
Validation with Spring Boot - the Complete Guide - Reflectoring
The @Validated annotation is a class-level annotation that we can use to tell Spring to validate parameters that are passed into a method...
Read more >
Validation Annotation - Apache Struts
Validation annotation must be applied at Type level. Parameters. validations - list of validations to apply. Examples. An Annotated Interface. Apply standard or ......
Read more >
javax.validation.constraints (Java(TM) EE 7 Specification APIs)
Package javax.validation.constraints ; AssertTrue.List. Defines several AssertTrue annotations on the same element. ; DecimalMax. The annotated element must be a ...
Read more >
Spring Boot - Creating a Custom Annotation for Validation
While I was working on a Spring Boot Project, I found that custom annotations were being used for validation. The best way to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found