Skip to content

Commit 8680742

Browse files
authored
[Java] Extend JavaSpring apiClient.mustache with option to override contextId for FeignClient (#20943)
1 parent f399910 commit 8680742

File tree

23 files changed

+27
-20
lines changed

23 files changed

+27
-20
lines changed

docs/generators/java-camel.md

+1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
9999
|unhandledException|Declare operation methods to throw a generic exception and allow unhandled exceptions (useful for Spring `@ControllerAdvice` directives).| |false|
100100
|useBeanValidation|Use BeanValidation API annotations| |true|
101101
|useEnumCaseInsensitive|Use `equalsIgnoreCase` when String for enum comparison| |false|
102+
|useFeignClientContextId|Whether to generate Feign client with contextId parameter.| |true|
102103
|useFeignClientUrl|Whether to generate Feign client with url parameter.| |true|
103104
|useJakartaEe|whether to use Jakarta EE namespace instead of javax| |false|
104105
|useOneOfInterfaces|whether to use a java interface to describe a set of oneOf options, where each option is a class that implements the interface| |false|

docs/generators/spring.md

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
9292
|unhandledException|Declare operation methods to throw a generic exception and allow unhandled exceptions (useful for Spring `@ControllerAdvice` directives).| |false|
9393
|useBeanValidation|Use BeanValidation API annotations| |true|
9494
|useEnumCaseInsensitive|Use `equalsIgnoreCase` when String for enum comparison| |false|
95+
|useFeignClientContextId|Whether to generate Feign client with contextId parameter.| |true|
9596
|useFeignClientUrl|Whether to generate Feign client with url parameter.| |true|
9697
|useJakartaEe|whether to use Jakarta EE namespace instead of javax| |false|
9798
|useOneOfInterfaces|whether to use a java interface to describe a set of oneOf options, where each option is a class that implements the interface| |false|

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java

+5
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public class SpringCodegen extends AbstractJavaCodegen
6666
public static final String INTERFACE_ONLY = "interfaceOnly";
6767
public static final String USE_FEIGN_CLIENT_URL = "useFeignClientUrl";
6868
public static final String USE_FEIGN_CLIENT = "useFeignClient";
69+
public static final String USE_FEIGN_CLIENT_CONTEXT_ID = "useFeignClientContextId";
6970
public static final String DELEGATE_PATTERN = "delegatePattern";
7071
public static final String SINGLE_CONTENT_TYPES = "singleContentTypes";
7172
public static final String VIRTUAL_SERVICE = "virtualService";
@@ -124,6 +125,7 @@ public enum RequestMappingMode {
124125

125126
@Setter protected boolean interfaceOnly = false;
126127
@Setter protected boolean useFeignClientUrl = true;
128+
@Setter protected boolean useFeignClientContextId = true;
127129
@Setter protected boolean delegatePattern = false;
128130
protected boolean delegateMethod = false;
129131
@Setter protected boolean singleContentTypes = false;
@@ -200,6 +202,8 @@ public SpringCodegen() {
200202
"Whether to generate only API interface stubs without the server files.", interfaceOnly));
201203
cliOptions.add(CliOption.newBoolean(USE_FEIGN_CLIENT_URL,
202204
"Whether to generate Feign client with url parameter.", useFeignClientUrl));
205+
cliOptions.add(CliOption.newBoolean(USE_FEIGN_CLIENT_CONTEXT_ID,
206+
"Whether to generate Feign client with contextId parameter.", useFeignClientContextId));
203207
cliOptions.add(CliOption.newBoolean(DELEGATE_PATTERN,
204208
"Whether to generate the server files using the delegate pattern", delegatePattern));
205209
cliOptions.add(CliOption.newBoolean(SINGLE_CONTENT_TYPES,
@@ -398,6 +402,7 @@ public void processOpts() {
398402
convertPropertyToBooleanAndWriteBack(VIRTUAL_SERVICE, this::setVirtualService);
399403
convertPropertyToBooleanAndWriteBack(INTERFACE_ONLY, this::setInterfaceOnly);
400404
convertPropertyToBooleanAndWriteBack(USE_FEIGN_CLIENT_URL, this::setUseFeignClientUrl);
405+
convertPropertyToBooleanAndWriteBack(USE_FEIGN_CLIENT_CONTEXT_ID, this::setUseFeignClientContextId);
401406
convertPropertyToBooleanAndWriteBack(DELEGATE_PATTERN, this::setDelegatePattern);
402407
convertPropertyToBooleanAndWriteBack(SINGLE_CONTENT_TYPES, this::setSingleContentTypes);
403408
convertPropertyToBooleanAndWriteBack(SKIP_DEFAULT_INTERFACE, this::setSkipDefaultInterface);

modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-cloud/apiClient.mustache

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ package {{package}};
33
import org.springframework.cloud.openfeign.FeignClient;
44
import {{configPackage}}.ClientConfiguration;
55

6-
@FeignClient(name="${{openbrace}}{{classVarName}}.name:{{classVarName}}{{closebrace}}", {{#useFeignClientUrl}}url="${{openbrace}}{{classVarName}}.url:{{basePath}}{{closebrace}}", {{/useFeignClientUrl}}configuration = ClientConfiguration.class)
6+
@FeignClient(name="${{openbrace}}{{classVarName}}.name:{{classVarName}}{{closebrace}}", {{#useFeignClientContextId}}contextId="${{openbrace}}{{classVarName}}.contextId:${{openbrace}}{{classVarName}}.name{{closebrace}}{{closebrace}}",{{/useFeignClientContextId}} {{#useFeignClientUrl}}url="${{openbrace}}{{classVarName}}.url:{{basePath}}{{closebrace}}",{{/useFeignClientUrl}} configuration = ClientConfiguration.class)
77
public interface {{classname}}Client extends {{classname}} {
88
}

samples/client/petstore/spring-cloud-auth/src/main/java/org/openapitools/api/SomeApiClient.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
import org.springframework.cloud.openfeign.FeignClient;
44
import org.openapitools.configuration.ClientConfiguration;
55

6-
@FeignClient(name="${some.name:some}", url="${some.url:http://localhost}", configuration = ClientConfiguration.class)
6+
@FeignClient(name="${some.name:some}", contextId="${some.contextId:${some.name}}", url="${some.url:http://localhost}", configuration = ClientConfiguration.class)
77
public interface SomeApiClient extends SomeApi {
88
}

samples/client/petstore/spring-cloud-feign-without-url/src/main/java/org/openapitools/api/PetApiClient.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
import org.springframework.cloud.openfeign.FeignClient;
44
import org.openapitools.configuration.ClientConfiguration;
55

6-
@FeignClient(name="${pet.name:pet}", configuration = ClientConfiguration.class)
6+
@FeignClient(name="${pet.name:pet}", contextId="${pet.contextId:${pet.name}}", configuration = ClientConfiguration.class)
77
public interface PetApiClient extends PetApi {
88
}

samples/client/petstore/spring-cloud-feign-without-url/src/main/java/org/openapitools/api/StoreApiClient.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
import org.springframework.cloud.openfeign.FeignClient;
44
import org.openapitools.configuration.ClientConfiguration;
55

6-
@FeignClient(name="${store.name:store}", configuration = ClientConfiguration.class)
6+
@FeignClient(name="${store.name:store}", contextId="${store.contextId:${store.name}}", configuration = ClientConfiguration.class)
77
public interface StoreApiClient extends StoreApi {
88
}

samples/client/petstore/spring-cloud-feign-without-url/src/main/java/org/openapitools/api/UserApiClient.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
import org.springframework.cloud.openfeign.FeignClient;
44
import org.openapitools.configuration.ClientConfiguration;
55

6-
@FeignClient(name="${user.name:user}", configuration = ClientConfiguration.class)
6+
@FeignClient(name="${user.name:user}", contextId="${user.contextId:${user.name}}", configuration = ClientConfiguration.class)
77
public interface UserApiClient extends UserApi {
88
}

samples/client/petstore/spring-cloud/src/main/java/org/openapitools/api/PetApiClient.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
import org.springframework.cloud.openfeign.FeignClient;
44
import org.openapitools.configuration.ClientConfiguration;
55

6-
@FeignClient(name="${pet.name:pet}", url="${pet.url:http://petstore.swagger.io/v2}", configuration = ClientConfiguration.class)
6+
@FeignClient(name="${pet.name:pet}", contextId="${pet.contextId:${pet.name}}", url="${pet.url:http://petstore.swagger.io/v2}", configuration = ClientConfiguration.class)
77
public interface PetApiClient extends PetApi {
88
}

samples/client/petstore/spring-cloud/src/main/java/org/openapitools/api/StoreApiClient.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
import org.springframework.cloud.openfeign.FeignClient;
44
import org.openapitools.configuration.ClientConfiguration;
55

6-
@FeignClient(name="${store.name:store}", url="${store.url:http://petstore.swagger.io/v2}", configuration = ClientConfiguration.class)
6+
@FeignClient(name="${store.name:store}", contextId="${store.contextId:${store.name}}", url="${store.url:http://petstore.swagger.io/v2}", configuration = ClientConfiguration.class)
77
public interface StoreApiClient extends StoreApi {
88
}

samples/client/petstore/spring-cloud/src/main/java/org/openapitools/api/UserApiClient.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
import org.springframework.cloud.openfeign.FeignClient;
44
import org.openapitools.configuration.ClientConfiguration;
55

6-
@FeignClient(name="${user.name:user}", url="${user.url:http://petstore.swagger.io/v2}", configuration = ClientConfiguration.class)
6+
@FeignClient(name="${user.name:user}", contextId="${user.contextId:${user.name}}", url="${user.url:http://petstore.swagger.io/v2}", configuration = ClientConfiguration.class)
77
public interface UserApiClient extends UserApi {
88
}

samples/openapi3/client/petstore/spring-cloud-3-with-optional/src/main/java/org/openapitools/api/PetApiClient.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
import org.springframework.cloud.openfeign.FeignClient;
44
import org.openapitools.configuration.ClientConfiguration;
55

6-
@FeignClient(name="${pet.name:pet}", url="${pet.url:http://petstore.swagger.io/v2}", configuration = ClientConfiguration.class)
6+
@FeignClient(name="${pet.name:pet}", contextId="${pet.contextId:${pet.name}}", url="${pet.url:http://petstore.swagger.io/v2}", configuration = ClientConfiguration.class)
77
public interface PetApiClient extends PetApi {
88
}

samples/openapi3/client/petstore/spring-cloud-3-with-optional/src/main/java/org/openapitools/api/StoreApiClient.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
import org.springframework.cloud.openfeign.FeignClient;
44
import org.openapitools.configuration.ClientConfiguration;
55

6-
@FeignClient(name="${store.name:store}", url="${store.url:http://petstore.swagger.io/v2}", configuration = ClientConfiguration.class)
6+
@FeignClient(name="${store.name:store}", contextId="${store.contextId:${store.name}}", url="${store.url:http://petstore.swagger.io/v2}", configuration = ClientConfiguration.class)
77
public interface StoreApiClient extends StoreApi {
88
}

samples/openapi3/client/petstore/spring-cloud-3-with-optional/src/main/java/org/openapitools/api/UserApiClient.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
import org.springframework.cloud.openfeign.FeignClient;
44
import org.openapitools.configuration.ClientConfiguration;
55

6-
@FeignClient(name="${user.name:user}", url="${user.url:http://petstore.swagger.io/v2}", configuration = ClientConfiguration.class)
6+
@FeignClient(name="${user.name:user}", contextId="${user.contextId:${user.name}}", url="${user.url:http://petstore.swagger.io/v2}", configuration = ClientConfiguration.class)
77
public interface UserApiClient extends UserApi {
88
}

samples/openapi3/client/petstore/spring-cloud-3/src/main/java/org/openapitools/api/PetApiClient.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
import org.springframework.cloud.openfeign.FeignClient;
44
import org.openapitools.configuration.ClientConfiguration;
55

6-
@FeignClient(name="${pet.name:pet}", url="${pet.url:http://petstore.swagger.io/v2}", configuration = ClientConfiguration.class)
6+
@FeignClient(name="${pet.name:pet}", contextId="${pet.contextId:${pet.name}}", url="${pet.url:http://petstore.swagger.io/v2}", configuration = ClientConfiguration.class)
77
public interface PetApiClient extends PetApi {
88
}

samples/openapi3/client/petstore/spring-cloud-3/src/main/java/org/openapitools/api/StoreApiClient.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
import org.springframework.cloud.openfeign.FeignClient;
44
import org.openapitools.configuration.ClientConfiguration;
55

6-
@FeignClient(name="${store.name:store}", url="${store.url:http://petstore.swagger.io/v2}", configuration = ClientConfiguration.class)
6+
@FeignClient(name="${store.name:store}", contextId="${store.contextId:${store.name}}", url="${store.url:http://petstore.swagger.io/v2}", configuration = ClientConfiguration.class)
77
public interface StoreApiClient extends StoreApi {
88
}

samples/openapi3/client/petstore/spring-cloud-3/src/main/java/org/openapitools/api/UserApiClient.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
import org.springframework.cloud.openfeign.FeignClient;
44
import org.openapitools.configuration.ClientConfiguration;
55

6-
@FeignClient(name="${user.name:user}", url="${user.url:http://petstore.swagger.io/v2}", configuration = ClientConfiguration.class)
6+
@FeignClient(name="${user.name:user}", contextId="${user.contextId:${user.name}}", url="${user.url:http://petstore.swagger.io/v2}", configuration = ClientConfiguration.class)
77
public interface UserApiClient extends UserApi {
88
}

samples/openapi3/client/petstore/spring-cloud-async/src/main/java/org/openapitools/api/PetApiClient.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
import org.springframework.cloud.openfeign.FeignClient;
44
import org.openapitools.configuration.ClientConfiguration;
55

6-
@FeignClient(name="${pet.name:pet}", url="${pet.url:http://petstore.swagger.io/v2}", configuration = ClientConfiguration.class)
6+
@FeignClient(name="${pet.name:pet}", contextId="${pet.contextId:${pet.name}}", url="${pet.url:http://petstore.swagger.io/v2}", configuration = ClientConfiguration.class)
77
public interface PetApiClient extends PetApi {
88
}

samples/openapi3/client/petstore/spring-cloud-async/src/main/java/org/openapitools/api/StoreApiClient.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
import org.springframework.cloud.openfeign.FeignClient;
44
import org.openapitools.configuration.ClientConfiguration;
55

6-
@FeignClient(name="${store.name:store}", url="${store.url:http://petstore.swagger.io/v2}", configuration = ClientConfiguration.class)
6+
@FeignClient(name="${store.name:store}", contextId="${store.contextId:${store.name}}", url="${store.url:http://petstore.swagger.io/v2}", configuration = ClientConfiguration.class)
77
public interface StoreApiClient extends StoreApi {
88
}

samples/openapi3/client/petstore/spring-cloud-async/src/main/java/org/openapitools/api/UserApiClient.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
import org.springframework.cloud.openfeign.FeignClient;
44
import org.openapitools.configuration.ClientConfiguration;
55

6-
@FeignClient(name="${user.name:user}", url="${user.url:http://petstore.swagger.io/v2}", configuration = ClientConfiguration.class)
6+
@FeignClient(name="${user.name:user}", contextId="${user.contextId:${user.name}}", url="${user.url:http://petstore.swagger.io/v2}", configuration = ClientConfiguration.class)
77
public interface UserApiClient extends UserApi {
88
}

samples/openapi3/client/petstore/spring-cloud-spring-pageable/src/main/java/org/openapitools/api/PetApiClient.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
import org.springframework.cloud.openfeign.FeignClient;
44
import org.openapitools.configuration.ClientConfiguration;
55

6-
@FeignClient(name="${pet.name:pet}", url="${pet.url:http://petstore.swagger.io/v2}", configuration = ClientConfiguration.class)
6+
@FeignClient(name="${pet.name:pet}", contextId="${pet.contextId:${pet.name}}", url="${pet.url:http://petstore.swagger.io/v2}", configuration = ClientConfiguration.class)
77
public interface PetApiClient extends PetApi {
88
}

samples/openapi3/client/petstore/spring-cloud-spring-pageable/src/main/java/org/openapitools/api/StoreApiClient.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
import org.springframework.cloud.openfeign.FeignClient;
44
import org.openapitools.configuration.ClientConfiguration;
55

6-
@FeignClient(name="${store.name:store}", url="${store.url:http://petstore.swagger.io/v2}", configuration = ClientConfiguration.class)
6+
@FeignClient(name="${store.name:store}", contextId="${store.contextId:${store.name}}", url="${store.url:http://petstore.swagger.io/v2}", configuration = ClientConfiguration.class)
77
public interface StoreApiClient extends StoreApi {
88
}

samples/openapi3/client/petstore/spring-cloud-spring-pageable/src/main/java/org/openapitools/api/UserApiClient.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
import org.springframework.cloud.openfeign.FeignClient;
44
import org.openapitools.configuration.ClientConfiguration;
55

6-
@FeignClient(name="${user.name:user}", url="${user.url:http://petstore.swagger.io/v2}", configuration = ClientConfiguration.class)
6+
@FeignClient(name="${user.name:user}", contextId="${user.contextId:${user.name}}", url="${user.url:http://petstore.swagger.io/v2}", configuration = ClientConfiguration.class)
77
public interface UserApiClient extends UserApi {
88
}

0 commit comments

Comments
 (0)