hapi-swagger
Advanced tools
Comparing version 3.2.0 to 3.3.0
@@ -161,85 +161,2 @@ 'use strict'; | ||
method: 'PUT', | ||
path: '/contenttype/1', | ||
config: { | ||
handler: defaultHandler, | ||
description: 'Add', | ||
tags: ['api'], | ||
plugins: { | ||
'hapi-swagger': { | ||
consumes: ['application/json','application/json;charset=UTF-8','application/json; charset=UTF-8'], | ||
order: 2 | ||
} | ||
}, | ||
validate: { | ||
payload: { | ||
a: Joi.number() | ||
.required() | ||
.description('the first number'), | ||
b: Joi.number() | ||
.required() | ||
.description('the second number') | ||
} | ||
}, | ||
payload:{ | ||
allow: ['application/json','application/json;charset=UTF-8','application/json; charset=UTF-8'] | ||
} | ||
} | ||
},{ | ||
method: 'PUT', | ||
path: '/contenttype/2', | ||
config: { | ||
handler: defaultHandler, | ||
description: 'Add', | ||
tags: ['api'], | ||
plugins: { | ||
'hapi-swagger': { | ||
produces: ['application/json','application/xml'], | ||
order: 1 | ||
} | ||
}, | ||
validate: { | ||
payload: Joi.object({ | ||
a: Joi.number() | ||
.required() | ||
.description('the first number'), | ||
b: Joi.number() | ||
.required() | ||
.description('the second number') | ||
}).label('sum_input') | ||
} | ||
} | ||
},{ | ||
method: 'PUT', | ||
path: '/contenttype/3', | ||
config: { | ||
handler: defaultHandler, | ||
description: 'Add', | ||
tags: ['api'], | ||
plugins: { | ||
'hapi-swagger': { | ||
order: 1 | ||
} | ||
}, | ||
validate: { | ||
payload: { | ||
a: Joi.number() | ||
.required() | ||
.description('the first number'), | ||
b: Joi.number() | ||
.required() | ||
.description('the second number') | ||
}, | ||
headers: Joi.object({ | ||
'content-type': Joi.string().valid([ | ||
'application/json', | ||
'application/json;charset=UTF-8', | ||
'application/json; charset=UTF-8']) | ||
}).unknown() | ||
} | ||
} | ||
},{ | ||
method: 'PUT', | ||
path: '/sum/add/{a}/{b}', | ||
@@ -246,0 +163,0 @@ config: { |
@@ -60,9 +60,2 @@ 'use strict'; | ||
tags: [{ | ||
'name': 'contenttype', | ||
'description': 'temp endpoints for content-type', | ||
'externalDocs': { | ||
'description': 'Find out more', | ||
'url': 'http://example.org' | ||
} | ||
}, { | ||
'name': 'sum', | ||
@@ -100,8 +93,13 @@ 'description': 'working with maths', | ||
}); | ||
server.start(() => { | ||
server.route(Routes); | ||
console.log('server running at:', server.info.uri); | ||
server.start((err) => { | ||
if (err) { | ||
console.log(err); | ||
} else { | ||
console.log('Server running at:', server.info.uri); | ||
} | ||
}); | ||
}); | ||
server.route(Routes); | ||
104
lib/index.js
@@ -51,2 +51,6 @@ 'use strict'; | ||
/** | ||
@@ -61,3 +65,3 @@ * register the plug-in with the Hapi framework | ||
const settings = Hoek.applyToDefaults(defaults, options); | ||
let settings = Hoek.applyToDefaults(defaults, options); | ||
const publicDirPath = __dirname + Path.sep + '..' + Path.sep + 'public'; | ||
@@ -87,59 +91,59 @@ const swaggerDirPath = publicDirPath + Path.sep + 'swaggerui'; | ||
// add routing for swagger ui | ||
// only add 'inert' and 'vision' based routes if needed | ||
if (settings.enableDocumentation === true) { | ||
// There is no way to cover this differs from Hapi 9 to 10+ | ||
/* $lab:coverage:off$ */ | ||
if (plugin.registrations){ | ||
Hoek.assert(plugin.registrations.vision, 'Missing vision plug-in registation'); | ||
Hoek.assert(plugin.registrations.inert, 'Missing inert plug-in registation'); | ||
} | ||
/* $lab:coverage:on$ */ | ||
// make sure we have other plug-in dependencies | ||
plugin.dependency(['inert', 'vision'], (pluginWithDependencies, nextWithDependencies) => { | ||
// add routing for swaggerui static assets /swaggerui/ | ||
plugin.views({ | ||
engines: { | ||
html: { | ||
module: require('handlebars') | ||
// add routing for swaggerui static assets /swaggerui/ | ||
pluginWithDependencies.views({ | ||
engines: { | ||
html: { | ||
module: require('handlebars') | ||
} | ||
}, | ||
path: swaggerDirPath | ||
}); | ||
pluginWithDependencies.route([{ | ||
method: 'GET', | ||
path: settings.documentationPath, | ||
config: { | ||
auth: settings.auth | ||
}, | ||
handler: (request, reply) => { | ||
reply.view('index.html', {}); | ||
} | ||
}, | ||
path: swaggerDirPath | ||
}); | ||
},{ | ||
method: 'GET', | ||
path: settings.swaggerUIPath + '{path*}', | ||
config: { | ||
auth: settings.auth | ||
}, | ||
handler: { | ||
directory: { | ||
path: swaggerDirPath + Path.sep, | ||
listing: true, | ||
index: false | ||
} | ||
} | ||
},{ | ||
method: 'GET', | ||
path: settings.swaggerUIPath + 'extend.js', | ||
config: { | ||
auth: settings.auth | ||
}, | ||
handler: { | ||
file: publicDirPath + Path.sep + 'extend.js' | ||
} | ||
}]); | ||
plugin.route([{ | ||
method: 'GET', | ||
path: settings.documentationPath, | ||
config: { | ||
auth: settings.auth | ||
}, | ||
handler: (request, reply) => { | ||
appendDataContext(pluginWithDependencies, settings); | ||
reply.view('index.html', {}); | ||
} | ||
},{ | ||
method: 'GET', | ||
path: settings.swaggerUIPath + '{path*}', | ||
config: { | ||
auth: settings.auth | ||
}, | ||
handler: { | ||
directory: { | ||
path: swaggerDirPath + Path.sep, | ||
listing: true, | ||
index: false | ||
} | ||
} | ||
},{ | ||
method: 'GET', | ||
path: settings.swaggerUIPath + 'extend.js', | ||
config: { | ||
auth: settings.auth | ||
}, | ||
handler: { | ||
file: publicDirPath + Path.sep + 'extend.js' | ||
} | ||
}]); | ||
nextWithDependencies(); | ||
}); | ||
} | ||
appendDataContext(plugin, settings); | ||
next(); | ||
@@ -146,0 +150,0 @@ }; |
{ | ||
"name": "hapi-swagger", | ||
"description": "A swagger documentation UI generator plugin for hapi", | ||
"version": "3.2.0", | ||
"version": "3.3.0", | ||
"author": "Glenn Jones", | ||
@@ -6,0 +6,0 @@ "repository": { |
@@ -59,4 +59,8 @@ # hapi-swagger | ||
}], (err) => { | ||
server.start( () => { | ||
console.log('Server running at:', server.info.uri); | ||
server.start( (err) => { | ||
if (err) { | ||
console.log(err); | ||
} else { | ||
console.log('Server running at:', server.info.uri); | ||
} | ||
}); | ||
@@ -114,3 +118,2 @@ }); | ||
* `sortEndpoints`: (string) a sort method for endpoints in UI. `path`, `method`, `ordered` | ||
* `sortPaths`: (string) a sort method for `path` objects in JSON. `unsorted` or `path-method` | ||
* `securityDefinitions:`: (array) Containing [Security Definitions Object](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#securityDefinitionsObject). No defaults are provided. | ||
@@ -236,3 +239,3 @@ | ||
## Response Object | ||
HAPI allow you to define a response object for an API endpoint. The response object is used by HAPI to both validation and description the output of an API. It uses the same JOI validation objects to describe the input parameters. The plugin turns these object into visual description and examples in the Swagger UI. | ||
HAPI allow you to define a response object for an API endpoint. The response object is used by HAPI to both validate and describe the output of an API. It uses the same JOI validation objects to describe the input parameters. The plugin turns these object into visual description and examples in the Swagger UI. | ||
@@ -239,0 +242,0 @@ An very simple example of the use of the response object: |
@@ -23,3 +23,2 @@ 'use strict'; | ||
let err = null; | ||
const server = new Hapi.Server(); | ||
@@ -44,2 +43,4 @@ | ||
callback(err, null); | ||
} else { | ||
callback(null, server); | ||
} | ||
@@ -49,3 +50,3 @@ }); | ||
callback(err, server); | ||
}; | ||
@@ -63,3 +64,2 @@ | ||
let err = null; | ||
const server = new Hapi.Server(); | ||
@@ -89,7 +89,10 @@ | ||
callback(err, null); | ||
} else { | ||
callback(null, server); | ||
} | ||
}); | ||
}); | ||
callback(err, server); | ||
}; | ||
@@ -96,0 +99,0 @@ |
@@ -16,3 +16,3 @@ 'use strict'; | ||
lab.experiment('index', () => { | ||
lab.experiment('plugin', () => { | ||
@@ -48,2 +48,4 @@ const routes = [{ | ||
server.start(function (err) { | ||
done(); | ||
}); | ||
@@ -70,2 +72,4 @@ }); | ||
server.start(function (err) { | ||
done(); | ||
}); | ||
@@ -120,7 +124,8 @@ }); | ||
Helper.createServer({}, routes, (err, server) => { | ||
expect(err).to.equal(null); | ||
lab.test('default jsonPath url', (done) => { | ||
lab.test('default jsonPath url', (done) => { | ||
Helper.createServer({}, routes, (err, server) => { | ||
expect(err).to.equal(null); | ||
server.inject({ method: 'GET', url: '/swagger.json' }, function (response) { | ||
@@ -132,5 +137,10 @@ | ||
}); | ||
}); | ||
lab.test('default documentationPath url', (done) => { | ||
lab.test('default documentationPath url', (done) => { | ||
Helper.createServer({}, routes, (err, server) => { | ||
server.inject({ method: 'GET', url: '/documentation' }, function (response) { | ||
@@ -142,5 +152,9 @@ | ||
}); | ||
}); | ||
lab.test('default swaggerUIPath url', (done) => { | ||
lab.test('default swaggerUIPath url', (done) => { | ||
Helper.createServer({}, routes, (err, server) => { | ||
server.inject({ method: 'GET', url: '/swaggerui/swagger-ui.js' }, function (response) { | ||
@@ -152,3 +166,2 @@ | ||
}); | ||
}); | ||
@@ -155,0 +168,0 @@ |
@@ -111,2 +111,3 @@ 'use strict'; | ||
/* These test are no longer needed `sortPaths` is to be deprecate | ||
@@ -119,3 +120,3 @@ lab.test('sort ordered unsorted', (done) => { | ||
//console.log(JSON.stringify(response.result.paths['/a'])); | ||
expect(Object.keys(response.result.paths['/a'])).to.deep.equal(['get', 'post', 'delete']); | ||
expect(Object.keys(response.result.paths['/a'])).to.deep.equal(['post', 'get', 'delete']); | ||
done(); | ||
@@ -125,2 +126,3 @@ }); | ||
}); | ||
*/ | ||
@@ -141,2 +143,3 @@ | ||
}); |
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
538
3728853
44782