forked from swagger-api/swagger-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
integration servlet initializer and fixes
- Loading branch information
Showing
15 changed files
with
345 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
modules/swagger-integration/src/main/java/io/swagger/v3/oas/integration/IgnoredPackages.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package io.swagger.v3.oas.integration; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
public final class IgnoredPackages { | ||
|
||
public static final Set<String> ignored = new HashSet(); | ||
|
||
static { | ||
ignored.add("io.swagger.v3.jaxrs2.integration.resources"); | ||
ignored.add("org.glassfish.jersey"); | ||
ignored.add("org.jboss.resteasy"); | ||
ignored.add("com.sun.jersey"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,6 @@ public interface OpenApiScanner { | |
Set<Class<?>> classes(); | ||
|
||
Map<String, Object> resources(); | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>swagger-project</artifactId> | ||
<groupId>io.swagger.core.v3</groupId> | ||
<version>2.0.0-SNAPSHOT</version> | ||
<relativePath>../../</relativePath> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
<artifactId>swagger-jaxrs2-servlet-initializer</artifactId> | ||
<packaging>bundle</packaging> | ||
<name>swagger-jaxrs2-servlet-initializer</name> | ||
<build> | ||
<sourceDirectory>src/main/java</sourceDirectory> | ||
<defaultGoal>install</defaultGoal> | ||
<testResources> | ||
<testResource> | ||
<directory>src/test/resources</directory> | ||
</testResource> | ||
</testResources> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.felix</groupId> | ||
<artifactId>maven-bundle-plugin</artifactId> | ||
<version>${felix-version}</version> | ||
<extensions>true</extensions> | ||
<configuration> | ||
<instructions> | ||
<Export-Package> | ||
io.swagger.v3.jaxrs2.integration | ||
</Export-Package> | ||
<Import-Package> | ||
javax.ws.rs*;version="2.0", | ||
* | ||
</Import-Package> | ||
</instructions> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-failsafe-plugin</artifactId> | ||
<version>${failsafe-plugin-version}</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>integration-test</goal> | ||
<goal>verify</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.eclipse.jetty</groupId> | ||
<artifactId>jetty-maven-plugin</artifactId> | ||
<configuration> | ||
<scanIntervalSeconds>10</scanIntervalSeconds> | ||
<stopKey>a</stopKey> | ||
<stopPort>9999</stopPort> | ||
<useTestScope>true</useTestScope> | ||
<webAppSourceDirectory>${project.basedir}/src/test/webapp</webAppSourceDirectory> | ||
</configuration> | ||
<dependencies> | ||
<dependency> | ||
<groupId>io.swagger.core.v3</groupId> | ||
<artifactId>swagger-jaxrs2</artifactId> | ||
<version>${swagger.version}</version> | ||
</dependency> | ||
</dependencies> | ||
<executions> | ||
<execution> | ||
<id>start-jetty</id> | ||
<phase>pre-integration-test</phase> | ||
<goals> | ||
<goal>start</goal> | ||
</goals> | ||
<configuration> | ||
<scanIntervalSeconds>0</scanIntervalSeconds> | ||
</configuration> | ||
</execution> | ||
<execution> | ||
<id>stop-jetty</id> | ||
<phase>post-integration-test</phase> | ||
<goals> | ||
<goal>stop</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>javax.ws.rs</groupId> | ||
<artifactId>javax.ws.rs-api</artifactId> | ||
<version>2.1</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>javax.servlet</groupId> | ||
<artifactId>javax.servlet-api</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-classic</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-core</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.swagger.core.v3</groupId> | ||
<artifactId>swagger-jaxrs2</artifactId> | ||
<version>${swagger.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.testng</groupId> | ||
<artifactId>testng</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.jayway.restassured</groupId> | ||
<artifactId>rest-assured</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-all</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.glassfish.jersey.core</groupId> | ||
<artifactId>jersey-server</artifactId> | ||
<version>${jersey2-version}</version> | ||
<scope>test</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>org.javassist</groupId> | ||
<artifactId>javassist</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
</dependencies> | ||
<properties> | ||
<swagger.version>2.0.0-SNAPSHOT</swagger.version> | ||
</properties> | ||
</project> |
51 changes: 51 additions & 0 deletions
51
...initializer/src/main/java/io/swagger/v3/jaxrs2/integration/SwaggerServletInitializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package io.swagger.v3.jaxrs2.integration; | ||
|
||
import io.swagger.v3.oas.integration.IgnoredPackages; | ||
import io.swagger.v3.oas.integration.OpenApiConfigurationException; | ||
import io.swagger.v3.oas.integration.SwaggerConfiguration; | ||
|
||
import javax.servlet.ServletContainerInitializer; | ||
import javax.servlet.ServletContext; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.annotation.HandlesTypes; | ||
import javax.ws.rs.Path; | ||
import java.util.HashSet; | ||
import java.util.LinkedHashSet; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
@HandlesTypes({Path.class}) | ||
public class SwaggerServletInitializer implements ServletContainerInitializer { | ||
|
||
static final Set<String> ignored = new HashSet(); | ||
|
||
static { | ||
ignored.addAll(IgnoredPackages.ignored); | ||
} | ||
|
||
public SwaggerServletInitializer() { | ||
} | ||
|
||
public void onStartup(Set<Class<?>> classes, ServletContext servletContext) throws ServletException { | ||
if (classes != null && classes.size() != 0) { | ||
Set<Class<?>> resources = new LinkedHashSet(); | ||
classes.stream() | ||
.filter(c -> ignored.stream().noneMatch(i -> c.getName().startsWith(i))) | ||
.forEach(resources::add); | ||
if (!resources.isEmpty()) { | ||
// init context | ||
try { | ||
SwaggerConfiguration oasConfig = new SwaggerConfiguration() | ||
.resourceClasses(resources.stream().map(c -> c.getName()).collect(Collectors.toSet())); | ||
|
||
new JaxrsOpenApiContextBuilder() | ||
.openApiConfiguration(oasConfig) | ||
.buildContext(true); | ||
} catch (OpenApiConfigurationException e) { | ||
throw new RuntimeException(e.getMessage(), e); | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
1 change: 1 addition & 0 deletions
1
...nitializer/src/main/resources/META-INF/services/javax.servlet.ServletContainerInitializer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
io.swagger.v3.jaxrs2.integration.SwaggerServletInitializer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.