Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bin/spring-all-pestore.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/sh

./bin/spring-cloud-feign-petstore.sh
./bin/spring-delegate.sh
./bin/spring-delegate-j8.sh
./bin/spring-stubs.sh
./bin/spring-mvc-petstore-j8-async-server.sh
./bin/springboot-petstore-server.sh
Expand Down
34 changes: 34 additions & 0 deletions bin/spring-delegate-j8.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/sh

SCRIPT="$0"

while [ -h "$SCRIPT" ] ; do
ls=`ls -ld "$SCRIPT"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
SCRIPT="$link"
else
SCRIPT=`dirname "$SCRIPT"`/"$link"
fi
done

if [ ! -d "${APP_DIR}" ]; then
APP_DIR=`dirname "$SCRIPT"`/..
APP_DIR=`cd "${APP_DIR}"; pwd`
fi

executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar"

if [ ! -f "$executable" ]
then
mvn clean package
fi

# if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
ags="$@ generate -t modules/swagger-codegen/src/main/resources/JavaSpring -i modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -l spring -o samples/server/petstore/springboot-delegate-j8 -DdelegatePattern=true,hideGenerationTimestamp=true,java8=true"

echo "Removing files and folders under samples/server/petstore/springboot-delegate-j8/src/main"
rm -rf samples/server/petstore/springboot/src/main
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong. Should be the same as the line above.

find samples/server/petstore/springboot -maxdepth 1 -type f ! -name "README.md" -exec rm {} +
java $JAVA_OPTS -jar $executable $ags
34 changes: 34 additions & 0 deletions bin/spring-delegate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/sh

SCRIPT="$0"

while [ -h "$SCRIPT" ] ; do
ls=`ls -ld "$SCRIPT"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
SCRIPT="$link"
else
SCRIPT=`dirname "$SCRIPT"`/"$link"
fi
done

if [ ! -d "${APP_DIR}" ]; then
APP_DIR=`dirname "$SCRIPT"`/..
APP_DIR=`cd "${APP_DIR}"; pwd`
fi

executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar"

if [ ! -f "$executable" ]
then
mvn clean package
fi

# if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
ags="$@ generate -t modules/swagger-codegen/src/main/resources/JavaSpring -i modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -l spring -o samples/server/petstore/springboot-delegate -DdelegatePattern=true,hideGenerationTimestamp=true"

echo "Removing files and folders under samples/server/petstore/springboot-delegate/src/main"
rm -rf samples/server/petstore/springboot/src/main
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong. Should be the same as the line above.

find samples/server/petstore/springboot -maxdepth 1 -type f ! -name "README.md" -exec rm {} +
java $JAVA_OPTS -jar $executable $ags
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class SpringCodegen extends AbstractJavaCodegen {
public static final String CONFIG_PACKAGE = "configPackage";
public static final String BASE_PACKAGE = "basePackage";
public static final String INTERFACE_ONLY = "interfaceOnly";
public static final String DELEGATE_PATTERN = "delegatePattern";
public static final String SINGLE_CONTENT_TYPES = "singleContentTypes";
public static final String JAVA_8 = "java8";
public static final String ASYNC = "async";
Expand All @@ -26,6 +27,7 @@ public class SpringCodegen extends AbstractJavaCodegen {
protected String configPackage = "io.swagger.configuration";
protected String basePackage = "io.swagger";
protected boolean interfaceOnly = false;
protected boolean delegatePattern = false;
protected boolean singleContentTypes = false;
protected boolean java8 = false;
protected boolean async = false;
Expand All @@ -52,6 +54,7 @@ public SpringCodegen() {
cliOptions.add(new CliOption(CONFIG_PACKAGE, "configuration package for generated code"));
cliOptions.add(new CliOption(BASE_PACKAGE, "base package for generated code"));
cliOptions.add(CliOption.newBoolean(INTERFACE_ONLY, "Whether to generate only API interface stubs without the server files."));
cliOptions.add(CliOption.newBoolean(DELEGATE_PATTERN, "Whether to generate the server files using the delegate pattern"));
cliOptions.add(CliOption.newBoolean(SINGLE_CONTENT_TYPES, "Whether to select only one produces/consumes content-type by operation."));
cliOptions.add(CliOption.newBoolean(JAVA_8, "use java8 default interface"));
cliOptions.add(CliOption.newBoolean(ASYNC, "use async Callable controllers"));
Expand Down Expand Up @@ -111,6 +114,10 @@ public void processOpts() {
this.setInterfaceOnly(Boolean.valueOf(additionalProperties.get(INTERFACE_ONLY).toString()));
}

if (additionalProperties.containsKey(DELEGATE_PATTERN)) {
this.setDelegatePattern(Boolean.valueOf(additionalProperties.get(DELEGATE_PATTERN).toString()));
}

if (additionalProperties.containsKey(SINGLE_CONTENT_TYPES)) {
this.setSingleContentTypes(Boolean.valueOf(additionalProperties.get(SINGLE_CONTENT_TYPES).toString()));
}
Expand All @@ -134,6 +141,11 @@ public void processOpts() {
supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml"));
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));

if (this.interfaceOnly && this.delegatePattern) {
throw new IllegalArgumentException(
String.format("Can not generate code with `%s` and `%s` both true.", DELEGATE_PATTERN, INTERFACE_ONLY));
}

if (!this.interfaceOnly) {
if (library.equals(DEFAULT_LIBRARY)) {
supportingFiles.add(new SupportingFile("homeController.mustache",
Expand Down Expand Up @@ -184,6 +196,16 @@ public void processOpts() {
}
}

if (!this.delegatePattern && this.java8) {
additionalProperties.put("jdk8-no-delegate", true);
}


if (this.delegatePattern) {
additionalProperties.put("isDelegate", "true");
apiTemplateFiles.put("apiDelegate.mustache", "Delegate.java");
}

if (this.java8) {
additionalProperties.put("javaVersion", "1.8");
additionalProperties.put("jdk8", "true");
Expand Down Expand Up @@ -397,6 +419,8 @@ public void setBasePackage(String configPackage) {

public void setInterfaceOnly(boolean interfaceOnly) { this.interfaceOnly = interfaceOnly; }

public void setDelegatePattern(boolean delegatePattern) { this.delegatePattern = delegatePattern; }

public void setSingleContentTypes(boolean singleContentTypes) {
this.singleContentTypes = singleContentTypes;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package {{package}};

{{^jdk8}}
{{^jdk8-no-delegate}}
{{#imports}}import {{import}};
{{/imports}}

import io.swagger.annotations.*;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
{{/jdk8}}
{{/jdk8-no-delegate}}
import org.springframework.stereotype.Controller;
{{^jdk8}}
{{^jdk8-no-delegate}}
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
Expand All @@ -21,24 +21,33 @@ import org.springframework.web.multipart.MultipartFile;
import java.util.List;
{{#async}}
import java.util.concurrent.Callable;
{{/async}}{{/jdk8}}
{{/async}}{{/jdk8-no-delegate}}

{{>generatedAnnotation}}
@Controller
{{#operations}}
public class {{classname}}Controller implements {{classname}} {
{{^jdk8}}{{#operation}}
{{#isDelegate}}
private final {{classname}}Delegate delegate;

@org.springframework.beans.factory.annotation.Autowired
{{classname}}Controller({{classname}}Delegate delegate) {
this.delegate = delegate;
}{{/isDelegate}}

{{^jdk8-no-delegate}}{{#operation}}
public {{#async}}Callable<{{/async}}ResponseEntity<{{>returnTypes}}>{{#async}}>{{/async}} {{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}},
{{/hasMore}}{{/allParams}}) {
// do some magic!{{^async}}
// do some magic!{{^isDelegate}}{{^async}}
return new ResponseEntity<{{>returnTypes}}>(HttpStatus.OK);{{/async}}{{#async}}
return new Callable<ResponseEntity<{{>returnTypes}}>>() {
@Override
public ResponseEntity<{{>returnTypes}}> call() throws Exception {
return new ResponseEntity<{{>returnTypes}}>(HttpStatus.OK);
}
};{{/async}}
};{{/async}}{{/isDelegate}}{{#isDelegate}}
return delegate.{{operationId}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});{{/isDelegate}}
}
{{/operation}}{{/jdk8}}
{{/operation}}{{/jdk8-no-delegate}}
}
{{/operations}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package {{package}};

{{#imports}}import {{import}};
{{/imports}}

import io.swagger.annotations.*;{{#jdk8}}
import org.springframework.http.HttpStatus;{{/jdk8}}
import org.springframework.http.ResponseEntity;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
{{#async}}
import java.util.concurrent.{{^jdk8}}Callable{{/jdk8}}{{#jdk8}}CompletableFuture{{/jdk8}};
{{/async}}

{{#operations}}
/**
* A delegate to be called by the {@link {{classname}}Controller}}.
* Should be implemented as a controller but without the {@link org.springframework.stereotype.Controller} annotation.
* Instead, use spring to autowire this class into the {@link {{classname}}Controller}.
*/
{{>generatedAnnotation}}
public interface {{classname}}Delegate {

{{#operation}}
/**
* @see {{classname}}#{{operationId}}
*/
{{#jdk8}}default {{/jdk8}}{{#responseWrapper}}{{.}}<{{/responseWrapper}}ResponseEntity<{{>returnTypes}}>{{#responseWrapper}}>{{/responseWrapper}} {{operationId}}({{#allParams}}{{^isFile}}{{{dataType}}}{{/isFile}}{{#isFile}}MultipartFile{{/isFile}} {{paramName}}{{#hasMore}},
{{/hasMore}}{{/allParams}}){{^jdk8}};{{/jdk8}}{{#jdk8}} {
// do some magic!
return {{#async}}CompletableFuture.completedFuture({{/async}}new ResponseEntity<{{>returnTypes}}>(HttpStatus.OK){{#async}}){{/async}};
}{{/jdk8}}

{{/operation}}
}
{{/operations}}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class SpringOptionsProvider extends JavaOptionsProvider {
public static final String BASE_PACKAGE_VALUE = "basePackage";
public static final String LIBRARY_VALUE = "spring-mvc"; //FIXME hidding value from super class
public static final String INTERFACE_ONLY = "true";
public static final String DELEGATE_PATTERN = "true";
public static final String SINGLE_CONTENT_TYPES = "true";
public static final String JAVA_8 = "true";
public static final String ASYNC = "true";
Expand All @@ -31,6 +32,7 @@ public Map<String, String> createOptions() {
options.put(SpringCodegen.BASE_PACKAGE, BASE_PACKAGE_VALUE);
options.put(CodegenConstants.LIBRARY, LIBRARY_VALUE);
options.put(SpringCodegen.INTERFACE_ONLY, INTERFACE_ONLY);
options.put(SpringCodegen.DELEGATE_PATTERN, DELEGATE_PATTERN);
options.put(SpringCodegen.SINGLE_CONTENT_TYPES, SINGLE_CONTENT_TYPES);
options.put(SpringCodegen.JAVA_8, JAVA_8);
options.put(SpringCodegen.ASYNC, ASYNC);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ protected void setExpectations() {
times = 1;
clientCodegen.setInterfaceOnly(Boolean.valueOf(SpringOptionsProvider.INTERFACE_ONLY));
times = 1;
clientCodegen.setDelegatePattern(Boolean.valueOf(SpringOptionsProvider.DELEGATE_PATTERN));
times = 1;
clientCodegen.setSingleContentTypes(Boolean.valueOf(SpringOptionsProvider.SINGLE_CONTENT_TYPES));
times = 1;
clientCodegen.setJava8(Boolean.valueOf(SpringOptionsProvider.JAVA_8));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.swagger.api;

import io.swagger.model.Pet;
import io.swagger.model.ModelApiResponse;
import java.io.File;
import io.swagger.model.ModelApiResponse;
import io.swagger.model.Pet;

import io.swagger.annotations.*;
import org.springframework.http.ResponseEntity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.swagger.api;

import io.swagger.model.User;
import java.util.List;
import io.swagger.model.User;

import io.swagger.annotations.*;
import org.springframework.http.ResponseEntity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.swagger.api;

import io.swagger.model.Pet;
import io.swagger.model.ModelApiResponse;
import java.io.File;
import io.swagger.model.ModelApiResponse;
import io.swagger.model.Pet;

import io.swagger.annotations.*;
import org.springframework.http.ResponseEntity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.swagger.api;

import io.swagger.model.User;
import java.util.List;
import io.swagger.model.User;

import io.swagger.annotations.*;
import org.springframework.http.ResponseEntity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package io.swagger.api;

import java.math.BigDecimal;
import io.swagger.model.Client;
import java.time.OffsetDateTime;
import java.time.LocalDate;
import java.math.BigDecimal;
import java.time.OffsetDateTime;

import io.swagger.annotations.*;
import org.springframework.http.HttpStatus;
Expand All @@ -24,7 +24,7 @@
@Api(value = "fake", description = "the fake API")
public interface FakeApi {

@ApiOperation(value = "To test \"client\" model", notes = "", response = Client.class, tags={ "fake", })
@ApiOperation(value = "To test \"client\" model", notes = "To test \"client\" model", response = Client.class, tags={ "fake", })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation", response = Client.class) })
@RequestMapping(value = "/fake",
Expand Down Expand Up @@ -66,7 +66,7 @@ default CompletableFuture<ResponseEntity<Void>> testEndpointParameters(@ApiParam
}


@ApiOperation(value = "To test enum parameters", notes = "", response = Void.class, tags={ "fake", })
@ApiOperation(value = "To test enum parameters", notes = "To test enum parameters", response = Void.class, tags={ "fake", })
@ApiResponses(value = {
@ApiResponse(code = 400, message = "Invalid request", response = Void.class),
@ApiResponse(code = 404, message = "Not found", response = Void.class) })
Expand All @@ -80,7 +80,7 @@ default CompletableFuture<ResponseEntity<Void>> testEnumParameters(@ApiParam(val
@ApiParam(value = "Header parameter enum test (string)" , allowableValues="_ABC, _EFG, _XYZ_", defaultValue="-efg") @RequestHeader(value="enum_header_string", required=false) String enumHeaderString,
@ApiParam(value = "Query parameter enum test (string array)", allowableValues = "GREATER_THAN, DOLLAR") @RequestParam(value = "enumQueryStringArray", required = false) List<String> enumQueryStringArray,
@ApiParam(value = "Query parameter enum test (string)", allowableValues = "_ABC, _EFG, _XYZ_", defaultValue = "-efg") @RequestParam(value = "enumQueryString", required = false, defaultValue="-efg") String enumQueryString,
@ApiParam(value = "Query parameter enum test (double)") @RequestParam(value = "enumQueryInteger", required = false) BigDecimal enumQueryInteger,
@ApiParam(value = "Query parameter enum test (double)") @RequestParam(value = "enumQueryInteger", required = false) Integer enumQueryInteger,
@ApiParam(value = "Query parameter enum test (double)" ) @RequestPart(value="enumQueryDouble", required=false) Double enumQueryDouble) {
// do some magic!
return CompletableFuture.completedFuture(new ResponseEntity<Void>(HttpStatus.OK));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@
@Controller
public class FakeApiController implements FakeApi {



}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.swagger.api;

import io.swagger.model.Pet;
import io.swagger.model.ModelApiResponse;
import java.io.File;
import io.swagger.model.ModelApiResponse;
import io.swagger.model.Pet;

import io.swagger.annotations.*;
import org.springframework.http.HttpStatus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@
@Controller
public class PetApiController implements PetApi {



}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@
@Controller
public class StoreApiController implements StoreApi {



}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.swagger.api;

import io.swagger.model.User;
import java.util.List;
import io.swagger.model.User;

import io.swagger.annotations.*;
import org.springframework.http.HttpStatus;
Expand Down
Loading