Skip to content

Ng galien claude/add clientregistrationid annotation rm tc0#23807

Draft
wing328 wants to merge 11 commits into
masterfrom
ng-galien-claude/add-clientregistrationid-annotation-rmTC0
Draft

Ng galien claude/add clientregistrationid annotation rm tc0#23807
wing328 wants to merge 11 commits into
masterfrom
ng-galien-claude/add-clientregistrationid-annotation-rmTC0

Conversation

@wing328
Copy link
Copy Markdown
Member

@wing328 wing328 commented May 18, 2026

based on #22726

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. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • File the PR against the correct branch: master (upcoming 7.x.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR solves a reported issue, reference it using GitHub's linking syntax (e.g., having "fixes #123" present in the PR description)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

Summary by cubic

Adds a clientRegistrationId option to the Spring generator to emit @ClientRegistrationId on spring-http-interface clients, enabling OAuth2 token propagation with Spring Security. Also updates the spring-http-interface pom template to Spring Boot 3.5.0 and adds a conditional spring-boot-starter-oauth2-client dependency when the option is used.

  • New Features

    • Add clientRegistrationId additional property in SpringCodegen.
    • Generate class-level @ClientRegistrationId("...") for API interfaces in spring-http-interface.
    • Include org.springframework.security.oauth2.client.annotation.ClientRegistrationId import in api.mustache.
    • Update pom-sb3.mustache to use Spring Boot 3.5.0 and add spring-boot-starter-oauth2-client when clientRegistrationId is set.
  • Docs & Samples

    • Document option in docs/generators/spring.md and docs/generators/java-camel.md.
    • Add config bin/configs/spring-http-interface-oauth.yaml and sample at samples/client/petstore/spring-http-interface-oauth.
    • Add CI entry to build the new sample.
    • Add unit test in SpringCodegenTest to verify the annotation is generated.

Written for commit bbeae12. Summary will update on new commits. Review in cubic

claude and others added 10 commits May 14, 2026 17:05
…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>
- 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>
- 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>
Restore Spring Boot 3.5.0 and spring-boot-starter-oauth2-client
dependency in the spring-http-interface-oauth pom (template default
is now 3.3.13, but @ClientRegistrationId requires 6.5+/Boot 3.5+).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@wing328
Copy link
Copy Markdown
Member Author

wing328 commented May 18, 2026

Copy link
Copy Markdown
Contributor

@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 69 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


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

<violation number="1" location="samples/client/petstore/spring-http-interface-oauth/README.md:56">
P2: The documented minimum Spring Security version is incorrect for `@ClientRegistrationId`; this annotation is available starting in Spring Security 7.0.</violation>

<violation number="2" location="samples/client/petstore/spring-http-interface-oauth/README.md:96">
P2: The configuration example is incomplete for `@ClientRegistrationId`: it adds the OAuth2 interceptor but does not configure `HttpServiceProxyFactory` with `ClientRegistrationIdProcessor`.</violation>
</file>

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

<violation number="1" location="samples/client/petstore/spring-http-interface-oauth/pom.xml:47">
P1: Missing OAuth2 client dependency for generated `@ClientRegistrationId` annotations causes compilation failure.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread samples/client/petstore/spring-http-interface-oauth/pom.xml
### Requirements

- Spring Boot 3.5+
- Spring Security 6.5+
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: The documented minimum Spring Security version is incorrect for @ClientRegistrationId; this annotation is available starting in Spring Security 7.0.

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 56:

<comment>The documented minimum Spring Security version is incorrect for `@ClientRegistrationId`; this annotation is available starting in Spring Security 7.0.</comment>

<file context>
@@ -0,0 +1,108 @@
+### Requirements
+
+- Spring Boot 3.5+
+- Spring Security 6.5+
+
+### Application Properties
</file context>

.requestInterceptor(interceptor)
.build();

HttpServiceProxyFactory factory = HttpServiceProxyFactory
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: The configuration example is incomplete for @ClientRegistrationId: it adds the OAuth2 interceptor but does not configure HttpServiceProxyFactory with ClientRegistrationIdProcessor.

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 96:

<comment>The configuration example is incomplete for `@ClientRegistrationId`: it adds the OAuth2 interceptor but does not configure `HttpServiceProxyFactory` with `ClientRegistrationIdProcessor`.</comment>

<file context>
@@ -0,0 +1,108 @@
+            .requestInterceptor(interceptor)
+            .build();
+
+        HttpServiceProxyFactory factory = HttpServiceProxyFactory
+            .builderFor(RestClientAdapter.create(restClient))
+            .build();
</file context>

@wing328
Copy link
Copy Markdown
Member Author

wing328 commented May 18, 2026

update: i pushed bbeae12 to update the mustache templates as well.

<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.13</version>
<version>3.5.0</version>
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

looks like updating this will break current supported use cases: https://github.com/OpenAPITools/openapi-generator/actions/runs/26022364837/job/76486919726?pr=23807

so i suggest we update this and address any broken code in a separate PR instead.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

update: filed #23809 to update it and the templates (which broke) as well and all tests passed

@wing328 wing328 marked this pull request as draft May 18, 2026 10:59
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.

3 participants