Skip to content

Commit edde45b

Browse files
authored
Merge pull request #3481 from swagger-api/issue-3412
refs #3412 - deprecate swagger-jaxrs2-servlet-initializer add alternative with different package
2 parents c305197 + a1b6104 commit edde45b

File tree

5 files changed

+250
-0
lines changed

5 files changed

+250
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>swagger-project</artifactId>
7+
<groupId>io.swagger.core.v3</groupId>
8+
<version>2.1.2-SNAPSHOT</version>
9+
<relativePath>../../</relativePath>
10+
</parent>
11+
<modelVersion>4.0.0</modelVersion>
12+
<artifactId>swagger-jaxrs2-servlet-initializer-v2</artifactId>
13+
<packaging>bundle</packaging>
14+
<name>swagger-jaxrs2-servlet-initializer-v2</name>
15+
<build>
16+
<sourceDirectory>src/main/java</sourceDirectory>
17+
<defaultGoal>install</defaultGoal>
18+
<testResources>
19+
<testResource>
20+
<directory>src/test/resources</directory>
21+
</testResource>
22+
</testResources>
23+
<plugins>
24+
<plugin>
25+
<groupId>org.apache.felix</groupId>
26+
<artifactId>maven-bundle-plugin</artifactId>
27+
<version>${felix-version}</version>
28+
<extensions>true</extensions>
29+
<configuration>
30+
<instructions>
31+
<Export-Package>
32+
io.swagger.v3.jaxrs2.integration.servlet
33+
</Export-Package>
34+
<Import-Package>
35+
javax.ws.rs*;version="2.0",
36+
*
37+
</Import-Package>
38+
<Automatic-Module-Name>io.swagger.v3.jaxrs2.integration.servlet</Automatic-Module-Name>
39+
</instructions>
40+
</configuration>
41+
</plugin>
42+
<plugin>
43+
<groupId>org.codehaus.mojo</groupId>
44+
<artifactId>build-helper-maven-plugin</artifactId>
45+
<version>3.0.0</version>
46+
<configuration>
47+
<portNames>
48+
<portName>jetty.port</portName>
49+
<portName>jetty.port.stop</portName>
50+
</portNames>
51+
</configuration>
52+
<executions>
53+
<execution>
54+
<id>reserve-port</id>
55+
<phase>pre-integration-test</phase>
56+
<goals>
57+
<goal>reserve-network-port</goal>
58+
</goals>
59+
</execution>
60+
</executions>
61+
</plugin>
62+
<plugin>
63+
<groupId>org.apache.maven.plugins</groupId>
64+
<artifactId>maven-failsafe-plugin</artifactId>
65+
<version>${failsafe-plugin-version}</version>
66+
<executions>
67+
<execution>
68+
<goals>
69+
<goal>integration-test</goal>
70+
<goal>verify</goal>
71+
</goals>
72+
<configuration>
73+
<systemPropertyVariables>
74+
<jetty.port>${jetty.port}</jetty.port>
75+
</systemPropertyVariables>
76+
</configuration>
77+
</execution>
78+
</executions>
79+
</plugin>
80+
<plugin>
81+
<groupId>org.eclipse.jetty</groupId>
82+
<artifactId>jetty-maven-plugin</artifactId>
83+
<configuration>
84+
<scanIntervalSeconds>10</scanIntervalSeconds>
85+
<httpConnector><port>${jetty.port}</port></httpConnector>
86+
<stopKey>a</stopKey>
87+
<stopPort>${jetty.port.stop}</stopPort>
88+
<useTestScope>true</useTestScope>
89+
<webAppSourceDirectory>${project.basedir}/src/test/webapp</webAppSourceDirectory>
90+
</configuration>
91+
<dependencies>
92+
<dependency>
93+
<groupId>io.swagger.core.v3</groupId>
94+
<artifactId>swagger-jaxrs2</artifactId>
95+
<version>${project.version}</version>
96+
</dependency>
97+
</dependencies>
98+
<executions>
99+
<execution>
100+
<id>start-jetty</id>
101+
<phase>pre-integration-test</phase>
102+
<goals>
103+
<goal>start</goal>
104+
</goals>
105+
<configuration>
106+
<scanIntervalSeconds>0</scanIntervalSeconds>
107+
</configuration>
108+
</execution>
109+
<execution>
110+
<id>stop-jetty</id>
111+
<phase>post-integration-test</phase>
112+
<goals>
113+
<goal>stop</goal>
114+
</goals>
115+
</execution>
116+
</executions>
117+
</plugin>
118+
</plugins>
119+
</build>
120+
121+
<dependencies>
122+
<dependency>
123+
<groupId>jakarta.ws.rs</groupId>
124+
<artifactId>jakarta.ws.rs-api</artifactId>
125+
<scope>provided</scope>
126+
</dependency>
127+
<dependency>
128+
<groupId>jakarta.servlet</groupId>
129+
<artifactId>jakarta.servlet-api</artifactId>
130+
<scope>provided</scope>
131+
</dependency>
132+
<dependency>
133+
<groupId>ch.qos.logback</groupId>
134+
<artifactId>logback-classic</artifactId>
135+
<scope>provided</scope>
136+
</dependency>
137+
<dependency>
138+
<groupId>ch.qos.logback</groupId>
139+
<artifactId>logback-core</artifactId>
140+
<scope>provided</scope>
141+
</dependency>
142+
<dependency>
143+
<groupId>io.swagger.core.v3</groupId>
144+
<artifactId>swagger-jaxrs2</artifactId>
145+
<version>${project.version}</version>
146+
<scope>provided</scope>
147+
</dependency>
148+
<dependency>
149+
<groupId>org.testng</groupId>
150+
<artifactId>testng</artifactId>
151+
<scope>test</scope>
152+
</dependency>
153+
<dependency>
154+
<groupId>io.rest-assured</groupId>
155+
<artifactId>rest-assured</artifactId>
156+
<scope>test</scope>
157+
<exclusions>
158+
<exclusion>
159+
<groupId>javax.xml.bind</groupId>
160+
<artifactId>jaxb-api</artifactId>
161+
</exclusion>
162+
<exclusion>
163+
<groupId>org.apache.httpcomponents</groupId>
164+
<artifactId>httpmime</artifactId>
165+
</exclusion>
166+
</exclusions>
167+
</dependency>
168+
<dependency>
169+
<groupId>org.mockito</groupId>
170+
<artifactId>mockito-core</artifactId>
171+
<scope>test</scope>
172+
</dependency>
173+
<dependency>
174+
<groupId>org.glassfish.jersey.core</groupId>
175+
<artifactId>jersey-server</artifactId>
176+
<version>${jersey2-version}</version>
177+
<scope>test</scope>
178+
<exclusions>
179+
<exclusion>
180+
<groupId>org.javassist</groupId>
181+
<artifactId>javassist</artifactId>
182+
</exclusion>
183+
</exclusions>
184+
</dependency>
185+
</dependencies>
186+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package io.swagger.v3.jaxrs2.integration.servlet;
2+
3+
import io.swagger.v3.jaxrs2.integration.JaxrsOpenApiContextBuilder;
4+
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
5+
import io.swagger.v3.oas.integration.IgnoredPackages;
6+
import io.swagger.v3.oas.integration.OpenApiConfigurationException;
7+
import io.swagger.v3.oas.integration.SwaggerConfiguration;
8+
9+
import javax.servlet.ServletContainerInitializer;
10+
import javax.servlet.ServletContext;
11+
import javax.servlet.ServletException;
12+
import javax.servlet.annotation.HandlesTypes;
13+
import javax.ws.rs.Path;
14+
import java.util.HashSet;
15+
import java.util.LinkedHashSet;
16+
import java.util.Set;
17+
import java.util.stream.Collectors;
18+
19+
/**
20+
*
21+
* @since 2.1.2
22+
*/
23+
@HandlesTypes({Path.class, OpenAPIDefinition.class})
24+
public class SwaggerServletInitializer implements ServletContainerInitializer {
25+
26+
static final Set<String> ignored = new HashSet();
27+
28+
static {
29+
ignored.addAll(IgnoredPackages.ignored);
30+
}
31+
32+
public SwaggerServletInitializer() {
33+
}
34+
35+
public void onStartup(Set<Class<?>> classes, ServletContext servletContext) throws ServletException {
36+
if (classes != null && classes.size() != 0) {
37+
Set<Class<?>> resources = new LinkedHashSet();
38+
classes.stream()
39+
.filter(c -> ignored.stream().noneMatch(i -> c.getName().startsWith(i)))
40+
.forEach(resources::add);
41+
if (!resources.isEmpty()) {
42+
// init context
43+
try {
44+
SwaggerConfiguration oasConfig = new SwaggerConfiguration()
45+
.resourceClasses(resources.stream().map(c -> c.getName()).collect(Collectors.toSet()));
46+
47+
new JaxrsOpenApiContextBuilder()
48+
.openApiConfiguration(oasConfig)
49+
.buildContext(true);
50+
} catch (OpenApiConfigurationException e) {
51+
throw new RuntimeException(e.getMessage(), e);
52+
}
53+
}
54+
}
55+
}
56+
57+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
io.swagger.v3.jaxrs2.integration.servlet.SwaggerServletInitializer

modules/swagger-jaxrs2-servlet-initializer/src/main/java/io/swagger/v3/jaxrs2/integration/SwaggerServletInitializer.java

+5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
import java.util.Set;
1616
import java.util.stream.Collectors;
1717

18+
/**
19+
* deprecated since 2.1.2. Please use io.swagger.v3.jaxrs2.integration.SwaggerServletInitializer in
20+
* swagger-jaxrs2-servlet-initializer-v2
21+
*/
22+
@Deprecated
1823
@HandlesTypes({Path.class, OpenAPIDefinition.class})
1924
public class SwaggerServletInitializer implements ServletContainerInitializer {
2025

pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@
313313
<module>modules/swagger-integration</module>
314314
<module>modules/swagger-jaxrs2</module>
315315
<module>modules/swagger-jaxrs2-servlet-initializer</module>
316+
<module>modules/swagger-jaxrs2-servlet-initializer-v2</module>
316317
<module>modules/swagger-maven-plugin</module>
317318

318319
</modules>

0 commit comments

Comments
 (0)