Skip to content

Commit 029912b

Browse files
committed
Merge pull request #2249 from Mindera/master
Fix for #2100 - List<String> being generated as List<Enum>
2 parents c74ea67 + 051ba88 commit 029912b

39 files changed

+1879
-78
lines changed

modules/swagger-codegen/src/main/resources/JavaSpringMVC/model.mustache

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,12 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {
2020
public enum {{datatypeWithEnum}} {
2121
{{#allowableValues}}{{#values}} {{.}}, {{/values}}{{/allowableValues}}
2222
};
23-
private {{{datatypeWithEnum}}} {{name}} = {{{defaultValue}}};{{/isEnum}}{{^isEnum}}
24-
private {{{datatype}}} {{name}} = {{{defaultValue}}};{{/isEnum}}{{/vars}}
23+
{{/isEnum}}{{#items}}{{#isEnum}}
24+
public enum {{datatypeWithEnum}} {
25+
{{#allowableValues}}{{#values}} {{.}}, {{/values}}{{/allowableValues}}
26+
};
27+
{{/isEnum}}{{/items}}
28+
private {{{datatypeWithEnum}}} {{name}} = {{{defaultValue}}};{{/vars}}
2529

2630
{{#vars}}
2731
/**{{#description}}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Swagger generated server
2+
3+
Spring MVC Server
4+
5+
6+
## Overview
7+
This server was generated by the [swagger-codegen](https://github.com/swagger-api/swagger-codegen) project. By using the [OpenAPI-Spec](https://github.com/swagger-api/swagger-core), you can easily generate a server stub. This is an example of building a swagger-enabled server in Java using the Spring MVC framework.
8+
9+
The underlying library integrating swagger to Spring-MVC is [springfox](https://github.com/springfox/springfox)
10+
11+
You can view the server in swagger-ui by pointing to
12+
http://localhost:8002/v2/swagger-ui.html
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
2+
<modelVersion>4.0.0</modelVersion>
3+
<groupId>io.swagger</groupId>
4+
<artifactId>swagger-spring-mvc-server</artifactId>
5+
<packaging>jar</packaging>
6+
<name>swagger-spring-mvc-server</name>
7+
<version>1.0.0</version>
8+
<build>
9+
<sourceDirectory>src/main/java</sourceDirectory>
10+
<plugins>
11+
<plugin>
12+
<groupId>org.apache.maven.plugins</groupId>
13+
<artifactId>maven-war-plugin</artifactId>
14+
<version>2.1.1</version>
15+
</plugin>
16+
<plugin>
17+
<artifactId>maven-failsafe-plugin</artifactId>
18+
<version>2.6</version>
19+
<executions>
20+
<execution>
21+
<goals>
22+
<goal>integration-test</goal>
23+
<goal>verify</goal>
24+
</goals>
25+
</execution>
26+
</executions>
27+
</plugin>
28+
<plugin>
29+
<groupId>org.eclipse.jetty</groupId>
30+
<artifactId>jetty-maven-plugin</artifactId>
31+
<version>${jetty-version}</version>
32+
<configuration>
33+
<webAppConfig>
34+
<contextPath>/v2</contextPath>
35+
</webAppConfig>
36+
<webAppSourceDirectory>target/${project.artifactId}-${project.version}</webAppSourceDirectory>
37+
<stopPort>8079</stopPort>
38+
<stopKey>stopit</stopKey>
39+
<httpConnector>
40+
<port>8002</port>
41+
<idleTimeout>60000</idleTimeout>
42+
</httpConnector>
43+
</configuration>
44+
<executions>
45+
<execution>
46+
<id>start-jetty</id>
47+
<phase>pre-integration-test</phase>
48+
<goals>
49+
<goal>start</goal>
50+
</goals>
51+
<configuration>
52+
<scanIntervalSeconds>0</scanIntervalSeconds>
53+
<daemon>true</daemon>
54+
</configuration>
55+
</execution>
56+
<execution>
57+
<id>stop-jetty</id>
58+
<phase>post-integration-test</phase>
59+
<goals>
60+
<goal>stop</goal>
61+
</goals>
62+
</execution>
63+
</executions>
64+
</plugin>
65+
<plugin>
66+
<groupId>org.apache.maven.plugins</groupId>
67+
<artifactId>maven-compiler-plugin</artifactId>
68+
<version>3.3</version>
69+
<configuration>
70+
<source>1.8</source>
71+
<target>1.8</target>
72+
</configuration>
73+
</plugin>
74+
</plugins>
75+
</build>
76+
<dependencies>
77+
<dependency>
78+
<groupId>io.swagger</groupId>
79+
<artifactId>swagger-jersey-jaxrs</artifactId>
80+
<version>${swagger-core-version}</version>
81+
</dependency>
82+
<dependency>
83+
<groupId>org.slf4j</groupId>
84+
<artifactId>slf4j-log4j12</artifactId>
85+
<version>${slf4j-version}</version>
86+
</dependency>
87+
<dependency>
88+
<groupId>com.sun.jersey</groupId>
89+
<artifactId>jersey-core</artifactId>
90+
<version>${jersey-version}</version>
91+
</dependency>
92+
<dependency>
93+
<groupId>com.sun.jersey</groupId>
94+
<artifactId>jersey-json</artifactId>
95+
<version>${jersey-version}</version>
96+
</dependency>
97+
<dependency>
98+
<groupId>com.sun.jersey</groupId>
99+
<artifactId>jersey-servlet</artifactId>
100+
<version>${jersey-version}</version>
101+
</dependency>
102+
<dependency>
103+
<groupId>com.sun.jersey.contribs</groupId>
104+
<artifactId>jersey-multipart</artifactId>
105+
<version>${jersey-version}</version>
106+
</dependency>
107+
<dependency>
108+
<groupId>com.sun.jersey</groupId>
109+
<artifactId>jersey-server</artifactId>
110+
<version>${jersey-version}</version>
111+
</dependency>
112+
113+
<!--Spring dependencies -->
114+
<dependency>
115+
<groupId>org.springframework</groupId>
116+
<artifactId>spring-core</artifactId>
117+
<version>${spring-version}</version>
118+
</dependency>
119+
<dependency>
120+
<groupId>org.springframework</groupId>
121+
<artifactId>spring-webmvc</artifactId>
122+
<version>${spring-version}</version>
123+
</dependency>
124+
<dependency>
125+
<groupId>org.springframework</groupId>
126+
<artifactId>spring-web</artifactId>
127+
<version>${spring-version}</version>
128+
</dependency>
129+
130+
<!--SpringFox dependencies-->
131+
<dependency>
132+
<groupId>io.springfox</groupId>
133+
<artifactId>springfox-swagger2</artifactId>
134+
<version>${springfox-version}</version>
135+
</dependency>
136+
<dependency>
137+
<groupId>io.springfox</groupId>
138+
<artifactId>springfox-swagger-ui</artifactId>
139+
<version>${springfox-version}</version>
140+
</dependency>
141+
142+
<dependency>
143+
<groupId>junit</groupId>
144+
<artifactId>junit</artifactId>
145+
<version>${junit-version}</version>
146+
<scope>test</scope>
147+
</dependency>
148+
<dependency>
149+
<groupId>javax.servlet</groupId>
150+
<artifactId>servlet-api</artifactId>
151+
<version>${servlet-api-version}</version>
152+
</dependency>
153+
</dependencies>
154+
<repositories>
155+
<repository>
156+
<id>jcenter-snapshots</id>
157+
<name>jcenter</name>
158+
<url>http://oss.jfrog.org/artifactory/oss-snapshot-local/</url>
159+
</repository>
160+
</repositories>
161+
<properties>
162+
<swagger-core-version>1.5.7</swagger-core-version>
163+
<jetty-version>9.2.9.v20150224</jetty-version>
164+
<jersey-version>1.13</jersey-version>
165+
<slf4j-version>1.6.3</slf4j-version>
166+
<scala-test-version>1.6.1</scala-test-version>
167+
<junit-version>4.8.1</junit-version>
168+
<servlet-api-version>2.5</servlet-api-version>
169+
<springfox-version>2.0.4-SNAPSHOT</springfox-version>
170+
<spring-version>4.0.9.RELEASE</spring-version>
171+
</properties>
172+
</project>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package io.swagger.api;
2+
3+
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.SpringMVCServerCodegen", date = "2016-02-26T13:59:02.543Z")
4+
public class ApiException extends Exception{
5+
private int code;
6+
public ApiException (int code, String msg) {
7+
super(msg);
8+
this.code = code;
9+
}
10+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package io.swagger.api;
2+
3+
import java.io.IOException;
4+
5+
import javax.servlet.*;
6+
import javax.servlet.http.HttpServletResponse;
7+
8+
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.SpringMVCServerCodegen", date = "2016-02-26T13:59:02.543Z")
9+
public class ApiOriginFilter implements javax.servlet.Filter {
10+
@Override
11+
public void doFilter(ServletRequest request, ServletResponse response,
12+
FilterChain chain) throws IOException, ServletException {
13+
HttpServletResponse res = (HttpServletResponse) response;
14+
res.addHeader("Access-Control-Allow-Origin", "*");
15+
res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
16+
res.addHeader("Access-Control-Allow-Headers", "Content-Type");
17+
chain.doFilter(request, response);
18+
}
19+
20+
@Override
21+
public void destroy() {
22+
}
23+
24+
@Override
25+
public void init(FilterConfig filterConfig) throws ServletException {
26+
}
27+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package io.swagger.api;
2+
3+
import javax.xml.bind.annotation.XmlTransient;
4+
5+
@javax.xml.bind.annotation.XmlRootElement
6+
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.SpringMVCServerCodegen", date = "2016-02-26T13:59:02.543Z")
7+
public class ApiResponseMessage {
8+
public static final int ERROR = 1;
9+
public static final int WARNING = 2;
10+
public static final int INFO = 3;
11+
public static final int OK = 4;
12+
public static final int TOO_BUSY = 5;
13+
14+
int code;
15+
String type;
16+
String message;
17+
18+
public ApiResponseMessage(){}
19+
20+
public ApiResponseMessage(int code, String message){
21+
this.code = code;
22+
switch(code){
23+
case ERROR:
24+
setType("error");
25+
break;
26+
case WARNING:
27+
setType("warning");
28+
break;
29+
case INFO:
30+
setType("info");
31+
break;
32+
case OK:
33+
setType("ok");
34+
break;
35+
case TOO_BUSY:
36+
setType("too busy");
37+
break;
38+
default:
39+
setType("unknown");
40+
break;
41+
}
42+
this.message = message;
43+
}
44+
45+
@XmlTransient
46+
public int getCode() {
47+
return code;
48+
}
49+
50+
public void setCode(int code) {
51+
this.code = code;
52+
}
53+
54+
public String getType() {
55+
return type;
56+
}
57+
58+
public void setType(String type) {
59+
this.type = type;
60+
}
61+
62+
public String getMessage() {
63+
return message;
64+
}
65+
66+
public void setMessage(String message) {
67+
this.message = message;
68+
}
69+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package io.swagger.api;
2+
3+
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.SpringMVCServerCodegen", date = "2016-02-26T13:59:02.543Z")
4+
public class NotFoundException extends ApiException {
5+
private int code;
6+
public NotFoundException (int code, String msg) {
7+
super(code, msg);
8+
this.code = code;
9+
}
10+
}

0 commit comments

Comments
 (0)