Skip to content

Conversation

@ng-galien
Copy link

@ng-galien ng-galien commented Jan 19, 2026

Summary

Adds support for generating Spring HTTP Interface clients with the @ClientRegistrationId annotation to enable OAuth2 with Spring Security.

Changes

  • Add clientRegistrationId additional property and CLI option to SpringCodegen
  • Update spring-http-interface template to import and apply @ClientRegistrationId on the interface when set
  • Add unit tests for the new option
  • Include a sample config and generated sample demonstrating usage

Generated Code Example

@ClientRegistrationId("petstore-oauth")
public interface PetApi {

    @HttpExchange(
        method = "GET",
        value = "/pet/{petId}",
        accept = { "application/json" }
    )
    ResponseEntity<PetDto> getPetById(@PathVariable("petId") Long petId);
}

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work.
  • Run the following to build the project and update samples. Commit all changed files.
  • File the PR against the correct branch: master
  • @mention the technical committee members

Java Spring Technical Committee: @cachescrubber @welshm @MelleD @atextor @manedev79 @javisst @borsch @banlevente @Zomzog @martin-mfg

…face

Add support for the @ClientRegistrationId annotation in Spring HTTP Interface
generated clients to enable OAuth2 authentication integration with Spring Security.

Changes:
- Add new clientRegistrationId configuration option in SpringCodegen
- Update api.mustache template to include @ClientRegistrationId annotation
- Add import for org.springframework.security.oauth2.client.annotation.ClientRegistrationId
- Process clientRegistrationId in postProcessOperationsWithModels
- Add sample configuration and example output

The @ClientRegistrationId annotation automatically associates OAuth2 tokens
with HTTP requests when using Spring Security 7.0+ HTTP Service Client integration.

Usage:
  openapi-generator-cli generate -g spring \
    --library spring-http-interface \
    --additional-properties clientRegistrationId=my-oauth-client \
    -i spec.yaml -o ./output

Related documentation:
https://docs.spring.io/spring-security/reference/features/integrations/rest/http-service-client.html
Move the @ClientRegistrationId annotation from individual methods to the
interface class level, following Spring Security's recommended practice.

Changes:
- Update api.mustache to place annotation on interface declaration
- Modify SpringCodegen to set clientRegistrationId on operations map
- Update sample code to show class-level annotation
- Update README with improved example and explanation

This approach is cleaner and avoids repeating the annotation on every method,
as recommended in Spring Security documentation.
Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 5 files

Add tests to verify:
- @ClientRegistrationId annotation is generated when option is set
- Annotation is not present when option is not configured

Also regenerate complete samples for spring-http-interface-oauth config.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@ng-galien ng-galien changed the title Claude/add clientregistrationid annotation rm tc0 [Spring] Add clientRegistrationId option for OAuth2 HTTP Interface Jan 19, 2026
Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 issues found across 63 files (changes from recent commits).

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="samples/client/petstore/spring-http-interface-oauth/src/main/java/org/openapitools/model/UserDto.java">

<violation number="1" location="samples/client/petstore/spring-http-interface-oauth/src/main/java/org/openapitools/model/UserDto.java:226">
P1: toString() prints plaintext password, leaking sensitive data when logged</violation>
</file>

<file name="samples/client/petstore/spring-http-interface-oauth/README.md">

<violation number="1" location="samples/client/petstore/spring-http-interface-oauth/README.md:55">
P2: README requires Spring Boot 3.5+/Security 6.5+ but pom still targets Boot 3.1.3, so documented requirements and code dependencies are inconsistent</violation>
</file>

<file name="samples/client/petstore/spring-http-interface-oauth/src/main/java/org/openapitools/api/FakeApi.java">

<violation number="1" location="samples/client/petstore/spring-http-interface-oauth/src/main/java/org/openapitools/api/FakeApi.java:208">
P2: Multipart file parameter declared with @RequestPart while content type is application/x-www-form-urlencoded; RequestPart requires multipart/form-data so the file cannot be bound.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

sb.append(" firstName: ").append(toIndentedString(firstName)).append("\n");
sb.append(" lastName: ").append(toIndentedString(lastName)).append("\n");
sb.append(" email: ").append(toIndentedString(email)).append("\n");
sb.append(" password: ").append(toIndentedString(password)).append("\n");
Copy link

