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

Commit 79dd2a9

Browse files
committed
refs swagger-api/swagger-core#2312 - bootstrap draft
1 parent 95addce commit 79dd2a9

File tree

6 files changed

+91
-6
lines changed

6 files changed

+91
-6
lines changed

java/java-jaxrs/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
<version>${jetty-version}</version>
3838
<configuration>
3939
<webAppConfig>
40-
<contextPath>/</contextPath>
40+
<contextPath>/asdsadsdsadsda</contextPath>
4141
</webAppConfig>
4242
<webAppSourceDirectory>target/${project.artifactId}-${project.version}</webAppSourceDirectory>
4343
<webDefaultXml>${project.basedir}/conf/jetty/webdefault.xml</webDefaultXml>

java/java-jaxrs/src/main/java/io/swagger/sample/Bootstrap.java

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public void init(ServletConfig config) throws ServletException {
2626
.url("http://www.apache.org/licenses/LICENSE-2.0.html"));
2727

2828
ServletContext context = config.getServletContext();
29+
System.out.println("XXXXXXXXXXXXXXXXXXXXXX " + context.getContextPath());
2930
Swagger swagger = new Swagger().info(info);
3031
swagger.securityDefinition("api_key", new ApiKeyAuthDefinition("api_key", In.HEADER));
3132
swagger.securityDefinition("petstore_auth",

java/java-jersey2/pom.xml

+31
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,27 @@
3535
<groupId>org.eclipse.jetty</groupId>
3636
<artifactId>jetty-maven-plugin</artifactId>
3737
<version>${jetty-version}</version>
38+
<dependencies>
39+
<!--
40+
<dependency>
41+
<groupId>ch.qos.logback</groupId>
42+
<artifactId>logback-classic</artifactId>
43+
<version>${logback-version}</version>
44+
</dependency>
45+
-->
46+
<!--
47+
<dependency>
48+
<groupId>ch.qos.logback</groupId>
49+
<artifactId>logback-access</artifactId>
50+
<version>${logback-version}</version>
51+
</dependency>
52+
-->
53+
<dependency>
54+
<groupId>org.slf4j</groupId>
55+
<artifactId>slf4j-api</artifactId>
56+
<version>${slf4j-version}</version>
57+
</dependency>
58+
</dependencies>
3859
<configuration>
3960
<webApp>
4061
<contextPath>/</contextPath>
@@ -46,6 +67,16 @@
4667
<port>8002</port>
4768
<idleTimeout>60000</idleTimeout>
4869
</httpConnector>
70+
<systemProperties>
71+
<systemProperty>
72+
<name>org.eclipse.jetty.util.log.Log</name>
73+
<value>org.eclipse.jetty.util.log.Slf4jLog</value>
74+
</systemProperty>
75+
<systemProperty>
76+
<name>logback.configurationFile</name>
77+
<value>src/main/resources/logback.xml</value>
78+
</systemProperty>
79+
</systemProperties>
4980
</configuration>
5081
<executions>
5182
<execution>

java/java-jersey2/src/main/java/io/swagger/sample/Bootstrap.java

+22-3
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,42 @@
11
package io.swagger.sample;
22

33
import io.swagger.jaxrs2.Reader;
4+
import io.swagger.jaxrs2.config.SwaggerContextService;
5+
import io.swagger.jaxrs2.integration.ContextUtils;
6+
import io.swagger.jaxrs2.integration.XmlWebOpenApiContext;
7+
import io.swagger.oas.integration.OpenApiConfiguration;
8+
import io.swagger.oas.integration.OpenApiContextLocator;
49
import io.swagger.oas.models.OpenAPI;
10+
import io.swagger.oas.models.info.Contact;
11+
import io.swagger.oas.models.info.Info;
12+
import io.swagger.oas.models.info.License;
513
import io.swagger.sample.resource.Metadata;
614
import io.swagger.sample.resource.PetResource;
715
import io.swagger.sample.resource.UserResource;
816

917
import javax.servlet.ServletConfig;
18+
import javax.servlet.ServletContext;
1019
import javax.servlet.ServletException;
1120
import javax.servlet.http.HttpServlet;
1221

1322
public class Bootstrap extends HttpServlet {
1423
@Override
1524
public void init(ServletConfig config) throws ServletException {
16-
OpenAPI oas = new OpenAPI();
25+
//OpenAPI oas = new OpenAPI();
1726

18-
Reader reader = new Reader(oas, null);
27+
//Reader reader = new Reader(oas);
28+
/*
1929
2030
reader.read(Metadata.class);
2131
reader.read(UserResource.class);
2232
reader.read(PetResource.class);
2333
2434
config.getServletContext().setAttribute("oas", reader.getOpenAPI());
35+
*/
2536

26-
/*
37+
38+
39+
OpenAPI oas = new OpenAPI();
2740
Info info = new Info()
2841
.title("Swagger Sample App")
2942
.description("This is a sample server Petstore server. You can find out more about Swagger " +
@@ -36,6 +49,11 @@ public void init(ServletConfig config) throws ServletException {
3649
.name("Apache 2.0")
3750
.url("http://www.apache.org/licenses/LICENSE-2.0.html"));
3851

52+
oas.info(info);
53+
OpenApiConfiguration oasConfig = new OpenApiConfiguration()
54+
.openApi(oas)
55+
.withResourcePackage("io.swagger.sample.resource");
56+
/*
3957
ServletContext context = config.getServletContext();
4058
Swagger swagger = new Swagger().info(info);
4159
swagger.securityDefinition("api_key", new ApiKeyAuthDefinition("api_key", In.HEADER));
@@ -46,5 +64,6 @@ public void init(ServletConfig config) throws ServletException {
4664
.scope("write:pets", "modify pets in your account"));
4765
new SwaggerContextService().withServletConfig(config).updateSwagger(swagger);
4866
*/
67+
ContextUtils.getOrBuildContext(oasConfig);
4968
}
5069
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[
2+
{
3+
"resourcePackage": "io.swagger.sample.resource",
4+
"openApi": {
5+
"info": {
6+
"version": "1.0",
7+
"title": "Swagger Pet Sample App",
8+
"description": "This is a TEST AAsample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.",
9+
"termsOfService": "http://swagger.io/terms/",
10+
"contact": {
11+
"email": "[email protected]"
12+
},
13+
"license": {
14+
"name": "Apache 2.0",
15+
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
16+
}
17+
}
18+
}
19+
}
20+
]

java/java-jersey2/src/main/webapp/WEB-INF/web.xml

+16-2
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,23 @@
99
<init-param>
1010
<param-name>jersey.config.server.provider.packages</param-name>
1111
<param-value>
12-
com.fasterxml.jackson.jaxrs.json,
13-
io.swagger.sample.util,
12+
com.fasterxml.jackson.jaxrs.json,io.swagger.jaxrs2.integration.listing,io.swagger.sample.resource
13+
</param-value>
14+
<!--
15+
<param-value>
16+
com.fasterxml.jackson.jaxrs.json,io.swagger.jaxrs2.integration.listing,
17+
//io.swagger.sample.util,
18+
1419
io.swagger.sample.resource
1520
</param-value>
21+
-->
22+
1623
</init-param>
24+
<init-param>
25+
<param-name>openApi.configuration.location</param-name>
26+
<param-value>/openapi-configuration.json</param-value>
27+
</init-param>
28+
1729
<init-param>
1830
<param-name>jersey.config.server.wadl.disableWadl</param-name>
1931
<param-value>true</param-value>
@@ -48,11 +60,13 @@
4860
<filter-name>ApiOriginFilter</filter-name>
4961
<filter-class>io.swagger.sample.util.ApiOriginFilter</filter-class>
5062
</filter>
63+
<!--
5164
<servlet>
5265
<servlet-name>Bootstrap</servlet-name>
5366
<servlet-class>io.swagger.sample.Bootstrap</servlet-class>
5467
<load-on-startup>2</load-on-startup>
5568
</servlet>
69+
-->
5670
<filter-mapping>
5771
<filter-name>ApiOriginFilter</filter-name>
5872
<url-pattern>/*</url-pattern>

0 commit comments

Comments
 (0)