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

smallrye-openapi scan for @ServerExceptionMapper annotation #44035

Closed
indiealexh opened this issue Oct 23, 2024 · 3 comments · Fixed by #44996
Closed

smallrye-openapi scan for @ServerExceptionMapper annotation #44035

indiealexh opened this issue Oct 23, 2024 · 3 comments · Fixed by #44996
Milestone

Comments

@indiealexh
Copy link

indiealexh commented Oct 23, 2024

Description

This is a reopening of #31828, but I think it is worth consideration.

smallrye-openapi can scan for @Provider ExceptionMappers and add them to endpoints that throw that exception.

e.g.

@Path("/bundles")
@Produces({MediaType.APPLICATION_JSON})
@Consumes(MediaType.APPLICATION_JSON)
@Tag(name = "Bundles")
public class BundlesResource {
    [...]
    @POST
    @Path("/{bundleId}/actions/render")
    @APIResponses({
            @APIResponse(responseCode = "200", description = "Render bundle"),
    })
    public Uni<BundleRender> renderBundle(@RestPath long bundleId, BundleRenderRequest bundleRenderRequest) throws BundleRenderValidationException {
        return bundleRenderService.renderBundle(bundleId, bundleRenderRequest);
    }
   [...]
}

public class BundleRenderValidationException extends WebApplicationException {
    public BundleRenderValidationException(String exceptionMessage) {
        super(
                Response
                        .status(Response.Status.BAD_REQUEST)
                        .entity(new ErrorResponse("Bundle Render Request failed validation", List.of(new String[]{exceptionMessage})))
                        .build()
        );
    }
}

@Provider
public class BundleRenderValidationExceptionMapper implements ExceptionMapper<BundleRenderValidationException> {
    @Override
    @APIResponse(
            responseCode = "400",
            description = "Validation of bundle failed",
            content = @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))
    )
    public Response toResponse(BundleRenderValidationException exception) {
        return exception.getResponse();
    }
}

Image

The same should be possible for exceptions mapped by using @ServerExceptionMapper, happy to open this ticker with https://github.com/smallrye/smallrye-open-api if that is the better place to do so, but it seems like it should be part of the Quarkus extension given the annotation is RestEasy specific.

Implementation ideas

No response

Copy link

quarkus-bot bot commented Oct 23, 2024

/cc @EricWittmann (openapi), @Ladicek (smallrye), @MikeEdgar (openapi), @jmartisk (smallrye), @phillip-kruger (openapi,smallrye), @radcortez (smallrye)

@phillip-kruger
Copy link
Member

I think you can open this in SmallRye OpenAPI. We are already doing RESTEasy things there, see https://github.com/smallrye/smallrye-open-api/blob/main/extension-jaxrs/src/main/java/io/smallrye/openapi/jaxrs/RestEasyConstants.java for example

@indiealexh
Copy link
Author

I think you can open this in SmallRye OpenAPI. We are already doing RESTEasy things there, see https://github.com/smallrye/smallrye-open-api/blob/main/extension-jaxrs/src/main/java/io/smallrye/openapi/jaxrs/RestEasyConstants.java for example

Thanks, I will do that.

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

Successfully merging a pull request may close this issue.

3 participants