@cubic-dev-ai cubic-dev-ai bot Jan 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: toString() prints plaintext password, leaking sensitive data when logged

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/petstore/spring-http-interface-oauth/src/main/java/org/openapitools/model/UserDto.java, line 226:

<comment>toString() prints plaintext password, leaking sensitive data when logged</comment>

<file context>
@@ -0,0 +1,244 @@
+    sb.append("    firstName: ").append(toIndentedString(firstName)).append("\n");
+    sb.append("    lastName: ").append(toIndentedString(lastName)).append("\n");
+    sb.append("    email: ").append(toIndentedString(email)).append("\n");
+    sb.append("    password: ").append(toIndentedString(password)).append("\n");
+    sb.append("    phone: ").append(toIndentedString(phone)).append("\n");
+    sb.append("    userStatus: ").append(toIndentedString(userStatus)).append("\n");
</file context>
Fix with Cubic

- Upgrade Spring Boot from 3.1.3 to 3.5.0
- Add spring-boot-starter-oauth2-client dependency

@ClientRegistrationId requires Spring Security 6.5+ (Spring Boot 3.5+)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 issues found across 63 files (changes from recent commits).

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="samples/client/petstore/spring-http-interface-oauth/src/main/java/org/openapitools/model/UserDto.java">

<violation number="1" location="samples/client/petstore/spring-http-interface-oauth/src/main/java/org/openapitools/model/UserDto.java:226">
P2: toString() prints the password value, risking credential leakage when the DTO is logged</violation>
</file>

<file name="samples/client/petstore/spring-http-interface-oauth/README.md">

<violation number="1" location="samples/client/petstore/spring-http-interface-oauth/README.md:87">
P1: Bean configuration example builds a bare RestClient and passes it to HttpInterfacesAbstractConfigurator, which takes a WebClient and applies no OAuth2 configurer—clients will lack OAuth2 support and the snippet won’t compile.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

public class HttpInterfaceConfig extends HttpInterfacesAbstractConfigurator {
public HttpInterfaceConfig() {
super(RestClient.builder()
Copy link

@cubic-dev-ai cubic-dev-ai bot Jan 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: Bean configuration example builds a bare RestClient and passes it to HttpInterfacesAbstractConfigurator, which takes a WebClient and applies no OAuth2 configurer—clients will lack OAuth2 support and the snippet won’t compile.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/petstore/spring-http-interface-oauth/README.md, line 87:

<comment>Bean configuration example builds a bare RestClient and passes it to HttpInterfacesAbstractConfigurator, which takes a WebClient and applies no OAuth2 configurer—clients will lack OAuth2 support and the snippet won’t compile.</comment>

<file context>
@@ -78,31 +77,21 @@ spring:
 
-        return factory.createClient(PetApi.class);
+    public HttpInterfaceConfig() {
+        super(RestClient.builder()
+            .baseUrl("https://petstore.example.com/v2")
+            .build());
</file context>
Fix with Cubic

sb.append(" firstName: ").append(toIndentedString(firstName)).append("\n");
sb.append(" lastName: ").append(toIndentedString(lastName)).append("\n");
sb.append(" email: ").append(toIndentedString(email)).append("\n");
sb.append(" password: ").append(toIndentedString(password)).append("\n");
Copy link

@cubic-dev-ai cubic-dev-ai bot Jan 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: toString() prints the password value, risking credential leakage when the DTO is logged

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/petstore/spring-http-interface-oauth/src/main/java/org/openapitools/model/UserDto.java, line 226:

<comment>toString() prints the password value, risking credential leakage when the DTO is logged</comment>

<file context>
@@ -0,0 +1,244 @@
+    sb.append("    firstName: ").append(toIndentedString(firstName)).append("\n");
+    sb.append("    lastName: ").append(toIndentedString(lastName)).append("\n");
+    sb.append("    email: ").append(toIndentedString(email)).append("\n");
+    sb.append("    password: ").append(toIndentedString(password)).append("\n");
+    sb.append("    phone: ").append(toIndentedString(phone)).append("\n");
+    sb.append("    userStatus: ").append(toIndentedString(userStatus)).append("\n");
</file context>
Fix with Cubic

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants