Skip to content

Commit

Permalink
Bumped version of swagger-ui-dist and moved js template usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephen Scott committed Dec 1, 2021
1 parent ff10df4 commit aa3d56a
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 145 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ var htmlTplString = `
<title><% title %></title>
<link rel="stylesheet" type="text/css" href="./swagger-ui.css" >
<% favIconString %>
<% customJs %>
<style>
html
{
Expand Down Expand Up @@ -78,6 +77,7 @@ var htmlTplString = `
<script src="./swagger-ui-bundle.js"> </script>
<script src="./swagger-ui-standalone-preset.js"> </script>
<script src="./swagger-ui-init.js"> </script>
<% customJs %>
<% customCssUrl %>
<style>
<% customCss %>
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "swagger-ui-express",
"version": "4.1.6",
"version": "4.2.0",
"description": "Swagger UI Express",
"main": "./index.js",
"files": [
Expand Down Expand Up @@ -33,7 +33,7 @@
"istanbul-badges-readme": "^1.2.0",
"mocha": "2.2.5",
"nyc": "^15.1.0",
"phantom": "2.1.21"
"puppeteer": "5.3.1"
},
"author": {
"name": "Stephen Scott",
Expand All @@ -50,7 +50,7 @@
},
"homepage": "https://github.com/scottie1984/swagger-ui-express",
"dependencies": {
"swagger-ui-dist": "^3.52.5"
"swagger-ui-dist": ">3.52.5"
},
"peerDependencies": {
"express": ">=4.0.0"
Expand Down
198 changes: 58 additions & 140 deletions test/test.spec.js
Original file line number Diff line number Diff line change
@@ -1,174 +1,92 @@
var assert = require('assert');
var app = require('./testapp/app');
var http = require('http');
var phantom = require('phantom');
const assert = require('assert');
const app = require('./testapp/app');
const puppeteer = require('puppeteer');
require('es6-shim');

describe('integration', function() {
var server;
var browser = null;
var sitepage = null;
var phInstance = null;

before(function(done) {
app.set('port', 3001);

server = app.listen(app.get('port'), function() {
done();
});
});

after(function() {
after(async function() {
server.close();
sitepage.close();
phInstance.exit();
await sitepage.close();
await browser.close();
});

it('should have API Documentation hosted at /api-docs', function(done) {
it('should intialize browser', async function() {
this.timeout(30000);
phantom.create()
.then(function(instance) {
phInstance = instance;
return instance.createPage();
})
.then(function(page) {
sitepage = page;
return page.open('http://localhost:3001/api-docs/');
})
.then(function(status) {
setTimeout(function() {
assert.equal('success', status);
done();
}, 100);
})
.catch(function(err) {
done(err);
});
browser = await puppeteer.launch();
sitepage = await browser.newPage();
});

it('should have API Documentation hosted at /api-docs', async function() {
const httpResponse = await sitepage.goto('http://localhost:3001/api-docs/');
assert.ok(httpResponse.ok());
});

it('should contain the expected elements on the page', function(done) {
sitepage.property('title')
.then(function(title) {
assert.equal('Swagger UI', title);
return sitepage.evaluate(function() {
return document.querySelector('.swagger-ui').innerHTML;
});
})
.then(function(html) {
assert.ok(html);
assert.notEqual(html.indexOf('id="operations-/test-index"'), -1);
assert.notEqual(html.indexOf('id="operations-/test-impossible"'), -1);
done();
})
.catch(function(err) {
done(err);
});
it('should contain the expected elements on the page from /api-docs', async function() {
await sitepage.waitForSelector('.information-container', { timeout: 2000 });
assert.equal('Swagger UI', await sitepage.title());
const html = await sitepage.evaluate(() => document.querySelector('.swagger-ui').innerHTML);
assert.ok(html);
assert.notEqual(html.indexOf("id=\"operations-\\/test-index\""), -1);
assert.notEqual(html.indexOf("id=\"operations-\\/test-impossible\""), -1);
});

it('should have API Documentation hosted at /api-docs-from-url', function(done) {
sitepage.open('http://localhost:3001/api-docs-from-url/')
.then(function(status) {
setTimeout(function() {
assert.equal('success', status);
done();
}, 100);
})
.catch(function(err) {
done(err);
});
it('should have API Documentation hosted at /api-docs-from-url', async function() {
const httpResponse = await sitepage.goto('http://localhost:3001/api-docs-from-url/');
assert.ok(httpResponse.ok());
});

it('should contain the expected elements on the page', function(done) {
sitepage.property('title')
.then(function(title) {
assert.equal('Swagger UI', title);
return sitepage.evaluate(function() {
return document.querySelector('.swagger-ui').innerHTML;
});
})
.then(function(html) {
assert.ok(html);
assert.notEqual(html.indexOf('id="operations-/test-index"'), -1);
assert.notEqual(html.indexOf('id="operations-/test-impossible"'), -1);
done();
})
.catch(function(err) {
done(err);
});
it('should contain the expected elements on the page from /api-docs-from-url', async function() {
await sitepage.waitForSelector('.information-container', { timeout: 2000 });
assert.equal('Swagger UI', await sitepage.title());
const html = await sitepage.evaluate(() => document.querySelector('.swagger-ui').innerHTML);
assert.ok(html);
// console.log(`**** ${html}`);
assert.notEqual(html.indexOf("id=\"operations-\\/test-index\""), -1);
assert.notEqual(html.indexOf("id=\"operations-\\/test-impossible\""), -1);
});

it('should have API Documentation hosted at /api-docs-using-object', function(done) {
sitepage.open('http://localhost:3001/api-docs-using-object/')
.then(function(status) {
setTimeout(function() {
assert.equal('success', status);
done();
}, 100);
})
.catch(function(err) {
done(err);
});
it('should have API Documentation hosted at /api-docs-using-object', async function() {
const httpResponse = await sitepage.goto('http://localhost:3001/api-docs-using-object/');
assert.ok(httpResponse.ok());
});

it('should contain the expected elements on the page for api-docs-using-object', function(done) {
sitepage.property('title')
.then(function(title) {
assert.equal('Swagger UI', title);
return sitepage.evaluate(function() {
return document.querySelector('.swagger-ui').innerHTML;
});
})
.then(function(html) {
assert.ok(html);
assert.notEqual(html.indexOf('id="operations-/test-index"'), -1);
assert.notEqual(html.indexOf('id="operations-/test-impossible"'), -1);
done();
})
.catch(function(err) {
done(err);
});
it('should contain the expected elements on the page for api-docs-using-object', async function() {
await sitepage.waitForSelector('.information-container', { timeout: 2000 });
assert.equal('Swagger UI', await sitepage.title());
const html = await sitepage.evaluate(() => document.querySelector('.swagger-ui').innerHTML);
assert.ok(html);
assert.notEqual(html.indexOf("id=\"operations-\\/test-index\""), -1);
assert.notEqual(html.indexOf("id=\"operations-\\/test-impossible\""), -1);
});

it('should have API Documentation hosted at /api-docs-with-null', function(done) {
sitepage.open('http://localhost:3001/api-docs-with-null/')
.then(function(status) {
setTimeout(function() {
assert.equal('success', status);
done();
}, 100);
})
.catch(function(err) {
done(err);
});
it('should have API Documentation hosted at /api-docs-with-null', async function() {
const httpResponse = await sitepage.goto('http://localhost:3001/api-docs-with-null/');
assert.ok(httpResponse.ok());
});

it('should contain the expected elements on the page for api-docs-with-null', function(done) {
sitepage.property('title')
.then(function(title) {
assert.equal('Swagger UI', title);
return sitepage.evaluate(function() {
return document.querySelector('.swagger-ui').innerHTML;
});
})
.then(function(html) {
assert.ok(html);
assert.notEqual(html.indexOf('id="operations-/test-index"'), -1);
assert.notEqual(html.indexOf('id="operations-/test-impossible"'), -1);
done();
})
.catch(function(err) {
done(err);
});
it('should contain the expected elements on the page for api-docs-with-null', async function() {
await sitepage.waitForSelector('.information-container', { timeout: 2000 });
assert.equal('Swagger UI', await sitepage.title());
const html = await sitepage.evaluate(() => document.querySelector('.swagger-ui').innerHTML);
assert.ok(html);
assert.notEqual(html.indexOf("id=\"operations-\\/test-index\""), -1);
assert.notEqual(html.indexOf("id=\"operations-\\/test-impossible\""), -1);
});

it('should not leak package.json', function(done) {
sitepage.open('http://localhost:3001/api-docs/package.json')
.then(() => sitepage.evaluate(function () { return document.querySelector('body').innerText }))
.then(body => {
assert.equal('Not Found', body);
done()
})
.catch(function(err) {
done(err);
});
it('should not leak package.json', async function() {
await sitepage.goto('http://localhost:3001/api-docs/package.json');
const body = await sitepage.evaluate(() => document.querySelector('body').innerText);
assert.equal('Not Found', body);
});
});
});
4 changes: 3 additions & 1 deletion test/testapp/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ app.get('/bar', function(req, res) { res.json({ status: 'OKISH'}); });
app.use('/api-docs', swaggerUi.serve)
app.get('/api-docs', swaggerUi.setup(swaggerDocument, false, options, '.swagger-ui .topbar { background-color: red }'));

app.use('/api-docs-one', swaggerUi.serve, swaggerUi.setup(swaggerDocument, false, options, '.swagger-ui .topbar { background-color: red }'))

app.use('/api-docs-from-url', swaggerUi.serve)
app.get('/api-docs-from-url', swaggerUi.setup(null, false, options, '.swagger-ui .topbar { background-color: red }', null, '/swagger.json'));

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

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

var swaggerHtml = swaggerUi.generateHTML(swaggerDocument, swaggerUiOpts)
Expand Down

0 comments on commit aa3d56a

Please sign in to comment.