Skip to content

Commit f1569a0

Browse files
authored
Merge pull request #8131 from kerkhofsd/master
[Spring] Fixes #5244 Include basePath @RequestMapping in Spring API template
2 parents 0ceba0f + ff11895 commit f1569a0

File tree

66 files changed

+76
-8
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+76
-8
lines changed

modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultGenerator.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,15 @@ protected String getScheme() {
107107
}
108108

109109
private String getHost() {
110+
StringBuilder hostBuilder = new StringBuilder();
111+
hostBuilder.append(getHostWithoutBasePath());
112+
if (!StringUtils.isEmpty(swagger.getBasePath()) && !swagger.getBasePath().equals("/")) {
113+
hostBuilder.append(swagger.getBasePath());
114+
}
115+
return hostBuilder.toString();
116+
}
117+
118+
private String getHostWithoutBasePath() {
110119
StringBuilder hostBuilder = new StringBuilder();
111120
hostBuilder.append(getScheme());
112121
hostBuilder.append("://");
@@ -116,9 +125,6 @@ private String getHost() {
116125
hostBuilder.append("localhost");
117126
LOGGER.warn("'host' not defined in the spec. Default to 'localhost'.");
118127
}
119-
if (!StringUtils.isEmpty(swagger.getBasePath()) && !swagger.getBasePath().equals("/")) {
120-
hostBuilder.append(swagger.getBasePath());
121-
}
122128
return hostBuilder.toString();
123129
}
124130

@@ -475,6 +481,7 @@ public int compare(CodegenOperation one, CodegenOperation another) {
475481
});
476482
Map<String, Object> operation = processOperations(config, tag, ops, allModels);
477483

484+
operation.put("hostWithoutBasePath", getHostWithoutBasePath());
478485
operation.put("basePath", basePath);
479486
operation.put("basePathWithoutHost", basePathWithoutHost);
480487
operation.put("contextPath", contextPath);
@@ -715,7 +722,7 @@ protected Map<String, Object> buildSupportFileBundle(List<Object> allOperations,
715722
if (swagger.getHost() != null) {
716723
bundle.put("host", swagger.getHost());
717724
}
718-
725+
bundle.put("hostWithoutBasePath", getHostWithoutBasePath());
719726
bundle.put("swagger", this.swagger);
720727
bundle.put("basePath", basePath);
721728
bundle.put("basePathWithoutHost", basePathWithoutHost);

modules/swagger-codegen/src/main/resources/JavaSpring/api.mustache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import java.util.concurrent.{{^jdk8}}Callable{{/jdk8}}{{#jdk8}}CompletableFuture
5454
{{>generatedAnnotation}}
5555
@Api(value = "{{{baseName}}}", description = "the {{{baseName}}} API")
5656
{{#operations}}
57+
@RequestMapping(value = "{{{contextPath}}}")
5758
public interface {{classname}} {
5859
{{#jdk8}}
5960

modules/swagger-codegen/src/main/resources/JavaSpring/libraries/spring-cloud/apiClient.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ package {{package}};
99
import {{configPackage}}.ClientConfiguration;
1010

1111
{{=<% %>=}}
12-
@FeignClient(name="${<%title%>.name:<%title%>}", url="${<%title%>.url:<%basePath%>}", configuration = ClientConfiguration.class)
12+
@FeignClient(name="${<%title%>.name:<%title%>}", url="${<%title%>.url:<%hostWithoutBasePath%>}", configuration = ClientConfiguration.class)
1313
<%={{ }}=%>
1414
public interface {{classname}}Client extends {{classname}} {
1515
}

samples/client/petstore/spring-cloud/src/main/java/io/swagger/api/PetApi.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.List;
2626

2727
@Api(value = "Pet", description = "the Pet API")
28+
@RequestMapping(value = "/v2")
2829
public interface PetApi {
2930

3031
@ApiOperation(value = "Add a new pet to the store", nickname = "addPet", notes = "", authorizations = {

samples/client/petstore/spring-cloud/src/main/java/io/swagger/api/PetApiClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
import org.springframework.cloud.netflix.feign.FeignClient;
44
import io.swagger.configuration.ClientConfiguration;
55

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

samples/client/petstore/spring-cloud/src/main/java/io/swagger/api/StoreApi.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.List;
2525

2626
@Api(value = "Store", description = "the Store API")
27+
@RequestMapping(value = "/v2")
2728
public interface StoreApi {
2829

2930
@ApiOperation(value = "Delete purchase order by ID", nickname = "deleteOrder", notes = "For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors", tags={ "store", })

samples/client/petstore/spring-cloud/src/main/java/io/swagger/api/StoreApiClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
import org.springframework.cloud.netflix.feign.FeignClient;
44
import io.swagger.configuration.ClientConfiguration;
55

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

samples/client/petstore/spring-cloud/src/main/java/io/swagger/api/UserApi.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.List;
2525

2626
@Api(value = "User", description = "the User API")
27+
@RequestMapping(value = "/v2")
2728
public interface UserApi {
2829

2930
@ApiOperation(value = "Create user", nickname = "createUser", notes = "This can only be done by the logged in user.", tags={ "user", })

samples/client/petstore/spring-cloud/src/main/java/io/swagger/api/UserApiClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
import org.springframework.cloud.netflix.feign.FeignClient;
44
import io.swagger.configuration.ClientConfiguration;
55

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

samples/client/petstore/spring-stubs/src/main/java/io/swagger/api/PetApi.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.List;
2626

2727
@Api(value = "pet", description = "the pet API")
28+
@RequestMapping(value = "/v2")
2829
public interface PetApi {
2930

3031
@ApiOperation(value = "Add a new pet to the store", nickname = "addPet", notes = "", authorizations = {

0 commit comments

Comments
 (0)