swagger-ui-express
Advanced tools
Comparing version 4.0.2 to 4.0.3
13
index.js
@@ -16,2 +16,3 @@ 'use strict' | ||
var swaggerUrls | ||
var customCssUrl | ||
if (opts && typeof opts === 'object') { | ||
@@ -25,3 +26,4 @@ options = opts.swaggerOptions | ||
isExplorer = opts.explorer || !!swaggerUrls | ||
customeSiteTitle = opts.customSiteTitle | ||
customeSiteTitle = opts.customSiteTitle, | ||
customCssUrl = opts.customCssUrl | ||
} else { | ||
@@ -36,3 +38,3 @@ //support legacy params based function | ||
customeSiteTitle = customeSiteTitle || 'Swagger UI'; | ||
var html = fs.readFileSync(__dirname + '/indexTemplate.html'); | ||
var html = fs.readFileSync(__dirname + '/indexTemplate.html.tpl'); | ||
try { | ||
@@ -48,2 +50,3 @@ fs.unlinkSync(__dirname + '/index.html'); | ||
var htmlWithCustomJs = htmlWithFavIcon.replace('<% customJs %>', customJs ? `<script src="${customJs}"></script>` : ''); | ||
var htmlWithCustomCssUrl = htmlWithCustomJs.replace('<% customCssUrl %>', customCssUrl ? `<link href="${customCssUrl}" rel="stylesheet">` : ''); | ||
@@ -56,5 +59,5 @@ var initOptions = { | ||
} | ||
var js = fs.readFileSync(__dirname + '/swagger-ui-init.js'); | ||
var js = fs.readFileSync(__dirname + '/swagger-ui-init.js.tpl'); | ||
swaggerInit = js.toString().replace('<% swaggerOptions %>', stringify(initOptions)) | ||
return htmlWithCustomJs.replace('<% title %>', customeSiteTitle) | ||
return htmlWithCustomCssUrl.replace('<% title %>', customeSiteTitle) | ||
} | ||
@@ -77,3 +80,3 @@ | ||
var swaggerInitFunction = function (swaggerDoc, opts) { | ||
var js = fs.readFileSync(__dirname + '/swagger-ui-init.js'); | ||
var js = fs.readFileSync(__dirname + '/swagger-ui-init.js.tpl'); | ||
var swaggerInitFile = js.toString().replace('<% swaggerOptions %>', stringify(opts)) | ||
@@ -80,0 +83,0 @@ return function (req, res, next) { |
{ | ||
"name": "swagger-ui-express", | ||
"version": "4.0.2", | ||
"version": "4.0.3", | ||
"description": "Swagger UI Express", | ||
@@ -9,4 +9,4 @@ "main": "./lib/index.js", | ||
"index.js", | ||
"indexTemplate.html", | ||
"swagger-ui-init.js", | ||
"indexTemplate.html.tpl", | ||
"swagger-ui-init.js.tpl", | ||
"LICENSE" | ||
@@ -13,0 +13,0 @@ ], |
@@ -62,3 +62,3 @@ # Swagger UI Express | ||
var options = { | ||
explorer : true | ||
explorer: true | ||
}; | ||
@@ -80,4 +80,4 @@ | ||
var options = { | ||
swaggerOptions: { | ||
validatorUrl : null | ||
swaggerOptions: { | ||
validatorUrl: null | ||
} | ||
@@ -108,6 +108,22 @@ }; | ||
### Custom CSS styles from Url | ||
You can also pass the url to a custom css file, the value must be the public url of the file and can be relative or absolute to the swagger path. | ||
```javascript | ||
const express = require('express'); | ||
const app = express(); | ||
const swaggerUi = require('swagger-ui-express'); | ||
const swaggerDocument = require('./swagger.json'); | ||
var options = { | ||
customCssUrl: '/custom.css' | ||
}; | ||
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument, options)); | ||
``` | ||
### Custom JS | ||
If you would like to have full control over your HTML you can provide your own javascript file, value accepts absolute or relative path | ||
If you would like to have full control over your HTML you can provide your own javascript file, value accepts absolute or relative path. Value must be the public url of the js file. | ||
@@ -136,4 +152,2 @@ ```javascript | ||
const swaggerDocument = require('./swagger.json'); | ||
var options = { | ||
@@ -148,3 +162,3 @@ swaggerUrl: 'http://petstore.swagger.io/v2/swagger.json' | ||
To load your swagger specification yaml file you need to use a module able to convert yaml to json ; for instance `yamljs`. | ||
To load your swagger specification yaml file you need to use a module able to convert yaml to json; for instance `yamljs`. | ||
@@ -163,3 +177,2 @@ npm install --save yamljs | ||
## Requirements | ||
@@ -172,4 +185,4 @@ | ||
Install phantom | ||
npm install | ||
npm test | ||
* Install phantom | ||
* `npm install` | ||
* `npm test` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16000
182
118