Skip to content
This repository was archived by the owner on Oct 30, 2023. It is now read-only.

Commit 445906d

Browse files
authored
Merge pull request #62 from frantuma/release-1.5.10
bump core version, adds multi sample with basepath discriminator refs swagger-api/swagger-core#1656
2 parents e725cd4 + ba25470 commit 445906d

27 files changed

+2114
-1
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Swagger Sample App
2+
3+
This is the pet store sample hosted at http://petstore.swagger.io!
4+
5+
## Overview
6+
This is a java project to build a stand-alone server which implements the OpenAPI Spec. You can find out
7+
more about both the spec and the framework at http://swagger.io.
8+
9+
### To run (with Maven)
10+
To run the server, run this task:
11+
12+
```
13+
mvn package -Dlog4j.configuration=file:./conf/log4j.properties jetty:run
14+
```
15+
16+
This will start Jetty embedded on port 8002.
17+
18+
### Testing the server
19+
This sample demonstrate configuring two different "swagger contexts" (config + scanner) defined in two separate servlets in same web app.
20+
Once started, you can navigate to http://localhost:8002/api1/swagger.json and http://localhost:8002/api2/swagger.json to view the Swagger Resource Listing.
21+
This tells you that the server is up and ready to demonstrate Swagger.
22+
23+
### Using the UI
24+
There is an HTML5-based API tool bundled in this sample--you can view it it at [http://localhost:8002](http://localhost:8002). This lets you inspect the API using an interactive UI. You can access the source of this code from [here](https://github.com/swagger-api/swagger-ui)
25+
26+
### Applying an API key
27+
The sample app has an implementation of the Swagger ApiAuthorizationFilter. This restricts access to resources
28+
based on api-key. There are two keys defined in the sample app:
29+
30+
<li>- default-key</li>
31+
32+
<li>- special-key</li>
33+
34+
When no key is applied, the "default-key" is applied to all operations. If the "special-key" is entered, a
35+
number of other resources are shown in the UI, including sample CRUD operations.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
log4j.rootCategory=ERROR, CONSOLE, LOGFILE
2+
3+
log4j.logger.io.swagger=ERROR
4+
log4j.logger.org.atmosphere=ERROR
5+
6+
# CONSOLE is set to be a ConsoleAppender using a PatternLayout.
7+
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
8+
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
9+
log4j.appender.CONSOLE.layout.ConversionPattern=%p %d{yyyy-MM-dd HH:mm:ss.SSS Z} %c{1} - %m%n
10+
11+
# LOGFILE is set to be a File appender using a PatternLayout.
12+
log4j.appender.LOGFILE=org.apache.log4j.RollingFileAppender
13+
log4j.appender.LOGFILE.File=logs/swagger.log
14+
log4j.appender.LOGFILE.Append=true
15+
log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout
16+
log4j.appender.LOGFILE.layout.ConversionPattern=%p %d{yyyy-MM-dd HH:mm:ss.SSS Z} %c{1} - %m%n
17+
log4j.appender.LOGFILE.MaxFileSize=10MB
18+
log4j.appender.LOGFILE.MaxBackupIndex=10
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
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+
<parent>
3+
<groupId>io.swagger</groupId>
4+
<artifactId>swagger-samples-project</artifactId>
5+
<version>1.0.0</version>
6+
<relativePath>../..</relativePath>
7+
</parent>
8+
<modelVersion>4.0.0</modelVersion>
9+
<groupId>io.swagger</groupId>
10+
<artifactId>swagger-java-jersey-multi-sample-app</artifactId>
11+
<packaging>war</packaging>
12+
<name>swagger-java-jersey-jaxrs-multi-app</name>
13+
<version>1.0.0</version>
14+
<build>
15+
<sourceDirectory>src/main/java</sourceDirectory>
16+
<plugins>
17+
<plugin>
18+
<groupId>org.apache.maven.plugins</groupId>
19+
<artifactId>maven-war-plugin</artifactId>
20+
<version>2.1.1</version>
21+
</plugin>
22+
<plugin>
23+
<artifactId>maven-failsafe-plugin</artifactId>
24+
<version>2.6</version>
25+
<executions>
26+
<execution>
27+
<goals>
28+
<goal>integration-test</goal>
29+
<goal>verify</goal>
30+
</goals>
31+
</execution>
32+
</executions>
33+
</plugin>
34+
<plugin>
35+
<groupId>org.mortbay.jetty</groupId>
36+
<artifactId>jetty-maven-plugin</artifactId>
37+
<version>${jetty-version}</version>
38+
<configuration>
39+
<webAppConfig>
40+
<contextPath>/</contextPath>
41+
</webAppConfig>
42+
<webAppSourceDirectory>target/${project.artifactId}-${project.version}</webAppSourceDirectory>
43+
<webDefaultXml>${project.basedir}/conf/jetty/webdefault.xml</webDefaultXml>
44+
<stopPort>8079</stopPort>
45+
<stopKey>stopit</stopKey>
46+
<connectors>
47+
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
48+
<port>8002</port>
49+
<maxIdleTime>60000</maxIdleTime>
50+
<confidentialPort>8443</confidentialPort>
51+
</connector>
52+
</connectors>
53+
</configuration>
54+
<executions>
55+
<execution>
56+
<id>start-jetty</id>
57+
<phase>pre-integration-test</phase>
58+
<goals>
59+
<goal>run</goal>
60+
</goals>
61+
<configuration>
62+
<scanIntervalSeconds>0</scanIntervalSeconds>
63+
<daemon>true</daemon>
64+
</configuration>
65+
</execution>
66+
<execution>
67+
<id>stop-jetty</id>
68+
<phase>post-integration-test</phase>
69+
<goals>
70+
<goal>stop</goal>
71+
</goals>
72+
</execution>
73+
</executions>
74+
</plugin>
75+
<plugin>
76+
<groupId>com.googlecode.maven-download-plugin</groupId>
77+
<artifactId>download-maven-plugin</artifactId>
78+
<version>1.2.1</version>
79+
<executions>
80+
<execution>
81+
<id>swagger-ui</id>
82+
<goals>
83+
<goal>wget</goal>
84+
</goals>
85+
<configuration>
86+
<url>https://github.com/swagger-api/swagger-ui/archive/master.tar.gz</url>
87+
<unpack>true</unpack>
88+
<outputDirectory>${project.build.directory}</outputDirectory>
89+
</configuration>
90+
</execution>
91+
</executions>
92+
</plugin>
93+
<plugin>
94+
<artifactId>maven-resources-plugin</artifactId>
95+
<version>2.6</version>
96+
<executions>
97+
<execution>
98+
<id>copy-resources</id>
99+
<phase>validate</phase>
100+
<goals>
101+
<goal>copy-resources</goal>
102+
</goals>
103+
<configuration>
104+
<outputDirectory>target/${project.artifactId}-${project.version}</outputDirectory>
105+
<resources>
106+
<resource>
107+
<directory>${project.build.directory}/swagger-ui-master/dist</directory>
108+
<filtering>true</filtering>
109+
<excludes>
110+
<exclude>index.html</exclude>
111+
</excludes>
112+
</resource>
113+
</resources>
114+
</configuration>
115+
</execution>
116+
</executions>
117+
</plugin>
118+
</plugins>
119+
</build>
120+
<dependencies>
121+
<dependency>
122+
<groupId>io.swagger</groupId>
123+
<artifactId>swagger-jersey-jaxrs</artifactId>
124+
<version>${swagger-version}</version>
125+
</dependency>
126+
<dependency>
127+
<groupId>ch.qos.logback</groupId>
128+
<artifactId>logback-classic</artifactId>
129+
<version>${logback-version}</version>
130+
</dependency>
131+
<dependency>
132+
<groupId>ch.qos.logback</groupId>
133+
<artifactId>logback-core</artifactId>
134+
<version>${logback-version}</version>
135+
</dependency>
136+
<dependency>
137+
<groupId>commons-io</groupId>
138+
<artifactId>commons-io</artifactId>
139+
<version>1.3.2</version>
140+
</dependency>
141+
<dependency>
142+
<groupId>javax.servlet</groupId>
143+
<artifactId>servlet-api</artifactId>
144+
</dependency>
145+
<dependency>
146+
<groupId>com.sun.jersey</groupId>
147+
<artifactId>jersey-core</artifactId>
148+
</dependency>
149+
<dependency>
150+
<groupId>com.sun.jersey</groupId>
151+
<artifactId>jersey-json</artifactId>
152+
</dependency>
153+
<dependency>
154+
<groupId>com.sun.jersey</groupId>
155+
<artifactId>jersey-servlet</artifactId>
156+
</dependency>
157+
<dependency>
158+
<groupId>org.scalatest</groupId>
159+
<artifactId>scalatest_2.10</artifactId>
160+
<scope>test</scope>
161+
</dependency>
162+
<dependency>
163+
<groupId>junit</groupId>
164+
<artifactId>junit</artifactId>
165+
<scope>test</scope>
166+
</dependency>
167+
</dependencies>
168+
</project>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package io.swagger.sample;
2+
3+
import io.swagger.jaxrs.config.SwaggerContextService;
4+
import io.swagger.models.*;
5+
6+
import io.swagger.models.auth.*;
7+
8+
import javax.servlet.http.HttpServlet;
9+
import javax.servlet.ServletConfig;
10+
import javax.servlet.ServletException;
11+
12+
public class Bootstrap extends HttpServlet {
13+
@Override
14+
public void init(ServletConfig config) throws ServletException {
15+
Info info = new Info()
16+
.title("Swagger Petstore")
17+
.description("api1 This is a sample server Petstore server. You can find out more about Swagger " +
18+
"at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, " +
19+
"you can use the api key `special-key` to test the authorization filters.")
20+
.termsOfService("http://swagger.io1/terms/")
21+
.contact(new Contact()
22+
.email("[email protected]"))
23+
.license(new License()
24+
.name("Apache 2.0")
25+
.url("http://www.apache.org/licenses/LICENSE-2.0.html"));
26+
27+
Swagger swagger = new Swagger().info(info);
28+
swagger.externalDocs(new ExternalDocs("Find out more about Swagger", "http://swagger.io"));
29+
swagger.securityDefinition("api_key", new ApiKeyAuthDefinition("api_key", In.HEADER));
30+
swagger.securityDefinition("petstore_auth",
31+
new OAuth2Definition()
32+
.implicit("http://petstore.swagger.io/api/oauth/dialog")
33+
.scope("read:pets", "read your pets")
34+
.scope("write:pets", "modify pets in your account"));
35+
swagger.tag(new Tag()
36+
.name("pet")
37+
.description("Everything about your Pets")
38+
.externalDocs(new ExternalDocs("Find out more", "http://swagger.io")));
39+
swagger.tag(new Tag()
40+
.name("store")
41+
.description("Access to Petstore orders"));
42+
swagger.tag(new Tag()
43+
.name("user")
44+
.description("Operations about user")
45+
.externalDocs(new ExternalDocs("Find out more about our store", "http://swagger.io")));
46+
47+
new SwaggerContextService().withServletConfig(config).withBasePath("/api1").updateSwagger(swagger);
48+
}
49+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package io.swagger.sample;
2+
3+
import io.swagger.jaxrs.config.SwaggerContextService;
4+
import io.swagger.models.Contact;
5+
import io.swagger.models.ExternalDocs;
6+
import io.swagger.models.Info;
7+
import io.swagger.models.License;
8+
import io.swagger.models.Swagger;
9+
import io.swagger.models.Tag;
10+
import io.swagger.models.auth.ApiKeyAuthDefinition;
11+
import io.swagger.models.auth.In;
12+
import io.swagger.models.auth.OAuth2Definition;
13+
14+
import javax.servlet.ServletConfig;
15+
import javax.servlet.ServletException;
16+
import javax.servlet.http.HttpServlet;
17+
18+
public class Bootstrap2 extends HttpServlet {
19+
@Override
20+
public void init(ServletConfig config) throws ServletException {
21+
Info info = new Info()
22+
.title("Swagger 2 Petstore api2")
23+
.description("api2 This is a sample server Petstore server. You can find out more about Swagger " +
24+
"at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, " +
25+
"you can use the api key `special-key` to test the authorization filters.")
26+
.termsOfService("http://swagger.io2/terms/")
27+
.contact(new Contact()
28+
.email("[email protected]"))
29+
.license(new License()
30+
.name("Apache 2.0")
31+
.url("http://www.apache.org/licenses/LICENSE-2.0.html"));
32+
33+
Swagger swagger = new Swagger().info(info);
34+
swagger.externalDocs(new ExternalDocs("Find out more about Swagger", "http://swagger.io"));
35+
swagger.securityDefinition("api_key", new ApiKeyAuthDefinition("api_key", In.HEADER));
36+
swagger.securityDefinition("petstore_auth",
37+
new OAuth2Definition()
38+
.implicit("http://petstore.swagger.io/api/oauth/dialog")
39+
.scope("read:pets", "read your pets")
40+
.scope("write:pets", "modify pets in your account"));
41+
swagger.tag(new Tag()
42+
.name("pet")
43+
.description("Everything about your Pets")
44+
.externalDocs(new ExternalDocs("Find out more", "http://swagger.io")));
45+
swagger.tag(new Tag()
46+
.name("store")
47+
.description("Access to Petstore orders"));
48+
swagger.tag(new Tag()
49+
.name("user")
50+
.description("Operations about user")
51+
.externalDocs(new ExternalDocs("Find out more about our store", "http://swagger.io")));
52+
53+
new SwaggerContextService().withServletConfig(config).withBasePath("/api2").updateSwagger(swagger);
54+
}
55+
}

0 commit comments

Comments
 (0)