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

Validator for value returned from a function #50

Open
Obirah opened this issue Sep 3, 2020 · 0 comments
Open

Validator for value returned from a function #50

Obirah opened this issue Sep 3, 2020 · 0 comments

Comments

@Obirah
Copy link

Obirah commented Sep 3, 2020

Is your feature request related to a problem? Please describe.

The problem space this feature request arises from is the following:

In my Spring Boot Kotlin project, I'm using OpenAPI generator to generate API clients. I am generating Java client code, because I need the clients to use the Spring WebClient under the hood (because of a special authentication setup) and there is (to my knowledge) no way to generate Kotlin client code based on Spring WebClient.

Now, I need to validate the responses from those clients which are returned in classical PoJos with private members and public getters. Unfortunately, I can neither validate those PoJos with:

validate(response) {
    validate(ApiResponse::id).isNotBlank()
}

nor with:

validate(response) {
    validate(ApiResponse::getId).isNotBlank()
}

because both of those references point to KFunction and not a KProperty.

Describe the solution you'd like

The coolest way would be to have a validate function which takes a KFunction instead of a KProperty and validates the returned value in the same look and feel as the property validation.

Describe alternatives you've considered

Right now I'm using https://github.com/rcapraro/kalidation because it allows me to do something like that:

constraints<ApiResponse>{
    returnOf(ApiResponse::getId) {
        notBlank()
    }
}

Nonetheless, I think that the feature set of valiktor is way better. Therefore, using kalidation feels like a step backwards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant