Ktor override ProblemDetailsMessage field values via AkkurateConfig
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.
In the future it can be added to registerValidator to manipulate ProblemDetailsMessage per endpoint (as an idea)
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?
Ok, payload details in AkkurateConfig not needed. But can do bodyConfig and look like this:
And this looks much better
This still brings some tight coupling, however, we might find a solution with extension functions. I'll think about it.
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