Skip to content

Commit aa3d56a

Browse files
author
Stephen Scott
committedDec 1, 2021
Bumped version of swagger-ui-dist and moved js template usage
1 parent ff10df4 commit aa3d56a

File tree

4 files changed

+65
-145
lines changed

4 files changed

+65
-145
lines changed
 

‎index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ var htmlTplString = `
1515
<title><% title %></title>
1616
<link rel="stylesheet" type="text/css" href="./swagger-ui.css" >
1717
<% favIconString %>
18-
<% customJs %>
1918
<style>
2019
html
2120
{
@@ -78,6 +77,7 @@ var htmlTplString = `
7877
<script src="./swagger-ui-bundle.js"> </script>
7978
<script src="./swagger-ui-standalone-preset.js"> </script>
8079
<script src="./swagger-ui-init.js"> </script>
80+
<% customJs %>
8181
<% customCssUrl %>
8282
<style>
8383
<% customCss %>

‎package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "swagger-ui-express",
3-
"version": "4.1.6",
3+
"version": "4.2.0",
44
"description": "Swagger UI Express",
55
"main": "./index.js",
66
"files": [
@@ -33,7 +33,7 @@
3333
"istanbul-badges-readme": "^1.2.0",
3434
"mocha": "2.2.5",
3535
"nyc": "^15.1.0",
36-
"phantom": "2.1.21"
36+
"puppeteer": "5.3.1"
3737
},
3838
"author": {
3939
"name": "Stephen Scott",
@@ -50,7 +50,7 @@
5050
},
5151
"homepage": "https://github.com/scottie1984/swagger-ui-express",
5252
"dependencies": {
53-
"swagger-ui-dist": "^3.52.5"
53+
"swagger-ui-dist": ">3.52.5"
5454
},
5555
"peerDependencies": {
5656
"express": ">=4.0.0"

‎test/test.spec.js

+58-140
Original file line numberDiff line numberDiff line change
@@ -1,174 +1,92 @@
1-
var assert = require('assert');
2-
var app = require('./testapp/app');
3-
var http = require('http');
4-
var phantom = require('phantom');
1+
const assert = require('assert');
2+
const app = require('./testapp/app');
3+
const puppeteer = require('puppeteer');
54
require('es6-shim');
65

76
describe('integration', function() {
87
var server;
8+
var browser = null;
99
var sitepage = null;
10-
var phInstance = null;
1110

1211
before(function(done) {
1312
app.set('port', 3001);
14-
1513
server = app.listen(app.get('port'), function() {
1614
done();
1715
});
1816
});
1917

20-
after(function() {
18+
after(async function() {
2119
server.close();
22-
sitepage.close();
23-
phInstance.exit();
20+
await sitepage.close();
21+
await browser.close();
2422
});
2523

26-
it('should have API Documentation hosted at /api-docs', function(done) {
24+
it('should intialize browser', async function() {
2725
this.timeout(30000);
28-
phantom.create()
29-
.then(function(instance) {
30-
phInstance = instance;
31-
return instance.createPage();
32-
})
33-
.then(function(page) {
34-
sitepage = page;
35-
return page.open('http://localhost:3001/api-docs/');
36-
})
37-
.then(function(status) {
38-
setTimeout(function() {
39-
assert.equal('success', status);
40-
done();
41-
}, 100);
42-
})
43-
.catch(function(err) {
44-
done(err);
45-
});
26+
browser = await puppeteer.launch();
27+
sitepage = await browser.newPage();
28+
});
29+
30+
it('should have API Documentation hosted at /api-docs', async function() {
31+
const httpResponse = await sitepage.goto('http://localhost:3001/api-docs/');
32+
assert.ok(httpResponse.ok());
4633
});
4734

48-
it('should contain the expected elements on the page', function(done) {
49-
sitepage.property('title')
50-
.then(function(title) {
51-
assert.equal('Swagger UI', title);
52-
return sitepage.evaluate(function() {
53-
return document.querySelector('.swagger-ui').innerHTML;
54-
});
55-
})
56-
.then(function(html) {
57-
assert.ok(html);
58-
assert.notEqual(html.indexOf('id="operations-/test-index"'), -1);
59-
assert.notEqual(html.indexOf('id="operations-/test-impossible"'), -1);
60-
done();
61-
})
62-
.catch(function(err) {
63-
done(err);
64-
});
35+
it('should contain the expected elements on the page from /api-docs', async function() {
36+
await sitepage.waitForSelector('.information-container', { timeout: 2000 });
37+
assert.equal('Swagger UI', await sitepage.title());
38+
const html = await sitepage.evaluate(() => document.querySelector('.swagger-ui').innerHTML);
39+
assert.ok(html);
40+
assert.notEqual(html.indexOf("id=\"operations-\\/test-index\""), -1);
41+
assert.notEqual(html.indexOf("id=\"operations-\\/test-impossible\""), -1);
6542
});
6643

67-
it('should have API Documentation hosted at /api-docs-from-url', function(done) {
68-
sitepage.open('http://localhost:3001/api-docs-from-url/')
69-
.then(function(status) {
70-
setTimeout(function() {
71-
assert.equal('success', status);
72-
done();
73-
}, 100);
74-
})
75-
.catch(function(err) {
76-
done(err);
77-
});
44+
it('should have API Documentation hosted at /api-docs-from-url', async function() {
45+
const httpResponse = await sitepage.goto('http://localhost:3001/api-docs-from-url/');
46+
assert.ok(httpResponse.ok());
7847
});
7948

80-
it('should contain the expected elements on the page', function(done) {
81-
sitepage.property('title')
82-
.then(function(title) {
83-
assert.equal('Swagger UI', title);
84-
return sitepage.evaluate(function() {
85-
return document.querySelector('.swagger-ui').innerHTML;
86-
});
87-
})
88-
.then(function(html) {
89-
assert.ok(html);
90-
assert.notEqual(html.indexOf('id="operations-/test-index"'), -1);
91-
assert.notEqual(html.indexOf('id="operations-/test-impossible"'), -1);
92-
done();
93-
})
94-
.catch(function(err) {
95-
done(err);
96-
});
49+
it('should contain the expected elements on the page from /api-docs-from-url', async function() {
50+
await sitepage.waitForSelector('.information-container', { timeout: 2000 });
51+
assert.equal('Swagger UI', await sitepage.title());
52+
const html = await sitepage.evaluate(() => document.querySelector('.swagger-ui').innerHTML);
53+
assert.ok(html);
54+
// console.log(`**** ${html}`);
55+
assert.notEqual(html.indexOf("id=\"operations-\\/test-index\""), -1);
56+
assert.notEqual(html.indexOf("id=\"operations-\\/test-impossible\""), -1);
9757
});
9858

99-
it('should have API Documentation hosted at /api-docs-using-object', function(done) {
100-
sitepage.open('http://localhost:3001/api-docs-using-object/')
101-
.then(function(status) {
102-
setTimeout(function() {
103-
assert.equal('success', status);
104-
done();
105-
}, 100);
106-
})
107-
.catch(function(err) {
108-
done(err);
109-
});
59+
it('should have API Documentation hosted at /api-docs-using-object', async function() {
60+
const httpResponse = await sitepage.goto('http://localhost:3001/api-docs-using-object/');
61+
assert.ok(httpResponse.ok());
11062
});
11163

112-
it('should contain the expected elements on the page for api-docs-using-object', function(done) {
113-
sitepage.property('title')
114-
.then(function(title) {
115-
assert.equal('Swagger UI', title);
116-
return sitepage.evaluate(function() {
117-
return document.querySelector('.swagger-ui').innerHTML;
118-
});
119-
})
120-
.then(function(html) {
121-
assert.ok(html);
122-
assert.notEqual(html.indexOf('id="operations-/test-index"'), -1);
123-
assert.notEqual(html.indexOf('id="operations-/test-impossible"'), -1);
124-
done();
125-
})
126-
.catch(function(err) {
127-
done(err);
128-
});
64+
it('should contain the expected elements on the page for api-docs-using-object', async function() {
65+
await sitepage.waitForSelector('.information-container', { timeout: 2000 });
66+
assert.equal('Swagger UI', await sitepage.title());
67+
const html = await sitepage.evaluate(() => document.querySelector('.swagger-ui').innerHTML);
68+
assert.ok(html);
69+
assert.notEqual(html.indexOf("id=\"operations-\\/test-index\""), -1);
70+
assert.notEqual(html.indexOf("id=\"operations-\\/test-impossible\""), -1);
12971
});
13072

131-
it('should have API Documentation hosted at /api-docs-with-null', function(done) {
132-
sitepage.open('http://localhost:3001/api-docs-with-null/')
133-
.then(function(status) {
134-
setTimeout(function() {
135-
assert.equal('success', status);
136-
done();
137-
}, 100);
138-
})
139-
.catch(function(err) {
140-
done(err);
141-
});
73+
it('should have API Documentation hosted at /api-docs-with-null', async function() {
74+
const httpResponse = await sitepage.goto('http://localhost:3001/api-docs-with-null/');
75+
assert.ok(httpResponse.ok());
14276
});
14377

144-
it('should contain the expected elements on the page for api-docs-with-null', function(done) {
145-
sitepage.property('title')
146-
.then(function(title) {
147-
assert.equal('Swagger UI', title);
148-
return sitepage.evaluate(function() {
149-
return document.querySelector('.swagger-ui').innerHTML;
150-
});
151-
})
152-
.then(function(html) {
153-
assert.ok(html);
154-
assert.notEqual(html.indexOf('id="operations-/test-index"'), -1);
155-
assert.notEqual(html.indexOf('id="operations-/test-impossible"'), -1);
156-
done();
157-
})
158-
.catch(function(err) {
159-
done(err);
160-
});
78+
it('should contain the expected elements on the page for api-docs-with-null', async function() {
79+
await sitepage.waitForSelector('.information-container', { timeout: 2000 });
80+
assert.equal('Swagger UI', await sitepage.title());
81+
const html = await sitepage.evaluate(() => document.querySelector('.swagger-ui').innerHTML);
82+
assert.ok(html);
83+
assert.notEqual(html.indexOf("id=\"operations-\\/test-index\""), -1);
84+
assert.notEqual(html.indexOf("id=\"operations-\\/test-impossible\""), -1);
16185
});
16286

163-
it('should not leak package.json', function(done) {
164-
sitepage.open('http://localhost:3001/api-docs/package.json')
165-
.then(() => sitepage.evaluate(function () { return document.querySelector('body').innerText }))
166-
.then(body => {
167-
assert.equal('Not Found', body);
168-
done()
169-
})
170-
.catch(function(err) {
171-
done(err);
172-
});
87+
it('should not leak package.json', async function() {
88+
await sitepage.goto('http://localhost:3001/api-docs/package.json');
89+
const body = await sitepage.evaluate(() => document.querySelector('body').innerText);
90+
assert.equal('Not Found', body);
17391
});
174-
});
92+
});

‎test/testapp/app.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ app.get('/bar', function(req, res) { res.json({ status: 'OKISH'}); });
4747
app.use('/api-docs', swaggerUi.serve)
4848
app.get('/api-docs', swaggerUi.setup(swaggerDocument, false, options, '.swagger-ui .topbar { background-color: red }'));
4949

50+
app.use('/api-docs-one', swaggerUi.serve, swaggerUi.setup(swaggerDocument, false, options, '.swagger-ui .topbar { background-color: red }'))
51+
5052
app.use('/api-docs-from-url', swaggerUi.serve)
5153
app.get('/api-docs-from-url', swaggerUi.setup(null, false, options, '.swagger-ui .topbar { background-color: red }', null, '/swagger.json'));
5254

@@ -81,7 +83,7 @@ app.get('/api-docs-with-null', swaggerUi.setup(swaggerDocument, null, options, '
8183
app.use('/api-docs-split', swaggerUi.serve)
8284
app.get('/api-docs-split', swaggerUi.setup(swaggerDocumentSplit, null, options, '.swagger-ui .topbar { background-color: orange }'));
8385

84-
app.use('/api-docs-with-opts/', swaggerUi.serveWithOptions({ redirect: false }))
86+
app.use('/api-docs-with-opts/', swaggerUi.serveWithOptions({ redirect: false, cacheControl: false }))
8587
app.get('/api-docs-with-opts/', swaggerUi.setup(swaggerDocumentSplit, null, options, '.swagger-ui .topbar { background-color: orange }'));
8688

8789
var swaggerHtml = swaggerUi.generateHTML(swaggerDocument, swaggerUiOpts)

0 commit comments

Comments
 (0)
Please sign in to comment.