Skip to content

Commit

Permalink
Merge pull request #8131 from kerkhofsd/master
Browse files Browse the repository at this point in the history
[Spring] Fixes #5244 Include basePath @RequestMapping in Spring API template
  • Loading branch information
HugoMario committed Dec 2, 2019
2 parents 0ceba0f + ff11895 commit f1569a0
Show file tree
Hide file tree
Showing 66 changed files with 76 additions and 8 deletions.
Expand Up @@ -107,6 +107,15 @@ protected String getScheme() {
}

private String getHost() {
StringBuilder hostBuilder = new StringBuilder();
hostBuilder.append(getHostWithoutBasePath());
if (!StringUtils.isEmpty(swagger.getBasePath()) && !swagger.getBasePath().equals("/")) {
hostBuilder.append(swagger.getBasePath());
}
return hostBuilder.toString();
}

private String getHostWithoutBasePath() {
StringBuilder hostBuilder = new StringBuilder();
hostBuilder.append(getScheme());
hostBuilder.append("://");
Expand All @@ -116,9 +125,6 @@ private String getHost() {
hostBuilder.append("localhost");
LOGGER.warn("'host' not defined in the spec. Default to 'localhost'.");
}
if (!StringUtils.isEmpty(swagger.getBasePath()) && !swagger.getBasePath().equals("/")) {
hostBuilder.append(swagger.getBasePath());
}
return hostBuilder.toString();
}

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

