From df771b5a4d21a53a2a11d8c9cb26c7222b56eb66 Mon Sep 17 00:00:00 2001 From: Tony Tam Date: Wed, 1 Apr 2015 07:41:45 -0700 Subject: [PATCH] updated springfox templates --- .../swagger/codegen/DefaultGenerator.java | 1 - .../languages/SpringfoxServerCodegen.java | 15 +++++++------ .../JavaSpringfox/webApplication.mustache | 21 +++++++++++++++++++ .../webMvcConfiguration.mustache | 11 ++++++++++ 4 files changed, 41 insertions(+), 7 deletions(-) create mode 100644 modules/swagger-codegen/src/main/resources/JavaSpringfox/webApplication.mustache create mode 100644 modules/swagger-codegen/src/main/resources/JavaSpringfox/webMvcConfiguration.mustache diff --git a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/DefaultGenerator.java b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/DefaultGenerator.java index 11a6a2841fb..1937b03ca53 100644 --- a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/DefaultGenerator.java +++ b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/DefaultGenerator.java @@ -253,7 +253,6 @@ public class DefaultGenerator extends AbstractGenerator implements Generator { files.add(new File(outputFilename)); } else { InputStream in = this.getClass().getClassLoader().getResourceAsStream(config.templateDir() + File.separator + support.templateFile); - //new FileInputStream(config.templateDir() + File.separator + support.templateFile); File outputFile = new File(outputFilename); OutputStream out = new FileOutputStream(outputFile); IOUtils.copy(in,out); diff --git a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/SpringfoxServerCodegen.java b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/SpringfoxServerCodegen.java index 7382d5f0bab..3656eee2734 100644 --- a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/SpringfoxServerCodegen.java +++ b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/SpringfoxServerCodegen.java @@ -53,18 +53,21 @@ public class SpringfoxServerCodegen extends JavaClientCodegen implements Codegen supportingFiles.clear(); supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml")); supportingFiles.add(new SupportingFile("README.mustache", "", "README.md")); - supportingFiles.add(new SupportingFile("ApiException.mustache", + supportingFiles.add(new SupportingFile("apiException.mustache", (sourceFolder + File.separator + apiPackage).replace(".", java.io.File.separator), "ApiException.java")); - supportingFiles.add(new SupportingFile("ApiOriginFilter.mustache", + supportingFiles.add(new SupportingFile("apiOriginFilter.mustache", (sourceFolder + File.separator + apiPackage).replace(".", java.io.File.separator), "ApiOriginFilter.java")); - supportingFiles.add(new SupportingFile("ApiResponseMessage.mustache", + supportingFiles.add(new SupportingFile("apiResponseMessage.mustache", (sourceFolder + File.separator + apiPackage).replace(".", java.io.File.separator), "ApiResponseMessage.java")); - supportingFiles.add(new SupportingFile("NotFoundException.mustache", + supportingFiles.add(new SupportingFile("notFoundException.mustache", (sourceFolder + File.separator + apiPackage).replace(".", java.io.File.separator), "NotFoundException.java")); - - supportingFiles.add(new SupportingFile("SwaggerConfig.mustache", + supportingFiles.add(new SupportingFile("swaggerConfig.mustache", (sourceFolder + File.separator + configPackage).replace(".", java.io.File.separator), "SwaggerConfig.java")); + supportingFiles.add(new SupportingFile("webApplication.mustache", + (sourceFolder + File.separator + configPackage).replace(".", java.io.File.separator), "WebApplication.java")); + supportingFiles.add(new SupportingFile("webMvcConfiguration.mustache", + (sourceFolder + File.separator + configPackage).replace(".", java.io.File.separator), "WebMvcConfiguration.java")); languageSpecificPrimitives = new HashSet( Arrays.asList( diff --git a/modules/swagger-codegen/src/main/resources/JavaSpringfox/webApplication.mustache b/modules/swagger-codegen/src/main/resources/JavaSpringfox/webApplication.mustache new file mode 100644 index 00000000000..6910ad11b76 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaSpringfox/webApplication.mustache @@ -0,0 +1,21 @@ +package {{configPackage}}; + +import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; + +public class WebApplication extends AbstractAnnotationConfigDispatcherServletInitializer { + + @Override + protected Class[] getRootConfigClasses() { + return new Class[] { SwaggerConfig.class }; + } + + @Override + protected Class[] getServletConfigClasses() { + return new Class[] { WebMvcConfiguration.class }; + } + + @Override + protected String[] getServletMappings() { + return new String[] { "/" }; + } +} diff --git a/modules/swagger-codegen/src/main/resources/JavaSpringfox/webMvcConfiguration.mustache b/modules/swagger-codegen/src/main/resources/JavaSpringfox/webMvcConfiguration.mustache new file mode 100644 index 00000000000..03904e51e79 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaSpringfox/webMvcConfiguration.mustache @@ -0,0 +1,11 @@ +package {{configPackage}}; + +import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; + +public class WebMvcConfiguration extends WebMvcConfigurationSupport { + @Override + public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) { + configurer.enable(); + } +}