Skip to content

Commit

Permalink
Fixes swagger-api#5244 Include basePath @RequestMapping in Spring API…
Browse files Browse the repository at this point in the history
… template
  • Loading branch information
Daan Kerkhofs committed May 3, 2018
1 parent 415edb8 commit 2eda801
Show file tree
Hide file tree
Showing 68 changed files with 550 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ private 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 @@ -458,6 +464,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 @@ -695,7 +702,7 @@ private Map<String, Object> buildSupportFileBundle(List<Object> allOperations, L
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 @@ -4,7 +4,7 @@ import org.springframework.cloud.netflix.feign.FeignClient;
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 @@ -35,6 +35,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 @@ -53,6 +53,42 @@ public static EnumStringEnum fromValue(String text) {
@JsonProperty("enum_string")
private EnumStringEnum enumString = null;

/**
* Gets or Sets enumStringRequired
*/
public enum EnumStringRequiredEnum {
UPPER("UPPER"),

LOWER("lower"),

EMPTY("");

private String value;

EnumStringRequiredEnum(String value) {
this.value = value;
}

@Override
@JsonValue
public String toString() {
return String.valueOf(value);
}

@JsonCreator
public static EnumStringRequiredEnum fromValue(String text) {
for (EnumStringRequiredEnum b : EnumStringRequiredEnum.values()) {
if (String.valueOf(b.value).equals(text)) {
return b;
}
}
return null;
}
}

@JsonProperty("enum_string_required")
private EnumStringRequiredEnum enumStringRequired = null;

/**
* Gets or Sets enumInteger
*/
Expand Down Expand Up @@ -144,6 +180,27 @@ public void setEnumString(EnumStringEnum enumString) {
this.enumString = enumString;
}

public EnumTest enumStringRequired(EnumStringRequiredEnum enumStringRequired) {
this.enumStringRequired = enumStringRequired;
return this;
}

/**
* Get enumStringRequired
* @return enumStringRequired
**/
@ApiModelProperty(required = true, value = "")
@NotNull


public EnumStringRequiredEnum getEnumStringRequired() {
return enumStringRequired;
}

public void setEnumStringRequired(EnumStringRequiredEnum enumStringRequired) {
this.enumStringRequired = enumStringRequired;
}

public EnumTest enumInteger(EnumIntegerEnum enumInteger) {
this.enumInteger = enumInteger;
return this;
Expand Down Expand Up @@ -216,14 +273,15 @@ public boolean equals(java.lang.Object o) {
}
EnumTest enumTest = (EnumTest) o;
return Objects.equals(this.enumString, enumTest.enumString) &&
Objects.equals(this.enumStringRequired, enumTest.enumStringRequired) &&
Objects.equals(this.enumInteger, enumTest.enumInteger) &&
Objects.equals(this.enumNumber, enumTest.enumNumber) &&
Objects.equals(this.outerEnum, enumTest.outerEnum);
}

@Override
public int hashCode() {
return Objects.hash(enumString, enumInteger, enumNumber, outerEnum);
return Objects.hash(enumString, enumStringRequired, enumInteger, enumNumber, outerEnum);
}

@Override
Expand All @@ -232,6 +290,7 @@ public String toString() {
sb.append("class EnumTest {\n");

sb.append(" enumString: ").append(toIndentedString(enumString)).append("\n");
sb.append(" enumStringRequired: ").append(toIndentedString(enumStringRequired)).append("\n");
sb.append(" enumInteger: ").append(toIndentedString(enumInteger)).append("\n");
sb.append(" enumNumber: ").append(toIndentedString(enumNumber)).append("\n");
sb.append(" outerEnum: ").append(toIndentedString(outerEnum)).append("\n");
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 @@ -27,6 +27,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
Loading

0 comments on commit 2eda801

Please sign in to comment.