[Java][Client][MicroProfile] Add microprofileRegisterRestClient option
PR checklist
- Read the contribution guidelines.
- Pull Request title clearly describes the work in the pull request and the Pull Request label is correctly set.
- Pull Request is based on the
masterbranch of the repository. - Ran
mvn clean packagein the root of the repository and it passed. - There is a GitHub issue describing the problem, and this Pull Request fixes it.
PR Type
New feature
Description of the changes
When generating a Java client with library=microprofile, the generated API interfaces are always annotated with @RegisterRestClient.
In some use cases, these interfaces are intended to serve as base contracts extended by application-owned CDI REST clients. In that scenario, the base interface should not be registered as a CDI REST client itself.
This PR adds a new boolean config option microprofileRegisterRestClient (default: true) that controls generation of both:
- The
@RegisterRestClientannotation - Its corresponding import
When set to false, the rest of the generated code is unchanged (JAX-RS annotations, operation signatures, return types). Default behavior (true) preserves existing output.
Verification
-
Built the generator:
./mvnw clean package -DskipTests -
Generated clients with
library=microprofileand verified both cases:Default (true):
grep "RegisterRestClient" src/main/java/.../PetApi.java → 2 matches (import + annotation)Option false:
grep "RegisterRestClient" src/main/java/.../PetApi.java → 0 matches -
Added unit tests in
JavaClientCodegenTest:testMicroprofileRegisterRestClientDefaultTrue— verifies annotation present by defaulttestMicroprofileRegisterRestClientDisabled— verifies annotation and import omitted when false
Both tests pass:
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0
Related issues
- Fixes #25264
Technical committee
@OpenAPITools/openapi-generator-java-technical-committee
Summary by cubic
Adds a microprofileRegisterRestClient option (default: true) to the Java client generator for the microprofile library, allowing generated API interfaces to omit the @RegisterRestClient annotation and its import when set to false.
This lets generated interfaces be used as base contracts extended by application-owned CDI REST clients, without registering the base interface itself. When disabled, the rest of the generated code is unchanged.
- Adds the boolean CLI option and wires it through
processOpts. - Guards the annotation and import in the MicroProfile
api.mustachetemplate with the option. - Adds unit tests covering both the default (
true) and disabled (false) cases. - Regenerates MicroProfile samples (extra blank line after
@RegisterRestClient) and generator docs.
Fixes #25264.