vscut
vscut

Reputation: 3

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!

Upvotes: 0

Views: 263

Answers (2)

Jan Kunzmann
Jan Kunzmann

Reputation: 9

Sorry to give you that answer: Quarkus uses "SmallRye Health" which is an implementation of the MicroProfile Health specification. In your example you provide one check. But there could be others around your aop. They are aggregated in the /health endpoinpoint. The model of the CheckResults does not match the model of RFC7807. Just changing the media type does not make any sense to me.

Upvotes: 0

Related Questions