Skip to content

Commit f142474

Browse files
committed
updated templates
1 parent 084d448 commit f142474

File tree

8 files changed

+88
-66
lines changed

8 files changed

+88
-66
lines changed

modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/SpringfoxServerCodegen.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
import java.io.File;
1111

1212
public class SpringfoxServerCodegen extends JavaClientCodegen implements CodegenConfig {
13-
protected String invokerPackage = "com.concur.service.api";
14-
protected String groupId = "com.concur.service";
13+
protected String invokerPackage = "io.swagger.api";
14+
protected String groupId = "io.swagger";
1515
protected String artifactId = "swagger-server";
1616
protected String artifactVersion = "1.0.0";
1717
protected String sourceFolder = "src/main/java";
18-
protected String title = "Concur Server";
18+
protected String title = "Petstore Server";
1919

2020
protected String configPackage = "";
2121

@@ -37,9 +37,9 @@ public SpringfoxServerCodegen() {
3737
modelTemplateFiles.put("model.mustache", ".java");
3838
apiTemplateFiles.put("api.mustache", ".java");
3939
templateDir = "JavaSpringfox";
40-
apiPackage = "com.concur.service.api";
41-
modelPackage = "com.concur.service.model";
42-
configPackage = "com.concur.service.configuration";
40+
apiPackage = "io.swagger.api";
41+
modelPackage = "io.swagger.model";
42+
configPackage = "io.swagger.configuration";
4343

4444

4545
additionalProperties.put("invokerPackage", invokerPackage);
Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,37 @@
11
package {{configPackage}};
22

3-
import com.fasterxml.jackson.databind.ObjectMapper;
4-
5-
import org.springframework.beans.factory.annotation.Autowired;
63
import org.springframework.context.annotation.Bean;
4+
import org.springframework.context.annotation.ComponentScan;
75
import org.springframework.context.annotation.Configuration;
8-
9-
import springdox.documentation.swagger2.annotations.EnableSwagger2;
10-
import springdox.documentation.spring.web.plugins.DocumentationConfigurer;
11-
12-
import springdox.documentation.spi.DocumentationType;
13-
import springdox.documentation.service.ApiInfo;
146
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
15-
16-
import java.util.Set;
7+
import springfox.documentation.service.ApiInfo;
8+
import springfox.documentation.spi.DocumentationType;
9+
import springfox.documentation.spring.web.plugins.Docket;
10+
import springfox.documentation.swagger2.annotations.EnableSwagger2;
1711

1812

1913
@Configuration
14+
@ComponentScan(basePackages = "{{apiPackage}}")
2015
@EnableWebMvc
2116
@EnableSwagger2 //Loads the spring beans required by the framework
2217
public class SwaggerConfig {
2318
24-
private DocumentationConfigurer documentationConfigurer;
25-
26-
@Autowired
27-
public void setDocumentationConfigurer(DocumentationConfigurer configurer){
28-
this.documentationConfigurer = documentationConfigurer;
29-
}
30-
3119
@Bean
3220
ApiInfo apiInfo() {
3321
ApiInfo apiInfo = new ApiInfo(
3422
"{{appName}}",
3523
"{{appDescription}}",
36-
"1.0.0",
37-
"My Apps API terms of service",
24+
"{{appVersion}}",
25+
"{{infoUrl}}",
3826
"{{infoEmail}}",
3927
"{{licenseInfo}}",
4028
"{{licenseUrl}}" );
4129
return apiInfo;
4230
}
4331

4432
@Bean
45-
public DocumentationConfigurer customImplementation(){
46-
return new DocumentationConfigurer(DocumentationType.SWAGGER_2)
47-
.groupName("default")
48-
.includePatterns(".*replace {{appName}} with your api classes.*")
49-
.apiInfo(apiInfo());
33+
public Docket customImplementation(){
34+
return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo());
5035
}
5136

52-
@Bean
53-
ObjectMapper objectMapper() { return new ObjectMapper(); }
54-
5537
}

modules/swagger-codegen/src/main/resources/JavaSpringfox/api.mustache

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,50 @@ package {{apiPackage}};
22

33
import {{modelPackage}}.*;
44

5-
import com.wordnik.swagger.annotations.*;
6-
7-
import com.sun.jersey.multipart.FormDataParam;
8-
95
{{#imports}}import {{import}};
106
{{/imports}}
117

12-
import java.util.List;
13-
import {{package}}.NotFoundException;
14-
15-
import javax.ws.rs.core.Response;
16-
import javax.ws.rs.*;
17-
18-
import java.io.InputStream;
8+
import com.wordnik.swagger.annotations.Api;
9+
import com.wordnik.swagger.annotations.ApiOperation;
10+
import com.wordnik.swagger.annotations.ApiParam;
11+
import com.wordnik.swagger.annotations.ApiResponse;
12+
import com.wordnik.swagger.annotations.ApiResponses;
1913

14+
import org.springframework.http.HttpStatus;
15+
import org.springframework.http.ResponseEntity;
2016
import org.springframework.stereotype.Controller;
17+
import org.springframework.web.bind.annotation.PathVariable;
18+
import org.springframework.web.bind.annotation.RequestBody;
19+
import org.springframework.web.bind.annotation.RequestHeader;
2120
import org.springframework.web.bind.annotation.RequestMapping;
2221
import org.springframework.web.bind.annotation.RequestMethod;
2322
import org.springframework.web.bind.annotation.RequestParam;
24-
import org.springframework.web.bind.annotation.ResponseBody;
23+
import org.springframework.web.bind.annotation.RequestPart;
24+
import org.springframework.web.multipart.MultipartFile;
25+
26+
import java.util.List;
2527

2628
import static org.springframework.http.MediaType.*;
2729

2830
@Controller
29-
@RequestMapping("/{{baseName}}",produces = {APPLICATION_JSON_VALUE})
31+
@RequestMapping(value = "/{{baseName}}", produces = {APPLICATION_JSON_VALUE})
3032
@Api(value = "/{{baseName}}", description = "the {{baseName}} API")
3133
{{#operations}}
3234
public class {{classname}} {
3335
{{#operation}}
3436

35-
{{#subresourceOperation}}@RequestMapping(value = "{{path}}", method = RequestMethod.{{httpMethod}} ){{/subresourceOperation}}
36-
{{#hasConsumes}}@Consumes({ {{#consumes}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} }){{/hasConsumes}}
37-
{{#hasProduces}}@Produces({ {{#produces}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }){{/hasProduces}}
3837
@ApiOperation(value = "{{{summary}}}", notes = "{{{notes}}}", response = {{{returnType}}}.class{{#returnContainer}}, responseContainer = "{{{returnContainer}}}"{{/returnContainer}})
3938
@ApiResponses(value = { {{#responses}}
40-
@ApiResponse(code = {{{code}}}, message = "{{{message}}}"){{#hasMore}},
41-
{{/hasMore}}{{/responses}} })
42-
43-
public Response {{nickname}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}},
39+
@ApiResponse(code = {{{code}}}, message = "{{{message}}}"){{#hasMore}},{{/hasMore}}{{/responses}} })
40+
@RequestMapping(value = "{{path}}",
41+
{{#hasProduces}}produces = { {{#produces}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }, {{/hasProduces}}
42+
{{#hasConsumes}}consumes = { {{#consumes}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} },{{/hasConsumes}}
43+
method = RequestMethod.{{httpMethod}})
44+
public ResponseEntity<{{returnType}}> {{nickname}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}},
4445
{{/hasMore}}{{/allParams}})
4546
throws NotFoundException {
4647
// do some magic!
47-
return Response.ok().entity(new ApiResponseMessage(ApiResponseMessage.OK, "magic!")).build();
48+
return new ResponseEntity<{{returnType}}>(HttpStatus.OK);
4849
}
4950

5051
{{/operation}}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
{{#isFormParam}}{{#notFile}}@ApiParam(value = "{{{description}}}"{{#required}}, required=true{{/required}} {{#allowableValues}}, allowableValues="{{{allowableValues}}}"{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}})@FormParam("{{paramName}}") {{{dataType}}} {{paramName}}{{/notFile}}{{#isFile}}@ApiParam(value = "{{{description}}}") @FormDataParam("file") InputStream inputStream,
2-
@ApiParam(value = "file detail") @FormDataParam("file") FormDataContentDisposition fileDetail{{/isFile}}{{/isFormParam}}
1+
{{#isFormParam}}{{#notFile}}
2+
@ApiParam(value = "{{{description}}}"{{#required}}, required=true{{/required}} {{#allowableValues}}, allowableValues="{{{allowableValues}}}"{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}})@RequestPart("{{paramName}}") {{{dataType}}} {{paramName}}{{/notFile}}{{#isFile}}@ApiParam(value = "file detail") @RequestPart("file") MultipartFile fileDetail{{/isFile}}{{/isFormParam}}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{{#isHeaderParam}}@ApiParam(value = "{{{description}}}" {{#required}},required=true{{/required}} {{#allowableValues}}, allowableValues="{{{allowableValues}}}"{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}})@HeaderParam("{{paramName}}") {{{dataType}}} {{paramName}}{{/isHeaderParam}}
1+
{{#isHeaderParam}}@ApiParam(value = "{{{description}}}" {{#required}},required=true{{/required}} {{#allowableValues}}, allowableValues="{{{allowableValues}}}"{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}})@RequestHeader("{{paramName}}") {{{dataType}}} {{paramName}}{{/isHeaderParam}}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{{#isPathParam}}@ApiParam(value = "{{{description}}}"{{#required}},required=true{{/required}}{{#allowableValues}}, allowableValues="{{{allowableValues}}}"{{/allowableValues}} {{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}) @PathParam("{{paramName}}") {{{dataType}}} {{paramName}}{{/isPathParam}}
1+
{{#isPathParam}}@ApiParam(value = "{{{description}}}"{{#required}},required=true{{/required}}{{#allowableValues}}, allowableValues="{{{allowableValues}}}"{{/allowableValues}} {{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}) @PathVariable("{{paramName}}") {{{dataType}}} {{paramName}}{{/isPathParam}}

modules/swagger-codegen/src/main/resources/JavaSpringfox/pom.mustache

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
<webAppConfig>
3434
<contextPath>{{^contextPath}}/{{/contextPath}}{{#contextPath}}{{contextPath}}{{/contextPath}}</contextPath>
3535
</webAppConfig>
36-
<webAppSourceDirectory>target/${project.artifactId}-${project.version}</webAppSourceDirectory>
36+
<webAppSourceDirectory>target/${project.artifactId}-${project-version}</webAppSourceDirectory>
3737
<webDefaultXml>${project.basedir}/conf/jetty/webdefault.xml</webDefaultXml>
3838
<stopPort>8079</stopPort>
3939
<stopKey>stopit</stopKey>
@@ -105,6 +105,45 @@
105105
<version>${jersey-version}</version>
106106
</dependency>
107107

108+
<!--Spring dependencies -->
109+
<dependency>
110+
<groupId>org.springframework</groupId>
111+
<artifactId>spring-core</artifactId>
112+
<version>${spring-version}</version>
113+
</dependency>
114+
<dependency>
115+
<groupId>org.springframework</groupId>
116+
<artifactId>spring-webmvc</artifactId>
117+
<version>${spring-version}</version>
118+
</dependency>
119+
<dependency>
120+
<groupId>org.springframework</groupId>
121+
<artifactId>spring-web</artifactId>
122+
<version>${spring-version}</version>
123+
</dependency>
124+
125+
<!--SpringFox dependencies-->
126+
<dependency>
127+
<groupId>io.springfox</groupId>
128+
<artifactId>springfox-core</artifactId>
129+
<version>${springfox-version}</version>
130+
</dependency>
131+
<dependency>
132+
<groupId>io.springfox</groupId>
133+
<artifactId>springfox-spi</artifactId>
134+
<version>${springfox-version}</version>
135+
</dependency>
136+
<dependency>
137+
<groupId>io.springfox</groupId>
138+
<artifactId>springfox-spring-web</artifactId>
139+
<version>${springfox-version}</version>
140+
</dependency>
141+
<dependency>
142+
<groupId>io.springfox</groupId>
143+
<artifactId>springfox-swagger2</artifactId>
144+
<version>${springfox-version}</version>
145+
</dependency>
146+
108147
<dependency>
109148
<groupId>org.scalatest</groupId>
110149
<artifactId>scalatest_2.9.1</artifactId>
@@ -125,11 +164,9 @@
125164
</dependencies>
126165
<repositories>
127166
<repository>
128-
<id>sonatype-snapshots</id>
129-
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
130-
<snapshots>
131-
<enabled>true</enabled>
132-
</snapshots>
167+
<id>jcenter-snapshots</id>
168+
<name>jcenter</name>
169+
<url>http://oss.jfrog.org/artifactory/oss-snapshot-local/</url>
133170
</repository>
134171
</repositories>
135172
<properties>
@@ -140,5 +177,7 @@
140177
<scala-test-version>1.6.1</scala-test-version>
141178
<junit-version>4.8.1</junit-version>
142179
<servlet-api-version>2.5</servlet-api-version>
180+
<springfox-version>2.0.0-SNAPSHOT</springfox-version>
181+
<spring-version>4.0.9.RELEASE</spring-version>
143182
</properties>
144183
</project>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{{#isQueryParam}}@ApiParam(value = "{{{description}}}"{{#required}},required=true{{/required}}{{#allowableValues}}, allowableValues="{{{allowableValues}}}"{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}) @QueryParam("{{paramName}}") {{{dataType}}} {{paramName}}{{/isQueryParam}}
1+
{{#isQueryParam}}@ApiParam(value = "{{{description}}}"{{#required}},required=true{{/required}}{{#allowableValues}}, allowableValues="{{{allowableValues}}}"{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}) @RequestParam("{{paramName}}") {{{dataType}}} {{paramName}}{{/isQueryParam}}

0 commit comments

Comments
 (0)