operation.put("hostWithoutBasePath", getHostWithoutBasePath());
operation.put("basePath", basePath);
operation.put("basePathWithoutHost", basePathWithoutHost);
operation.put("contextPath", contextPath);
Expand Down Expand Up @@ -715,7 +722,7 @@ protected Map<String, Object> buildSupportFileBundle(List<Object> allOperations,
if (swagger.getHost() != null) {
bundle.put("host", swagger.getHost());
}

bundle.put("hostWithoutBasePath", getHostWithoutBasePath());
bundle.put("swagger", this.swagger);
bundle.put("basePath", basePath);
bundle.put("basePathWithoutHost", basePathWithoutHost);
Expand Down
Expand Up @@ -54,6 +54,7 @@ import java.util.concurrent.{{^jdk8}}Callable{{/jdk8}}{{#jdk8}}CompletableFuture
{{>generatedAnnotation}}
@Api(value = "{{{baseName}}}", description = "the {{{baseName}}} API")
{{#operations}}
@RequestMapping(value = "{{{contextPath}}}")
public interface {{classname}} {
{{#jdk8}}

Expand Down
Expand Up @@ -9,7 +9,7 @@ package {{package}};
import {{configPackage}}.ClientConfiguration;

{{=<% %>=}}
@FeignClient(name="${<%title%>.name:<%title%>}", url="${<%title%>.url:<%basePath%>}", configuration = ClientConfiguration.class)
@FeignClient(name="${<%title%>.name:<%title%>}", url="${<%title%>.url:<%hostWithoutBasePath%>}", configuration = ClientConfiguration.class)
<%={{ }}=%>
public interface {{classname}}Client extends {{classname}} {
}
Expand Up @@ -25,6 +25,7 @@
import java.util.List;

@Api(value = "Pet", description = "the Pet API")
@RequestMapping(value = "/v2")
public interface PetApi {

@ApiOperation(value = "Add a new pet to the store", nickname = "addPet", notes = "", authorizations = {
Expand Down
Expand Up @@ -3,6 +3,6 @@
import org.springframework.cloud.netflix.feign.FeignClient;
import io.swagger.configuration.ClientConfiguration;

@FeignClient(name="${swaggerPetstore.name:swaggerPetstore}", url="${swaggerPetstore.url:http://petstore.swagger.io/v2}", configuration = ClientConfiguration.class)
@FeignClient(name="${swaggerPetstore.name:swaggerPetstore}", url="${swaggerPetstore.url:http://petstore.swagger.io}", configuration = ClientConfiguration.class)
public interface PetApiClient extends PetApi {
}
Expand Up @@ -24,6 +24,7 @@
import java.util.List;

@Api(value = "Store", description = "the Store API")
@RequestMapping(value = "/v2")
public interface StoreApi {

@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", })
Expand Down
Expand Up @@ -3,6 +3,6 @@
import org.springframework.cloud.netflix.feign.FeignClient;
import io.swagger.configuration.ClientConfiguration;

@FeignClient(name="${swaggerPetstore.name:swaggerPetstore}", url="${swaggerPetstore.url:http://petstore.swagger.io/v2}", configuration = ClientConfiguration.class)
@FeignClient(name="${swaggerPetstore.name:swaggerPetstore}", url="${swaggerPetstore.url:http://petstore.swagger.io}", configuration = ClientConfiguration.class)
public interface StoreApiClient extends StoreApi {
}
Expand Up @@ -24,6 +24,7 @@
import java.util.List;

@Api(value = "User", description = "the User API")
@RequestMapping(value = "/v2")
public interface UserApi {

@ApiOperation(value = "Create user", nickname = "createUser", notes = "This can only be done by the logged in user.", tags={ "user", })
Expand Down
Expand Up @@ -3,6 +3,6 @@
import org.springframework.cloud.netflix.feign.FeignClient;
import io.swagger.configuration.ClientConfiguration;

@FeignClient(name="${swaggerPetstore.name:swaggerPetstore}", url="${swaggerPetstore.url:http://petstore.swagger.io/v2}", configuration = ClientConfiguration.class)
@FeignClient(name="${swaggerPetstore.name:swaggerPetstore}", url="${swaggerPetstore.url:http://petstore.swagger.io}", configuration = ClientConfiguration.class)
public interface UserApiClient extends UserApi {
}
Expand Up @@ -25,6 +25,7 @@
import java.util.List;

@Api(value = "pet", description = "the pet API")
@RequestMapping(value = "/v2")
public interface PetApi {

@ApiOperation(value = "Add a new pet to the store", nickname = "addPet", notes = "", authorizations = {
Expand Down
Expand Up @@ -24,6 +24,7 @@
import java.util.List;

@Api(value = "store", description = "the store API")
@RequestMapping(value = "/v2")
public interface StoreApi {

@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", })
Expand Down
Expand Up @@ -24,6 +24,7 @@
import java.util.List;

@Api(value = "user", description = "the user API")
@RequestMapping(value = "/v2")
public interface UserApi {

@ApiOperation(value = "Create user", nickname = "createUser", notes = "This can only be done by the logged in user.", tags={ "user", })
Expand Down
Expand Up @@ -31,6 +31,7 @@
import java.util.concurrent.CompletableFuture;

@Api(value = "another-fake", description = "the another-fake API")
@RequestMapping(value = "/v2")
public interface AnotherFakeApi {

Logger log = LoggerFactory.getLogger(AnotherFakeApi.class);
Expand Down
Expand Up @@ -36,6 +36,7 @@
import java.util.concurrent.CompletableFuture;

@Api(value = "fake", description = "the fake API")
@RequestMapping(value = "/v2")
public interface FakeApi {

Logger log = LoggerFactory.getLogger(FakeApi.class);
Expand Down
Expand Up @@ -31,6 +31,7 @@
import java.util.concurrent.CompletableFuture;

@Api(value = "fake_classname_test", description = "the fake_classname_test API")
@RequestMapping(value = "/v2")
public interface FakeClassnameTestApi {

Logger log = LoggerFactory.getLogger(FakeClassnameTestApi.class);
Expand Down
Expand Up @@ -33,6 +33,7 @@
import java.util.concurrent.CompletableFuture;

@Api(value = "pet", description = "the pet API")
@RequestMapping(value = "/v2")
public interface PetApi {

Logger log = LoggerFactory.getLogger(PetApi.class);
Expand Down
Expand Up @@ -32,6 +32,7 @@
import java.util.concurrent.CompletableFuture;

@Api(value = "store", description = "the store API")
@RequestMapping(value = "/v2")
public interface StoreApi {

Logger log = LoggerFactory.getLogger(StoreApi.class);
Expand Down
Expand Up @@ -32,6 +32,7 @@
import java.util.concurrent.CompletableFuture;

@Api(value = "user", description = "the user API")
@RequestMapping(value = "/v2")
public interface UserApi {

Logger log = LoggerFactory.getLogger(UserApi.class);
Expand Down
Expand Up @@ -30,6 +30,7 @@
import java.util.Optional;

@Api(value = "another-fake", description = "the another-fake API")
@RequestMapping(value = "/v2")
public interface AnotherFakeApi {

Logger log = LoggerFactory.getLogger(AnotherFakeApi.class);
Expand Down
Expand Up @@ -35,6 +35,7 @@
import java.util.Optional;

@Api(value = "fake", description = "the fake API")
@RequestMapping(value = "/v2")
public interface FakeApi {

Logger log = LoggerFactory.getLogger(FakeApi.class);
Expand Down
Expand Up @@ -30,6 +30,7 @@
import java.util.Optional;

@Api(value = "fake_classname_test", description = "the fake_classname_test API")
@RequestMapping(value = "/v2")
public interface FakeClassnameTestApi {

Logger log = LoggerFactory.getLogger(FakeClassnameTestApi.class);
Expand Down
Expand Up @@ -32,6 +32,7 @@
import java.util.Optional;

@Api(value = "pet", description = "the pet API")
@RequestMapping(value = "/v2")
public interface PetApi {

Logger log = LoggerFactory.getLogger(PetApi.class);
Expand Down
Expand Up @@ -31,6 +31,7 @@
import java.util.Optional;

@Api(value = "store", description = "the store API")
@RequestMapping(value = "/v2")
public interface StoreApi {

Logger log = LoggerFactory.getLogger(StoreApi.class);
Expand Down
Expand Up @@ -31,6 +31,7 @@
import java.util.Optional;

@Api(value = "user", description = "the user API")
@RequestMapping(value = "/v2")
public interface UserApi {

Logger log = LoggerFactory.getLogger(UserApi.class);
Expand Down
Expand Up @@ -23,6 +23,7 @@
import java.util.List;

@Api(value = "another-fake", description = "the another-fake API")
@RequestMapping(value = "/v2")
public interface AnotherFakeApi {

@ApiOperation(value = "To test special tags", nickname = "testSpecialTags", notes = "To test special tags", response = Client.class, tags={ "$another-fake?", })
Expand Down
Expand Up @@ -28,6 +28,7 @@
import java.util.List;

@Api(value = "fake", description = "the fake API")
@RequestMapping(value = "/v2")
public interface FakeApi {

@ApiOperation(value = "", nickname = "fakeOuterBooleanSerialize", notes = "Test serialization of outer boolean types", response = Boolean.class, tags={ "fake", })
Expand Down
Expand Up @@ -23,6 +23,7 @@
import java.util.List;

@Api(value = "fake_classname_test", description = "the fake_classname_test API")
@RequestMapping(value = "/v2")
public interface FakeClassnameTestApi {

@ApiOperation(value = "To test class name in snake case", nickname = "testClassname", notes = "To test class name in snake case", response = Client.class, authorizations = {
Expand Down
Expand Up @@ -25,6 +25,7 @@
import java.util.List;

@Api(value = "pet", description = "the pet API")
@RequestMapping(value = "/v2")
public interface PetApi {

@ApiOperation(value = "Add a new pet to the store", nickname = "addPet", notes = "", authorizations = {
Expand Down
Expand Up @@ -24,6 +24,7 @@
import java.util.List;

@Api(value = "store", description = "the store API")
@RequestMapping(value = "/v2")
public interface StoreApi {

@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", })
Expand Down
Expand Up @@ -24,6 +24,7 @@
import java.util.List;

@Api(value = "user", description = "the user API")
@RequestMapping(value = "/v2")
public interface UserApi {

@ApiOperation(value = "Create user", nickname = "createUser", notes = "This can only be done by the logged in user.", tags={ "user", })
Expand Down
Expand Up @@ -23,6 +23,7 @@
import java.util.List;

@Api(value = "another-fake", description = "the another-fake API")
@RequestMapping(value = "/v2")
public interface AnotherFakeApi {

@ApiOperation(value = "To test special tags", nickname = "testSpecialTags", notes = "To test special tags", response = Client.class, tags={ "$another-fake?", })
Expand Down
Expand Up @@ -28,6 +28,7 @@
import java.util.List;

@Api(value = "fake", description = "the fake API")
@RequestMapping(value = "/v2")
public interface FakeApi {

@ApiOperation(value = "", nickname = "fakeOuterBooleanSerialize", notes = "Test serialization of outer boolean types", response = Boolean.class, tags={ "fake", })
Expand Down
Expand Up @@ -23,6 +23,7 @@
import java.util.List;

@Api(value = "fake_classname_test", description = "the fake_classname_test API")
@RequestMapping(value = "/v2")
public interface FakeClassnameTestApi {

@ApiOperation(value = "To test class name in snake case", nickname = "testClassname", notes = "To test class name in snake case", response = Client.class, authorizations = {
Expand Down
Expand Up @@ -25,6 +25,7 @@
import java.util.List;

@Api(value = "pet", description = "the pet API")
@RequestMapping(value = "/v2")
public interface PetApi {

@ApiOperation(value = "Add a new pet to the store", nickname = "addPet", notes = "", authorizations = {
Expand Down
Expand Up @@ -24,6 +24,7 @@
import java.util.List;

@Api(value = "store", description = "the store API")
@RequestMapping(value = "/v2")
public interface StoreApi {

@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", })
Expand Down
Expand Up @@ -24,6 +24,7 @@
import java.util.List;

@Api(value = "user", description = "the user API")
@RequestMapping(value = "/v2")
public interface UserApi {

@ApiOperation(value = "Create user", nickname = "createUser", notes = "This can only be done by the logged in user.", tags={ "user", })
Expand Down
Expand Up @@ -23,6 +23,7 @@
import java.util.List;

@Api(value = "another-fake", description = "the another-fake API")
@RequestMapping(value = "/v2")
public interface AnotherFakeApi {

AnotherFakeApiDelegate getDelegate();
Expand Down
Expand Up @@ -28,6 +28,7 @@
import java.util.List;

@Api(value = "fake", description = "the fake API")
@RequestMapping(value = "/v2")
public interface FakeApi {

FakeApiDelegate getDelegate();
Expand Down
Expand Up @@ -23,6 +23,7 @@
import java.util.List;

@Api(value = "fake_classname_test", description = "the fake_classname_test API")
@RequestMapping(value = "/v2")
public interface FakeClassnameTestApi {

FakeClassnameTestApiDelegate getDelegate();
Expand Down
Expand Up @@ -25,6 +25,7 @@
import java.util.List;

@Api(value = "pet", description = "the pet API")
@RequestMapping(value = "/v2")
public interface PetApi {

PetApiDelegate getDelegate();
Expand Down
Expand Up @@ -24,6 +24,7 @@
import java.util.List;

@Api(value = "store", description = "the store API")
@RequestMapping(value = "/v2")
public interface StoreApi {

StoreApiDelegate getDelegate();
Expand Down
Expand Up @@ -24,6 +24,7 @@
import java.util.List;

@Api(value = "user", description = "the user API")
@RequestMapping(value = "/v2")
public interface UserApi {

UserApiDelegate getDelegate();
Expand Down
Expand Up @@ -23,6 +23,7 @@
import java.util.List;

@Api(value = "another-fake", description = "the another-fake API")
@RequestMapping(value = "/v2")
public interface AnotherFakeApi {

@ApiOperation(value = "To test special tags", nickname = "testSpecialTags", notes = "To test special tags", response = Client.class, tags={ "$another-fake?", })
Expand Down
Expand Up @@ -28,6 +28,7 @@
import java.util.List;

@Api(value = "fake", description = "the fake API")
@RequestMapping(value = "/v2")
public interface FakeApi {

@ApiOperation(value = "", nickname = "fakeOuterBooleanSerialize", notes = "Test serialization of outer boolean types", response = Boolean.class, tags={ "fake", })
Expand Down
Expand Up @@ -23,6 +23,7 @@
import java.util.List;

@Api(value = "fake_classname_test", description = "the fake_classname_test API")
@RequestMapping(value = "/v2")
public interface FakeClassnameTestApi {

@ApiOperation(value = "To test class name in snake case", nickname = "testClassname", notes = "To test class name in snake case", response = Client.class, authorizations = {
Expand Down

0 comments on commit f1569a0

Please sign in to comment.