File tree Expand file tree Collapse file tree
modules/openapi-generator/src/main
java/org/openapitools/codegen/languages
resources/JavaSpring/libraries/spring-http-interface
samples/client/petstore/spring-http-interface-oauth
src/main/java/org/openapitools/api Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -800,11 +800,6 @@ public void setIsVoid(boolean isVoid) {
800800
801801 prepareVersioningParameters (ops );
802802 handleImplicitHeaders (operation );
803-
804- // Add clientRegistrationId for spring-http-interface with OAuth
805- if (SPRING_HTTP_INTERFACE .equals (library ) && clientRegistrationId != null && !clientRegistrationId .isEmpty ()) {
806- operation .vendorExtensions .put ("clientRegistrationId" , clientRegistrationId );
807- }
808803 }
809804 // The tag for the controller is the first tag of the first operation
810805 final CodegenOperation firstOperation = ops .get (0 );
@@ -813,6 +808,11 @@ public void setIsVoid(boolean isVoid) {
813808 // But use a sensible tag name if there is none
814809 objs .put ("tagName" , "default" .equals (firstTagName ) ? firstOperation .baseName : firstTagName );
815810 objs .put ("tagDescription" , escapeText (firstTag .getDescription ()));
811+
812+ // Add clientRegistrationId for spring-http-interface with OAuth
813+ if (SPRING_HTTP_INTERFACE .equals (library ) && clientRegistrationId != null && !clientRegistrationId .isEmpty ()) {
814+ operations .put ("clientRegistrationId" , clientRegistrationId );
815+ }
816816 }
817817
818818 removeImport (objs , "java.util.List" );
Original file line number Diff line number Diff line change @@ -15,9 +15,9 @@ import org.springframework.http.ResponseEntity;
1515{ {/useResponseEntity} }
1616import org.springframework.web.bind.annotation.*;
1717import org.springframework.web.service.annotation.*;
18- { {#operations} }{ {#operation } } { {#vendorExtensions. clientRegistrationId} }
18+ { {#operations} }{ {#clientRegistrationId} }
1919import org.springframework.security.oauth2.client.annotation.ClientRegistrationId;
20- { {/vendorExtensions. clientRegistrationId} } { {/operation } }{ {/operations} }
20+ { {/clientRegistrationId} }{ {/operations} }
2121import org.springframework.web.multipart.MultipartFile;
2222{ {#reactive} }
2323
@@ -35,6 +35,9 @@ import {{javaxPackage}}.annotation.Generated;
3535{ {> generatedAnnotation} }
3636
3737{ {#operations} }
38+ { {#clientRegistrationId} }
39+ @ClientRegistrationId("{ {clientRegistrationId} }")
40+ { {/clientRegistrationId} }
3841public interface { {classname} } {
3942{{#operation} }
4043
@@ -60,9 +63,6 @@ public interface {{classname}} {
6063 { {#isDeprecated} }
6164 @Deprecated
6265 { {/isDeprecated} }
63- { {#vendorExtensions.clientRegistrationId} }
64- @ClientRegistrationId("{ {vendorExtensions.clientRegistrationId} }")
65- { {/vendorExtensions.clientRegistrationId} }
6666 { {^useResponseEntity} }
6767 @ResponseStatus({ {#springHttpStatus} }{ {#responses.0} }{ {{code} }}{ {/responses.0} }{ {/springHttpStatus} })
6868 { {/useResponseEntity} }
Original file line number Diff line number Diff line change @@ -30,18 +30,23 @@ openapi-generator-cli generate \
3030
3131## Generated Code
3232
33- The generated interface methods will include the ` @ClientRegistrationId ` annotation:
33+ The generated interface will include the ` @ClientRegistrationId ` annotation at the class level :
3434
3535``` java
3636@ClientRegistrationId (" petstore-oauth" )
37- @HttpExchange (
38- method = " GET" ,
39- value = " /pet/{petId}" ,
40- accept = { " application/json" }
41- )
42- ResponseEntity<PetDto > getPetById(@PathVariable (" petId" ) Long petId);
37+ public interface PetApi {
38+
39+ @HttpExchange (
40+ method = " GET" ,
41+ value = " /pet/{petId}" ,
42+ accept = { " application/json" }
43+ )
44+ ResponseEntity<PetDto > getPetById (@PathVariable (" petId" ) Long petId );
45+ }
4346```
4447
48+ This follows the Spring Security recommendation to add ` @ClientRegistrationId ` at the type level to avoid repeating the declaration on every method.
49+
4550## Spring Security Integration
4651
4752This annotation is part of Spring Security's OAuth2 integration for HTTP Service Clients. It automatically associates OAuth2 tokens with HTTP requests.
Original file line number Diff line number Diff line change 2020
2121@ Generated (value = "org.openapitools.codegen.languages.SpringCodegen" )
2222
23+ @ ClientRegistrationId ("petstore-oauth" )
2324public interface PetApi {
2425
2526 /**
@@ -28,7 +29,6 @@ public interface PetApi {
2829 * @param petDto Pet object that needs to be added to the store (required)
2930 * @return successful operation (status code 200)
3031 */
31- @ ClientRegistrationId ("petstore-oauth" )
3232 @ HttpExchange (
3333 method = "POST" ,
3434 value = "/pet" ,
@@ -45,7 +45,6 @@ ResponseEntity<Void> addPet(
4545 * @param petId ID of pet to return (required)
4646 * @return successful operation (status code 200)
4747 */
48- @ ClientRegistrationId ("petstore-oauth" )
4948 @ HttpExchange (
5049 method = "GET" ,
5150 value = "/pet/{petId}" ,
@@ -61,7 +60,6 @@ ResponseEntity<PetDto> getPetById(
6160 * @param petDto Pet object that needs to be updated in the store (required)
6261 * @return successful operation (status code 200)
6362 */
64- @ ClientRegistrationId ("petstore-oauth" )
6563 @ HttpExchange (
6664 method = "PUT" ,
6765 value = "/pet" ,
You can’t perform that action at this time.
0 commit comments