Skip to content

Commit fb989fc

Browse files
committed
Integrated UI with the generator's packaging process
1 parent 64ea3f8 commit fb989fc

File tree

3 files changed

+146
-2
lines changed

3 files changed

+146
-2
lines changed

modules/swagger-generator/pom.xml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,49 @@
127127
</execution>
128128
</executions>
129129
</plugin>
130+
<plugin>
131+
<groupId>com.googlecode.maven-download-plugin</groupId>
132+
<artifactId>download-maven-plugin</artifactId>
133+
<version>1.2.1</version>
134+
<executions>
135+
<execution>
136+
<id>swagger-ui</id>
137+
<goals>
138+
<goal>wget</goal>
139+
</goals>
140+
<configuration>
141+
<url>https://github.com/swagger-api/swagger-ui/archive/master.tar.gz</url>
142+
<unpack>true</unpack>
143+
<outputDirectory>${project.build.directory}</outputDirectory>
144+
</configuration>
145+
</execution>
146+
</executions>
147+
</plugin>
148+
<plugin>
149+
<artifactId>maven-resources-plugin</artifactId>
150+
<version>2.6</version>
151+
<executions>
152+
<execution>
153+
<id>copy-resources</id>
154+
<phase>validate</phase>
155+
<goals>
156+
<goal>copy-resources</goal>
157+
</goals>
158+
<configuration>
159+
<outputDirectory>target/${project.artifactId}-${project.version}</outputDirectory>
160+
<resources>
161+
<resource>
162+
<directory>${project.build.directory}/swagger-ui-master/dist</directory>
163+
<filtering>true</filtering>
164+
<excludes>
165+
<exclude>index.html</exclude>
166+
</excludes>
167+
</resource>
168+
</resources>
169+
</configuration>
170+
</execution>
171+
</executions>
172+
</plugin>
130173
</plugins>
131174
</build>
132175
<dependencies>

modules/swagger-generator/src/main/java/io/swagger/generator/Bootstrap.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ public void init(ServletConfig config) throws ServletException {
2929
bc.setBasePath("/api");
3030
bc.setTitle("Swagger Generator");
3131
bc.setDescription("This is an online swagger codegen server. You can find out more " +
32-
"at <a href=\"https://github.com/wordnik/swagger-generator\">https://github.com/swagger-api/swagger-codegen</a> or on irc.freenode.net, #swagger." +
33-
"http://swagger.io/terms/");
32+
"at https://github.com/swagger-api/swagger-codegen or on [irc.freenode.net, #swagger](http://swagger.io/irc/).");
3433
bc.setTermsOfServiceUrl("http://swagger.io/terms/");
3534
bc.setContact("[email protected]");
3635
bc.setLicense("Apache 2.0");
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Swagger UI</title>
5+
<link rel="icon" type="image/png" href="images/favicon-32x32.png" sizes="32x32" />
6+
<link rel="icon" type="image/png" href="images/favicon-16x16.png" sizes="16x16" />
7+
<link href='css/typography.css' media='screen' rel='stylesheet' type='text/css'/>
8+
<link href='css/reset.css' media='screen' rel='stylesheet' type='text/css'/>
9+
<link href='css/screen.css' media='screen' rel='stylesheet' type='text/css'/>
10+
<link href='css/reset.css' media='print' rel='stylesheet' type='text/css'/>
11+
<link href='css/print.css' media='print' rel='stylesheet' type='text/css'/>
12+
<script src='lib/jquery-1.8.0.min.js' type='text/javascript'></script>
13+
<script src='lib/jquery.slideto.min.js' type='text/javascript'></script>
14+
<script src='lib/jquery.wiggle.min.js' type='text/javascript'></script>
15+
<script src='lib/jquery.ba-bbq.min.js' type='text/javascript'></script>
16+
<script src='lib/handlebars-2.0.0.js' type='text/javascript'></script>
17+
<script src='lib/underscore-min.js' type='text/javascript'></script>
18+
<script src='lib/backbone-min.js' type='text/javascript'></script>
19+
<script src='swagger-ui.js' type='text/javascript'></script>
20+
<script src='lib/highlight.7.3.pack.js' type='text/javascript'></script>
21+
<script src='lib/marked.js' type='text/javascript'></script>
22+
<script src='lib/swagger-oauth.js' type='text/javascript'></script>
23+
24+
<script type="text/javascript">
25+
$(function () {
26+
var url = window.location.search.match(/url=([^&]+)/);
27+
if (url && url.length > 1) {
28+
url = decodeURIComponent(url[1]);
29+
} else {
30+
url = "http://generator.swagger.io/api/swagger.json";
31+
}
32+
window.swaggerUi = new SwaggerUi({
33+
url: url,
34+
dom_id: "swagger-ui-container",
35+
supportedSubmitMethods: ['get', 'post', 'put', 'delete', 'patch'],
36+
onComplete: function(swaggerApi, swaggerUi){
37+
if(typeof initOAuth == "function") {
38+
initOAuth({
39+
clientId: "your-client-id",
40+
realm: "your-realms",
41+
appName: "your-app-name"
42+
});
43+
}
44+
45+
$('pre code').each(function(i, e) {
46+
hljs.highlightBlock(e)
47+
});
48+
49+
addApiKeyAuthorization();
50+
},
51+
onFailure: function(data) {
52+
log("Unable to Load SwaggerUI");
53+
},
54+
docExpansion: "none",
55+
apisSorter: "alpha",
56+
showRequestHeaders: false
57+
});
58+
59+
function addApiKeyAuthorization(){
60+
var key = encodeURIComponent($('#input_apiKey')[0].value);
61+
if(key && key.trim() != "") {
62+
var apiKeyAuth = new SwaggerClient.ApiKeyAuthorization("api_key", key, "query");
63+
window.swaggerUi.api.clientAuthorizations.add("api_key", apiKeyAuth);
64+
log("added key " + key);
65+
}
66+
}
67+
68+
$('#input_apiKey').change(addApiKeyAuthorization);
69+
70+
// if you have an apiKey you would like to pre-populate on the page for demonstration purposes...
71+
/*
72+
var apiKey = "myApiKeyXXXX123456789";
73+
$('#input_apiKey').val(apiKey);
74+
*/
75+
76+
window.swaggerUi.load();
77+
78+
function log() {
79+
if ('console' in window) {
80+
console.log.apply(console, arguments);
81+
}
82+
}
83+
});
84+
</script>
85+
</head>
86+
87+
<body class="swagger-section">
88+
<div id='header'>
89+
<div class="swagger-ui-wrap">
90+
<a id="logo" href="http://swagger.io">swagger</a>
91+
<form id='api_selector'>
92+
<div class='input'><input placeholder="http://example.com/api" id="input_baseUrl" name="baseUrl" type="text"/></div>
93+
<div class='input'><input placeholder="api_key" id="input_apiKey" name="apiKey" type="text"/></div>
94+
<div class='input'><a id="explore" href="#">Explore</a></div>
95+
</form>
96+
</div>
97+
</div>
98+
99+
<div id="message-bar" class="swagger-ui-wrap">&nbsp;</div>
100+
<div id="swagger-ui-container" class="swagger-ui-wrap"></div>
101+
</body>
102+
</html>

0 commit comments

Comments
 (0)