Skip to content

[Spring] Add clientRegistrationId option for OAuth2 HTTP Interface - #22726

Merged
wing328 merged 9 commits into
OpenAPITools:masterfrom
ng-galien:claude/add-clientregistrationid-annotation-rmTC0
May 24, 2026
Merged

[Spring] Add clientRegistrationId option for OAuth2 HTTP Interface#22726
wing328 merged 9 commits into
OpenAPITools:masterfrom
ng-galien:claude/add-clientregistrationid-annotation-rmTC0

Conversation

@ng-galien

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

Copy link
Copy Markdown
Contributor

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

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

Copy link
Copy Markdown
Contributor

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

@ng-galien ng-galien changed the title Claude/add clientregistrationid annotation rm tc0 [Spring] Add clientRegistrationId option for OAuth2 HTTP Interface Jan 19, 2026

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

Copy link
Copy Markdown
Contributor

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");

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

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is generated Petstore sample behavior and is not specific to this PR’s clientRegistrationId support. Addressing it properly would require a broader generator/template change to support sensitive field redaction across generated models, so I’m leaving it out of scope here.

Comment thread samples/client/petstore/spring-http-interface-oauth/README.md Outdated

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

Copy link
Copy Markdown
Contributor

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.

Comment thread samples/client/petstore/spring-http-interface-oauth/README.md Outdated
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");

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

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is generated Petstore sample behavior and is not specific to this PR’s clientRegistrationId support. Addressing it properly would require a broader generator/template change to support sensitive field redaction across generated models, so I’m leaving it out of scope here.

@wing328

wing328 commented Jan 28, 2026

Copy link
Copy Markdown
Member

thanks for the PR

can you please review the build failure when you've time?

@ng-galien
ng-galien force-pushed the claude/add-clientregistrationid-annotation-rmTC0 branch from 8b6063c to 50178d9 Compare January 31, 2026 23:54
@ng-galien
ng-galien force-pushed the claude/add-clientregistrationid-annotation-rmTC0 branch from fbcfeea to 4c69be8 Compare March 6, 2026 18:41
@ng-galien

Copy link
Copy Markdown
Contributor Author

Hi @wing328, thanks for the review and for your patience!

I've rebased the branch on the latest master, resolved the merge conflicts, and regenerated all samples and docs. The build failures should now be fixed.

@wing328

wing328 commented May 12, 2026

Copy link
Copy Markdown
Member

please resolve the merge conflicts when you've time and PM me via Slack to get it reviewed and merged.

https://join.slack.com/t/openapi-generator/shared_invite/zt-36ucx4ybl-jYrN6euoYn6zxXNZdldoZA

@ng-galien
ng-galien force-pushed the claude/add-clientregistrationid-annotation-rmTC0 branch 2 times, most recently from ca33c94 to f960433 Compare May 15, 2026 09:50
claude and others added 9 commits May 23, 2026 17:50
…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.
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>
- Add README.md to .openapi-generator-ignore to preserve custom docs
- Include proper OAuth2ClientHttpRequestInterceptor configuration example
- Document Spring Boot 3.5+ / Spring Security 6.5+ requirements

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Make the spring-http-interface-oauth sample fully generator-driven
instead of hand-patching its pom:
- pom-sb3/sb4.mustache: emit spring-boot-starter-oauth2-client when
  clientRegistrationId is set
- spring-http-interface-oauth.yaml: set parent to Spring Boot 3.5.0
  (required by @ClientRegistrationId / Spring Security 6.5+)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@ng-galien
ng-galien force-pushed the claude/add-clientregistrationid-annotation-rmTC0 branch from f960433 to 876a6c5 Compare May 23, 2026 16:40
@ng-galien

Copy link
Copy Markdown
Contributor Author

Hi @wing328, I rebased the branch on current master, resolved the conflicts, regenerated the affected docs and samples, and fixed the Spring Security compatibility issue by requiring Spring Boot 4 for clientRegistrationId. Local targeted SpringCodegen tests and the OAuth sample build pass.

@ng-galien

Copy link
Copy Markdown
Contributor Author

Hi @wing328, sorry for the delay on my side and for the extra work on #23807. Thanks for helping move this forward.

Comment thread bin/configs/spring-http-interface-oauth.yaml
@wing328
wing328 merged commit 9022c9a into OpenAPITools:master May 24, 2026
87 of 91 checks passed
wing328 added a commit that referenced this pull request May 24, 2026
* add new folder to the workflow

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants