Skip to content

Commit ec6a925

Browse files
committed
put spring-mvc and spring-boot under the same language gen
1 parent 79dc342 commit ec6a925

File tree

70 files changed

+1929
-784
lines changed

Some content is hidden

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

70 files changed

+1929
-784
lines changed

bin/spring-mvc-petstore-j8-async-server.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ fi
2626

2727
# if you've executed sbt assembly previously it will use that instead.
2828
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
29-
ags="$@ generate -t modules/swagger-codegen/src/main/resources/JavaSpringMVC -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l spring-mvc -o samples/server/petstore/spring-mvc-j8-async -c bin/spring-mvc-petstore-j8-async.json"
29+
ags="$@ generate -t modules/swagger-codegen/src/main/resources/JavaSpringMVC -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l spring --library spring-mvc -o samples/server/petstore/spring-mvc-j8-async -c bin/spring-mvc-petstore-j8-async.json -DhideGenerationTimestamp=true,java8=true,async=true"
3030

3131
java $JAVA_OPTS -jar $executable $ags

bin/spring-mvc-petstore-server.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ fi
2626

2727
# if you've executed sbt assembly previously it will use that instead.
2828
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
29-
ags="$@ generate -t modules/swagger-codegen/src/main/resources/JavaSpringMVC -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l spring-mvc -o samples/server/petstore/spring-mvc"
29+
ags="$@ generate -t modules/swagger-codegen/src/main/resources/JavaSpringBoot -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l spring --library spring-mvc -o samples/server/petstore/spring-mvc -DhideGenerationTimestamp=true"
3030

3131
java $JAVA_OPTS -jar $executable $ags

bin/springboot-petstore-server.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fi
2626

2727
# if you've executed sbt assembly previously it will use that instead.
2828
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
29-
ags="$@ generate -t modules/swagger-codegen/src/main/resources/JavaSpringBoot -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l springboot -o samples/server/petstore/springboot -DhideGenerationTimestamp=true"
29+
ags="$@ generate -t modules/swagger-codegen/src/main/resources/JavaSpringBoot -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l spring --library=spring-boot -o samples/server/petstore/springboot -DhideGenerationTimestamp=true"
3030

