Skip to content

Commit 9916dc8

Browse files
MelleDJayAtOC
authored andcommitted
Remove wrong request mapping for feign clients (OpenAPITools#13546)
* Remove request mapping * Fix bug for feign clients * Fix test * Fix test files * Rebuild * Revert change
1 parent eeffb68 commit 9916dc8

File tree

21 files changed

+24
-18
lines changed

21 files changed

+24
-18
lines changed

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

+8
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public class SpringCodegen extends AbstractJavaCodegen
8383
public static final String BASE_PACKAGE = "basePackage";
8484
public static final String INTERFACE_ONLY = "interfaceOnly";
8585
public static final String USE_FEIGN_CLIENT_URL = "useFeignClientUrl";
86+
public static final String USE_FEIGN_CLIENT = "useFeignClient";
8687
public static final String DELEGATE_PATTERN = "delegatePattern";
8788
public static final String SINGLE_CONTENT_TYPES = "singleContentTypes";
8889
public static final String VIRTUAL_SERVICE = "virtualService";
@@ -110,6 +111,7 @@ public class SpringCodegen extends AbstractJavaCodegen
110111
protected String basePackage = "org.openapitools";
111112
protected boolean interfaceOnly = false;
112113
protected boolean useFeignClientUrl = true;
114+
protected boolean useFeignClient = false;
113115
protected boolean delegatePattern = false;
114116
protected boolean delegateMethod = false;
115117
protected boolean singleContentTypes = false;
@@ -491,6 +493,8 @@ public void processOpts() {
491493
additionalProperties.put(SINGLE_CONTENT_TYPES, "true");
492494
this.setSingleContentTypes(true);
493495
}
496+
additionalProperties.put(USE_FEIGN_CLIENT, "true");
497+
this.setUseFeignClient(true);
494498
} else {
495499
apiTemplateFiles.put("apiController.mustache", "Controller.java");
496500
supportingFiles.add(new SupportingFile("application.mustache",
@@ -846,6 +850,10 @@ public void setSingleContentTypes(boolean singleContentTypes) {
846850
this.singleContentTypes = singleContentTypes;
847851
}
848852

853+
public void setUseFeignClient( boolean useFeignClient ) {
854+
this.useFeignClient = useFeignClient;
855+
}
856+
849857
public void setSkipDefaultInterface(boolean skipDefaultInterface) {
850858
this.skipDefaultInterface = skipDefaultInterface;
851859
}

modules/openapi-generator/src/main/resources/JavaSpring/api.mustache

+2
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,11 @@ import javax.annotation.Generated;
9696
{{#virtualService}}
9797
@VirtualService
9898
{{/virtualService}}
99+
{{^useFeignClient}}
99100
{{=<% %>=}}
100101
@RequestMapping("${openapi.<%title%>.base-path:<%>defaultBasePath%>}")
101102
<%={{ }}=%>
103+
{{/useFeignClient}}
102104
public interface {{classname}} {
103105
{{#jdk8-default-interface}}
104106
{{^isDelegate}}

modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java

+14
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,20 @@ public void testRequestMappingAnnotation() throws IOException {
547547
assertFileNotContains(petApiControllerFile.toPath(), "@RequestMapping(\"${openapi.openAPIPetstore.base-path:/v2}\")");
548548
}
549549

550+
@Test
551+
public void testNoRequestMappingAnnotation() throws IOException {
552+
final SpringCodegen codegen = new SpringCodegen();
553+
codegen.setLibrary( "spring-cloud" );
554+
555+
final Map<String, File> files = generateFiles( codegen, "src/test/resources/2_0/petstore.yaml" );
556+
557+
// Check that the @RequestMapping annotation is not generated in the Api file
558+
final File petApiFile = files.get( "PetApi.java" );
559+
JavaFileAssert.assertThat( petApiFile ).assertTypeAnnotations().hasSize( 3 ).containsWithName( "Validated" )
560+
.containsWithName( "Generated" ).containsWithName( "Tag" );
561+
562+
}
563+
550564
@Test
551565
public void testSettersForConfigValues() throws Exception {
552566
final SpringCodegen codegen = new SpringCodegen();

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

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen")
2828
@Validated
2929
@Api(value = "Pet", description = "Everything about your Pets")
30-
@RequestMapping("${openapi.openAPIPetstore.base-path:/v2}")
3130
public interface PetApi {
3231

3332
/**

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

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen")
2828
@Validated
2929
@Api(value = "Store", description = "Access to Petstore orders")
30-
@RequestMapping("${openapi.openAPIPetstore.base-path:/v2}")
3130
public interface StoreApi {
3231

3332
/**

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

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen")
2929
@Validated
3030
@Api(value = "User", description = "Operations about user")
31-
@RequestMapping("${openapi.openAPIPetstore.base-path:/v2}")
3231
public interface UserApi {
3332

3433
/**

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

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen")
2727
@Validated
2828
@Api(value = "Pet", description = "Everything about your Pets")
29-
@RequestMapping("${openapi.openAPIPetstore.base-path:/v2}")
3029
public interface PetApi {
3130

3231
/**

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

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen")
2727
@Validated
2828
@Api(value = "Store", description = "Access to Petstore orders")
29-
@RequestMapping("${openapi.openAPIPetstore.base-path:/v2}")
3029
public interface StoreApi {
3130

3231
/**

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

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen")
2828
@Validated
2929
@Api(value = "User", description = "Operations about user")
30-
@RequestMapping("${openapi.openAPIPetstore.base-path:/v2}")
3130
public interface UserApi {
3231

3332
/**

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

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen")
2929
@Validated
3030
@Api(value = "Pet", description = "Everything about your Pets")
31-
@RequestMapping("${openapi.openAPIPetstore.base-path:/v2}")
3231
public interface PetApi {
3332

3433
/**

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

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen")
2727
@Validated
2828
@Api(value = "Store", description = "Access to Petstore orders")
29-
@RequestMapping("${openapi.openAPIPetstore.base-path:/v2}")
3029
public interface StoreApi {
3130

3231
/**

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

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen")
2828
@Validated
2929
@Api(value = "User", description = "Operations about user")
30-
@RequestMapping("${openapi.openAPIPetstore.base-path:/v2}")
3130
public interface UserApi {
3231

3332
/**

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

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen")
2727
@Validated
2828
@Api(value = "Pet", description = "Everything about your Pets")
29-
@RequestMapping("${openapi.openAPIPetstore.base-path:/v2}")
3029
public interface PetApi {
3130

3231
/**

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

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen")
2727
@Validated
2828
@Api(value = "Store", description = "Access to Petstore orders")
29-
@RequestMapping("${openapi.openAPIPetstore.base-path:/v2}")
3029
public interface StoreApi {
3130

3231
/**

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

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen")
2828
@Validated
2929
@Api(value = "User", description = "Operations about user")
30-
@RequestMapping("${openapi.openAPIPetstore.base-path:/v2}")
3130
public interface UserApi {
3231

3332
/**

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

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen")
3535
@Validated
3636
@Tag(name = "Pet", description = "Everything about your Pets")
37-
@RequestMapping("${openapi.openAPIPetstore.base-path:/v2}")
3837
public interface PetApi {
3938

4039
/**

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

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen")
3535
@Validated
3636
@Tag(name = "Store", description = "Access to Petstore orders")
37-
@RequestMapping("${openapi.openAPIPetstore.base-path:/v2}")
3837
public interface StoreApi {
3938

4039
/**

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

-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen")
3636
@Validated
3737
@Tag(name = "User", description = "Operations about user")
38-
@RequestMapping("${openapi.openAPIPetstore.base-path:/v2}")
3938
public interface UserApi {
4039

4140
/**

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

-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen")
3636
@Validated
3737
@Tag(name = "Pet", description = "Everything about your Pets")
38-
@RequestMapping("${openapi.openAPIPetstore.base-path:/v2}")
3938
public interface PetApi {
4039

4140
/**

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

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen")
3434
@Validated
3535
@Tag(name = "Store", description = "Access to Petstore orders")
36-
@RequestMapping("${openapi.openAPIPetstore.base-path:/v2}")
3736
public interface StoreApi {
3837

3938
/**

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

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen")
3535
@Validated
3636
@Tag(name = "User", description = "Operations about user")
37-
@RequestMapping("${openapi.openAPIPetstore.base-path:/v2}")
3837
public interface UserApi {
3938

4039
/**

0 commit comments

Comments
 (0)