9
9
import java .io .File ;
10
10
import java .util .*;
11
11
12
- public class SpringBootServerCodegen extends AbstractJavaCodegen {
12
+ public class SpringCodegen extends AbstractJavaCodegen {
13
+ public static final String DEFAULT_LIBRARY = "spring-boot" ;
13
14
public static final String CONFIG_PACKAGE = "configPackage" ;
14
15
public static final String BASE_PACKAGE = "basePackage" ;
15
16
public static final String INTERFACE_ONLY = "interfaceOnly" ;
@@ -24,15 +25,15 @@ public class SpringBootServerCodegen extends AbstractJavaCodegen {
24
25
protected boolean java8 = false ;
25
26
protected boolean async = false ;
26
27
27
- public SpringBootServerCodegen () {
28
+ public SpringCodegen () {
28
29
super ();
29
- outputFolder = "generated-code/javaSpringBoot " ;
30
+ outputFolder = "generated-code/javaSpring " ;
30
31
apiTestTemplateFiles .clear (); // TODO: add test template
31
- embeddedTemplateDir = templateDir = "JavaSpringBoot " ;
32
+ embeddedTemplateDir = templateDir = "JavaSpring " ;
32
33
apiPackage = "io.swagger.api" ;
33
34
modelPackage = "io.swagger.model" ;
34
35
invokerPackage = "io.swagger.api" ;
35
- artifactId = "swagger-springboot -server" ;
36
+ artifactId = "swagger-spring -server" ;
36
37
37
38
additionalProperties .put ("title" , title );
38
39
additionalProperties .put (CONFIG_PACKAGE , configPackage );
@@ -45,17 +46,15 @@ public SpringBootServerCodegen() {
45
46
cliOptions .add (CliOption .newBoolean (JAVA_8 , "use java8 default interface" ));
46
47
cliOptions .add (CliOption .newBoolean (ASYNC , "use async Callable controllers" ));
47
48
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)" );
49
+ supportedLibraries .put (DEFAULT_LIBRARY , "Spring-boot Server application using the SpringFox integration." );
50
+ supportedLibraries .put ("spring-mvc" , "Spring-MVC Server application using the SpringFox integration." );
51
+ setLibrary (DEFAULT_LIBRARY );
52
52
53
53
CliOption library = new CliOption (CodegenConstants .LIBRARY , "library template (sub-template) to use" );
54
54
library .setDefault (DEFAULT_LIBRARY );
55
55
library .setEnum (supportedLibraries );
56
56
library .setDefault (DEFAULT_LIBRARY );
57
57
cliOptions .add (library );
58
-
59
58
}
60
59
61
60
@ Override
@@ -65,7 +64,7 @@ public CodegenType getTag() {
65
64
66
65
@ Override
67
66
public String getName () {
68
- return "springboot " ;
67
+ return "spring " ;
69
68
}
70
69
71
70
@ Override
@@ -122,17 +121,24 @@ public void processOpts() {
122
121
(sourceFolder + File .separator + apiPackage ).replace ("." , java .io .File .separator ), "NotFoundException.java" ));
123
122
supportingFiles .add (new SupportingFile ("swaggerDocumentationConfig.mustache" ,
124
123
(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 );
124
+ if (library .equals (DEFAULT_LIBRARY )) {
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
+ if (library .equals ("spring-mvc" )) {
133
+ supportingFiles .add (new SupportingFile ("webApplication.mustache" ,
134
+ (sourceFolder + File .separator + configPackage ).replace ("." , java .io .File .separator ), "WebApplication.java" ));
135
+ supportingFiles .add (new SupportingFile ("webMvcConfiguration.mustache" ,
136
+ (sourceFolder + File .separator + configPackage ).replace ("." , java .io .File .separator ), "WebMvcConfiguration.java" ));
137
+ supportingFiles .add (new SupportingFile ("swaggerUiConfiguration.mustache" ,
138
+ (sourceFolder + File .separator + configPackage ).replace ("." , java .io .File .separator ), "SwaggerUiConfiguration.java" ));
139
+ supportingFiles .add (new SupportingFile ("application.properties" ,
140
+ ("src.main.resources" ).replace ("." , java .io .File .separator ), "swagger.properties" ));
141
+ }
136
142
}
137
143
138
144
if (this .java8 ) {
@@ -285,34 +291,15 @@ public void setSingleContentTypes(boolean singleContentTypes) {
285
291
public void setJava8 (boolean java8 ) { this .java8 = java8 ; }
286
292
287
293
public void setAsync (boolean async ) { this .async = async ; }
288
-
289
- @ Override
290
- public Map <String , Object > postProcessModels (Map <String , Object > objs ) {
291
- // remove the import of "Object" to avoid compilation error
292
- List <Map <String , String >> imports = (List <Map <String , String >>) objs .get ("imports" );
293
- Iterator <Map <String , String >> iterator = imports .iterator ();
294
- while (iterator .hasNext ()) {
295
- String _import = iterator .next ().get ("import" );
296
- if (_import .endsWith (".Object" )) iterator .remove ();
297
- }
298
- List <Object > models = (List <Object >) objs .get ("models" );
299
- for (Object _mo : models ) {
300
- Map <String , Object > mo = (Map <String , Object >) _mo ;
301
- CodegenModel cm = (CodegenModel ) mo .get ("model" );
302
- for (CodegenProperty var : cm .vars ) {
303
- // handle default value for enum, e.g. available => StatusEnum.available
304
- if (var .isEnum && var .defaultValue != null && !"null" .equals (var .defaultValue )) {
305
- var .defaultValue = var .datatypeWithEnum + "." + var .defaultValue ;
306
- }
307
- }
308
- }
309
- return objs ;
310
- }
311
294
312
295
@ Override
313
296
public void postProcessModelProperty (CodegenModel model , CodegenProperty property ) {
314
297
super .postProcessModelProperty (model , property );
315
298
299
+ if ("null" .equals (property .example )) {
300
+ property .example = null ;
301
+ }
302
+
316
303
//Add imports for Jackson
317
304
if (!BooleanUtils .toBoolean (model .isEnum )) {
318
305
model .imports .add ("JsonProperty" );
0 commit comments