3131
echo "Removing files and folders under samples/server/petstore/springboot/src/main"
3232
rm -rf samples/server/petstore/springboot/src/main

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaClientCodegen.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ public JavaClientCodegen() {
4040
supportedLibraries.put(RETROFIT_2, "HTTP client: OkHttp 3.2.0. JSON processing: Gson 2.6.1 (Retrofit 2.0.2). Enable the RxJava adapter using '-DuseRxJava=true'. (RxJava 1.1.3)");
4141

4242
CliOption library = new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use");
43-
library.setDefault(DEFAULT_LIBRARY);
4443
library.setEnum(supportedLibraries);
4544
library.setDefault(DEFAULT_LIBRARY);
4645
cliOptions.add(library);

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/SpringBootServerCodegen.java

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ public class SpringBootServerCodegen extends AbstractJavaCodegen {
2626

2727
public SpringBootServerCodegen() {
2828
super();
29-
outputFolder = "generated-code/javaSpringBoot";
29+
outputFolder = "generated-code/javaSpring";
3030
apiTestTemplateFiles.clear(); // TODO: add test template
3131
embeddedTemplateDir = templateDir = "JavaSpringBoot";
3232
apiPackage = "io.swagger.api";
3333
modelPackage = "io.swagger.model";
3434
invokerPackage = "io.swagger.api";
35-
artifactId = "swagger-springboot-server";
35+
artifactId = "swagger-spring-server";
3636

3737
additionalProperties.put("title", title);
3838
additionalProperties.put(CONFIG_PACKAGE, configPackage);
@@ -45,17 +45,14 @@ public SpringBootServerCodegen() {
4545
cliOptions.add(CliOption.newBoolean(JAVA_8, "use java8 default interface"));
4646
cliOptions.add(CliOption.newBoolean(ASYNC, "use async Callable controllers"));
4747

48-
supportedLibraries.put(DEFAULT_LIBRARY, "Default Spring Boot server stub.");
49-
supportedLibraries.put("j8-async", "Use async servlet feature and Java 8's default interface. Generating interface with service " +
50-
"declaration is useful when using Maven plugin. Just provide a implementation with @Controller to instantiate service." +
51-
"(DEPRECATED: use -Djava8=true,async=true instead)");
48+
supportedLibraries.put(DEFAULT_LIBRARY, "Spring-boot Server application using the SpringFox integration.");
49+
supportedLibraries.put("spring-mvc", "Spring-MVC Server application using the SpringFox integration.");
5250

5351
CliOption library = new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use");
5452
library.setDefault(DEFAULT_LIBRARY);
5553
library.setEnum(supportedLibraries);
5654
library.setDefault(DEFAULT_LIBRARY);
5755
cliOptions.add(library);
58-
5956
}
6057

6158
@Override
@@ -65,7 +62,7 @@ public CodegenType getTag() {
6562

6663
@Override
6764
public String getName() {
68-
return "springboot";
65+
return "spring";
6966
}
7067

7168
@Override
@@ -122,17 +119,24 @@ public void processOpts() {
122119
(sourceFolder + File.separator + apiPackage).replace(".", java.io.File.separator), "NotFoundException.java"));
123120
supportingFiles.add(new SupportingFile("swaggerDocumentationConfig.mustache",
124121
(sourceFolder + File.separator + configPackage).replace(".", java.io.File.separator), "SwaggerDocumentationConfig.java"));
125-
supportingFiles.add(new SupportingFile("homeController.mustache",
126-
(sourceFolder + File.separator + configPackage).replace(".", java.io.File.separator), "HomeController.java"));
127-
supportingFiles.add(new SupportingFile("swagger2SpringBoot.mustache",
128-
(sourceFolder + File.separator + basePackage).replace(".", java.io.File.separator), "Swagger2SpringBoot.java"));
129-
supportingFiles.add(new SupportingFile("application.properties",
130-
("src.main.resources").replace(".", java.io.File.separator), "application.properties"));
131-
}
132-
133-
if ("j8-async".equals(getLibrary())) {
134-
setJava8(true);
135-
setAsync(true);
122+
if (library.equals(DEFAULT_LIBRARY)) {
123+
supportingFiles.add(new SupportingFile("homeController.mustache",
124+
(sourceFolder + File.separator + configPackage).replace(".", java.io.File.separator), "HomeController.java"));
125+
supportingFiles.add(new SupportingFile("swagger2SpringBoot.mustache",
126+
(sourceFolder + File.separator + basePackage).replace(".", java.io.File.separator), "Swagger2SpringBoot.java"));
127+
supportingFiles.add(new SupportingFile("application.properties",
128+
("src.main.resources").replace(".", java.io.File.separator), "application.properties"));
129+
}
130+
if (library.equals("mvc")) {
131+
supportingFiles.add(new SupportingFile("webApplication.mustache",
132+
(sourceFolder + File.separator + configPackage).replace(".", java.io.File.separator), "WebApplication.java"));
133+
supportingFiles.add(new SupportingFile("webMvcConfiguration.mustache",
134+
(sourceFolder + File.separator + configPackage).replace(".", java.io.File.separator), "WebMvcConfiguration.java"));
135+
supportingFiles.add(new SupportingFile("swaggerUiConfiguration.mustache",
136+
(sourceFolder + File.separator + configPackage).replace(".", java.io.File.separator), "SwaggerUiConfiguration.java"));
137+
supportingFiles.add(new SupportingFile("application.properties",
138+
("src.main.resources").replace(".", java.io.File.separator), "swagger.properties"));
139+
}
136140
}
137141

138142
if (this.java8) {

modules/swagger-codegen/src/main/resources/JavaSpringBoot/apiResponseMessage.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package {{apiPackage}};
22

33
import javax.xml.bind.annotation.XmlTransient;
44

5-
@javax.xml.bind.annotation.XmlRootElement
65
{{>generatedAnnotation}}
6+
@javax.xml.bind.annotation.XmlRootElement
77
public class ApiResponseMessage {
88
public static final int ERROR = 1;
99
public static final int WARNING = 2;
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
{{^hideGenerationTimestamp}}@javax.annotation.Generated(value = "{{generatorClass}}", date = "{{generatedDate}}"){{/hideGenerationTimestamp}}
1+
{{^hideGenerationTimestamp}}
2+
@javax.annotation.Generated(value = "{{generatorClass}}", date = "{{generatedDate}}")
3+
{{/hideGenerationTimestamp}}
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)