Skip to content

Commit d019bbd

Browse files
fuj1g0nwing328
authored andcommitted
[Java][jaxrs-jersey] add sample with jaxrs-jersey + openapi v3 (#778)
* create sample with "jaxrs-jersey" language & openapi v3 * circle ci setting * fix typo. also add "jaxrs-jersey" to all samples profile * artifactId conflicts. rename. * generate samples with "./bin/openapi3/jaxrs-jersey-petstore.sh"
1 parent 748d1d7 commit d019bbd

35 files changed

Lines changed: 2524 additions & 0 deletions

CI/pom.xml.circleci

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,19 @@
607607
<module>samples/server/petstore/jaxrs/jersey1</module>
608608
</modules>
609609
</profile>
610+
<profile>
611+
<!-- openapi v3's one -->
612+
<id>jaxrs-jersey</id>
613+
<activation>
614+
<property>
615+
<name>env</name>
616+
<value>java</value>
617+
</property>
618+
</activation>
619+
<modules>
620+
<module>samples/server/petstore/jaxrs-jersey</module>
621+
</modules>
622+
</profile>
610623
<profile>
611624
<id>jaxrs-spec</id>
612625
<activation>
@@ -898,6 +911,7 @@
898911
<module>samples/client/petstore/kotlin-threetenbp/</module>
899912
<module>samples/client/petstore/kotlin-string/</module>
900913
<!-- servers -->
914+
<module>samples/server/petstore/jaxrs-jersey</module>
901915
<module>samples/server/petstore/jaxrs-spec</module>
902916
<module>samples/server/petstore/jaxrs-spec-interface</module>
903917
<module>samples/server/petstore/jaxrs-spec-interface-response</module>

CI/pom.xml.circleci.java7

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,19 @@
607607
<module>samples/server/petstore/jaxrs/jersey1</module>
608608
</modules>
609609
</profile>
610+
<profile>
611+
<!-- openapi v3's one -->
612+
<id>jaxrs-jersey</id>
613+
<activation>
614+
<property>
615+
<name>env</name>
616+
<value>java</value>
617+
</property>
618+
</activation>
619+
<modules>
620+
<module>samples/server/petstore/jaxrs-jersey</module>
621+
</modules>
622+
</profile>
610623
<profile>
611624
<id>jaxrs-spec</id>
612625
<activation>
@@ -889,6 +902,7 @@
889902
<module>samples/client/petstore/java/google-api-client</module>
890903
<module>samples/client/petstore/kotlin/</module>
891904
<!-- servers -->
905+
<module>samples/server/petstore/jaxrs-jersey</module>
892906
<module>samples/server/petstore/jaxrs-spec</module>
893907
<module>samples/server/petstore/jaxrs-spec-interface</module>
894908
<module>samples/server/petstore/jaxrs-spec-interface-response</module>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/sh
2+
3+
SCRIPT="$0"
4+
echo "# START SCRIPT: $SCRIPT"
5+
6+
while [ -h "$SCRIPT" ] ; do
7+
ls=`ls -ld "$SCRIPT"`
8+
link=`expr "$ls" : '.*-> \(.*\)$'`
9+
if expr "$link" : '/.*' > /dev/null; then
10+
SCRIPT="$link"
11+
else
12+
SCRIPT=`dirname "$SCRIPT"`/"$link"
13+
fi
14+
done
15+
16+
if [ ! -d "${APP_DIR}" ]; then
17+
APP_DIR=`dirname "$SCRIPT"`/..
18+
APP_DIR=`cd "${APP_DIR}"; pwd`
19+
fi
20+
21+
executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar"
22+
23+
if [ ! -f "$executable" ]
24+
then
25+
mvn clean package
26+
fi
27+
28+
# if you've executed sbt assembly previously it will use that instead.
29+
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
30+
ags="generate --artifact-id "openapiv3-jaxrs-jersey-petstore-server" -t modules/openapi-generator/src/main/resources/JavaJaxRS/ -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g jaxrs-jersey -o samples/server/petstore/jaxrs-jersey $@"
31+
32+
java $JAVA_OPTS -jar $executable $ags

pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,19 @@
715715
<module>samples/server/petstore/jaxrs/jersey1</module>
716716
</modules>
717717
</profile>
718+
<profile>
719+
<!-- openapi v3's one -->
720+
<id>jaxrs-jersey</id>
721+
<activation>
722+
<property>
723+
<name>env</name>
724+
<value>java</value>
725+
</property>
726+
</activation>
727+
<modules>
728+
<module>samples/server/petstore/jaxrs-jersey</module>
729+
</modules>
730+
</profile>
718731
<profile>
719732
<id>jaxrs-spec</id>
720733
<activation>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# OpenAPI Generator Ignore
2+
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
3+
4+
# Use this file to prevent files from being overwritten by the generator.
5+
# The patterns follow closely to .gitignore or .dockerignore.
6+
7+
# As an example, the C# client generator defines ApiClient.cs.
8+
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
9+
#ApiClient.cs
10+
11+
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
12+
#foo/*/qux
13+
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
14+
15+
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
16+
#foo/**/qux
17+
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
18+
19+
# You can also negate patterns with an exclamation (!).
20+
# For example, you can ignore all files in a docs folder with the file extension .md:
21+
#docs/*.md
22+
# Then explicitly reverse the ignore rule for a single file:
23+
#!docs/README.md
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.2.1-SNAPSHOT
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Swagger Jersey generated server
2+
3+
## Overview
4+
This server was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the
5+
[OpenAPI-Spec](https://openapis.org) from a remote server, you can easily generate a server stub. This
6+
is an example of building a OpenAPI-enabled JAX-RS server.
7+
8+
This example uses the [JAX-RS](https://jax-rs-spec.java.net/) framework.
9+
10+
To run the server, please execute the following:
11+
12+
```
13+
mvn clean package jetty:run
14+
```
15+
16+
You can then view the swagger listing here:
17+
18+
```
19+
http://localhost:8080/v2/openapi.json
20+
```
21+
22+
Note that if you have configured the `host` to be something other than localhost, the calls through
23+
swagger-ui will be directed to that host and not localhost!
Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
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>org.openapitools</groupId>
4+
<artifactId>openapiv3-jaxrs-jersey-petstore-server</artifactId>
5+
<packaging>jar</packaging>
6+
<name>openapiv3-jaxrs-jersey-petstore-server</name>
7+
<version>1.0.0</version>
8+
9+
<licenses>
10+
<license>
11+
<name>Unlicense</name>
12+
<url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
13+
<distribution>repo</distribution>
14+
</license>
15+
</licenses>
16+
17+
<build>
18+
<sourceDirectory>src/main/java</sourceDirectory>
19+
<plugins>
20+
<plugin>
21+
<groupId>org.apache.maven.plugins</groupId>
22+
<artifactId>maven-war-plugin</artifactId>
23+
<version>3.1.0</version>
24+
</plugin>
25+
<plugin>
26+
<artifactId>maven-failsafe-plugin</artifactId>
27+
<version>2.6</version>
28+
<executions>
29+
<execution>
30+
<goals>
31+
<goal>integration-test</goal>
32+
<goal>verify</goal>
33+
</goals>
34+
</execution>
35+
</executions>
36+
</plugin>
37+
<plugin>
38+
<groupId>org.eclipse.jetty</groupId>
39+
<artifactId>jetty-maven-plugin</artifactId>
40+
<version>${jetty-version}</version>
41+
<configuration>
42+
<webApp>
43+
<contextPath>/</contextPath>
44+
</webApp>
45+
<webAppSourceDirectory>target/${project.artifactId}-${project.version}</webAppSourceDirectory>
46+
<stopPort>8079</stopPort>
47+
<stopKey>stopit</stopKey>
48+
<stopWait>10</stopWait>
49+
<httpConnector>
50+
<port>8080</port>
51+
<idleTimeout>60000</idleTimeout>
52+
</httpConnector>
53+
</configuration>
54+
<dependencies>
55+
<dependency>
56+
<groupId>javax.validation</groupId>
57+
<artifactId>validation-api</artifactId>
58+
<version>${beanvalidation-version}</version>
59+
</dependency>
60+
</dependencies>
61+
<executions>
62+
<execution>
63+
<id>start-jetty</id>
64+
<phase>pre-integration-test</phase>
65+
<goals>
66+
<goal>start</goal>
67+
</goals>
68+
<configuration>
69+
<scanIntervalSeconds>0</scanIntervalSeconds>
70+
<daemon>true</daemon>
71+
</configuration>
72+
</execution>
73+
<execution>
74+
<id>stop-jetty</id>
75+
<phase>post-integration-test</phase>
76+
<goals>
77+
<goal>stop</goal>
78+
</goals>
79+
</execution>
80+
</executions>
81+
</plugin>
82+
<plugin>
83+
<groupId>org.codehaus.mojo</groupId>
84+
<artifactId>build-helper-maven-plugin</artifactId>
85+
<version>1.9.1</version>
86+
<executions>
87+
<execution>
88+
<id>add-source</id>
89+
<phase>generate-sources</phase>
90+
<goals>
91+
<goal>add-source</goal>
92+
</goals>
93+
<configuration>
94+
<sources>
95+
<source>src/gen/java</source>
96+
</sources>
97+
</configuration>
98+
</execution>
99+
</executions>
100+
</plugin>
101+
</plugins>
102+
</build>
103+
<dependencies>
104+
<dependency>
105+
<groupId>io.swagger</groupId>
106+
<artifactId>swagger-jersey2-jaxrs</artifactId>
107+
<scope>compile</scope>
108+
<version>${swagger-core-version}</version>
109+
</dependency>
110+
<dependency>
111+
<groupId>ch.qos.logback</groupId>
112+
<artifactId>logback-classic</artifactId>
113+
<version>${logback-version}</version>
114+
<scope>compile</scope>
115+
</dependency>
116+
<dependency>
117+
<groupId>ch.qos.logback</groupId>
118+
<artifactId>logback-core</artifactId>
119+
<version>${logback-version}</version>
120+
<scope>compile</scope>
121+
</dependency>
122+
<dependency>
123+
<groupId>junit</groupId>
124+
<artifactId>junit</artifactId>
125+
<version>${junit-version}</version>
126+
<scope>test</scope>
127+
</dependency>
128+
<dependency>
129+
<groupId>javax.servlet</groupId>
130+
<artifactId>servlet-api</artifactId>
131+
<version>${servlet-api-version}</version>
132+
</dependency>
133+
<dependency>
134+
<groupId>org.glassfish.jersey.containers</groupId>
135+
<artifactId>jersey-container-servlet-core</artifactId>
136+
<version>${jersey2-version}</version>
137+
</dependency>
138+
<dependency>
139+
<groupId>org.glassfish.jersey.media</groupId>
140+
<artifactId>jersey-media-multipart</artifactId>
141+
<version>${jersey2-version}</version>
142+
</dependency>
143+
<dependency>
144+
<groupId>com.fasterxml.jackson.datatype</groupId>
145+
<artifactId>jackson-datatype-joda</artifactId>
146+
<version>${jackson-version}</version>
147+
</dependency>
148+
<dependency>
149+
<groupId>com.fasterxml.jackson.jaxrs</groupId>
150+
<artifactId>jackson-jaxrs-json-provider</artifactId>
151+
<version>${jackson-version}</version>
152+
</dependency>
153+
<!-- Base64 encoding that works in both JVM and Android -->
154+
<dependency>
155+
<groupId>com.brsanthu</groupId>
156+
<artifactId>migbase64</artifactId>
157+
<version>2.2</version>
158+
</dependency>
159+
160+
161+
<!-- Bean Validation API support -->
162+
<dependency>
163+
<groupId>javax.validation</groupId>
164+
<artifactId>validation-api</artifactId>
165+
<version>${beanvalidation-version}</version>
166+
<scope>provided</scope>
167+
</dependency>
168+
169+
</dependencies>
170+
<repositories>
171+
<repository>
172+
<id>sonatype-snapshots</id>
173+
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
174+
<snapshots>
175+
<enabled>true</enabled>
176+
</snapshots>
177+
</repository>
178+
</repositories>
179+
<properties>
180+
<java.version>1.7</java.version>
181+
<maven.compiler.source>${java.version}</maven.compiler.source>
182+
<maven.compiler.target>${java.version}</maven.compiler.target>
183+
<swagger-core-version>1.5.18</swagger-core-version>
184+
<beanvalidation-version>1.1.0.Final</beanvalidation-version>
185+
<jetty-version>9.2.9.v20150224</jetty-version>
186+
<jersey2-version>2.22.2</jersey2-version>
187+
<jackson-version>2.8.9</jackson-version>
188+
<junit-version>4.12</junit-version>
189+
<logback-version>1.1.7</logback-version>
190+
<servlet-api-version>2.5</servlet-api-version>
191+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
192+
</properties>
193+
</project>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package org.openapitools.api;
2+
3+
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaJerseyServerCodegen", date = "2018-08-10T15:02:11.723+09:00[Asia/Tokyo]")
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: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package org.openapitools.api;
2+
3+
import java.io.IOException;
4+
5+
import javax.servlet.*;
6+
import javax.servlet.http.HttpServletResponse;
7+
8+
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaJerseyServerCodegen", date = "2018-08-10T15:02:11.723+09:00[Asia/Tokyo]")
9+
public class ApiOriginFilter implements javax.servlet.Filter {
10+
public void doFilter(ServletRequest request, ServletResponse response,
11+
FilterChain chain) throws IOException, ServletException {
12+
HttpServletResponse res = (HttpServletResponse) response;
13+
res.addHeader("Access-Control-Allow-Origin", "*");
14+
res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
15+
res.addHeader("Access-Control-Allow-Headers", "Content-Type");
16+
chain.doFilter(request, response);
17+
}
18+
19+
public void destroy() {}
20+
21+
public void init(FilterConfig filterConfig) throws ServletException {}
22+
}

0 commit comments

Comments
 (0)