Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Spring] Fixes #5244 Include basePath @RequestMapping in Spring API template #8131

Merged
merged 4 commits into from
Dec 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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}} {
}
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 {
}
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 {
}
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 {
}
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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