Skip to content

Add option to wrap JAX-RS return types in a configurable generic class #430

@EricWittmann

Description

@EricWittmann

Problem

The JAX-RS codegen generates interface methods that return POJOs directly (e.g., Beer getBeer(...)), which implicitly assumes HTTP 200. To return alternative status codes (201, 202, 204, etc.), developers must either:

  1. Change all methods to return jakarta.ws.rs.Response, losing type safety
  2. Manually edit the generated interfaces to use a framework-specific wrapper

Frameworks like RESTEasy Reactive provide typed wrappers such as RestResponse<T> that preserve type safety while allowing status and header control. The codegen currently has no way to leverage these.

Proposed Solution

Add a genericReturnType setting to JaxRsProjectSettings — a fully-qualified class name (e.g., org.jboss.resteasy.reactive.RestResponse) that wraps all return types:

  • Beer getBeer(...)RestResponse<Beer> getBeer(...)
  • void deleteBeer(...)RestResponse<Void> deleteBeer(...)
  • With reactive mode: CompletionStage<RestResponse<Beer>> getBeer(...)

The setting should be framework-agnostic — any class that takes a single type parameter should work.

Prior Art

PR #295 implemented this feature but became stale due to the package rename and other codebase changes. The approach in that PR is a good design reference: it adds a generateGenericReturnType method to OpenApi2JaxRs and applies the wrapping before reactive type wrapping in the return type chain.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions