akkurate icon indicating copy to clipboard operation
akkurate copied to clipboard

Ktor override ProblemDetailsMessage field values via AkkurateConfig

Open NoiRTvT opened this issue 10 months ago • 4 comments

Right now ProblemDetailsMessage has only hardcoded values in type, title and detail. It will be great to change them to use with different languages and values.

Image

In the future it can be added to registerValidator to manipulate ProblemDetailsMessage per endpoint (as an idea)

NoiRTvT avatar Jan 29 '25 08:01 NoiRTvT

I'm not sure I want to see the payload details to leak into AkkurateConfig because it would imply a tight coupling between this class and the ProblemDetailsMessage one. However, this could be a solution:

install(Akkurate) {
    buildResponse { call, violations ->
        call.respond(
            HttpStatusCode.BadRequest,
            ProblemDetailsMessage(
                type = "https: //google.com",
                title = "The payload is invalid",
                detail = "The payload has problems with validation",
                status = HttpStatusCode.BadRequest,
                fields = violations,
            )
        )
    }
}

What do you think about this?

nesk avatar Jan 29 '25 10:01 nesk

Ok, payload details in AkkurateConfig not needed. But can do bodyConfig and look like this:

Image

And this looks much better

Image

NoiRTvT avatar Jan 29 '25 12:01 NoiRTvT

This still brings some tight coupling, however, we might find a solution with extension functions. I'll think about it.

nesk avatar Jan 29 '25 13:01 nesk

I think status and contentType in AkkurateConfig belong to response of request. Why not add payload details there? In my opinion they have relations.

For example we can get ktor-client where contentType and setBody both in HttpRequestBuilder

Image

NoiRTvT avatar Jan 29 '25 13:01 NoiRTvT