javamicroservicesquarkuscontent-typesmallrye

How to customize smallrye-health response content type to application/problem+json?


I’m using SmallRye Health in my Quarkus REST application, and by default, it generates responses with a content type of application/json. However, I need the responses to be of media types defined in RFC7807, specifically:

Currently, I have declared the return type as application/problem+json (the one i need) in a static OpenAPI file, but I want the /q/health endpoint(which i remapped to /status) to reflect this return type. Is there a way to customize the output content type for SmallRye Health responses?

Here is what I have tried so far:

Declared the return type in the OpenAPI file. Looked into the SmallRye Health documentation but couldn’t find a direct solution.

import org.eclipse.microprofile.health.HealthCheck;
import org.eclipse.microprofile.health.HealthCheckResponse;
import org.eclipse.microprofile.health.Liveness;
import jakarta.enterprise.context.ApplicationScoped;


@Liveness
@ApplicationScoped
public class LivenessHealthCheck implements HealthCheck {

    @Override
    public HealthCheckResponse call() {
        boolean isAppAlive = checkApplicationHealth();
        if (isAppAlive) {
            return HealthCheckResponse.up("Liveness check");
        } else {
            return HealthCheckResponse.down("Liveness check");
        }
    }

    private boolean checkApplicationHealth() {
        return true;
    }

}

The readiness check is automatically generated based on the Agroal datasource used.

What I need: application/problem+json sample enter image description here

What I am getting: content-type response body

Additional Context:

Quarkus version: 3.8.2 SmallRye Health version: 4.1.0 SDK: OpenJDK version 17.0.9

Any guidance or examples on achieving this customization would be greatly appreciated!


Solution

  • Yes, this is hardcoded in https://github.com/quarkusio/quarkus/blob/main/extensions/smallrye-health/runtime/src/main/java/io/quarkus/smallrye/health/runtime/SmallRyeHealthHandlerBase.java#L63.

    However, I don't see any reason why not to make it overridable, thus https://github.com/quarkusio/quarkus/issues/43125.