Skip to content

Commit a0f194d

Browse files
committed
security pass-through
1 parent 415c92c commit a0f194d

4 files changed

Lines changed: 26 additions & 3 deletions

File tree

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ This plugin does not include the [swagger-ui](https://github.com/wordnik/swagger
5555
* `cache`: caching options for the swagger schema generation as specified in [`server.method()`](https://github.com/hapijs/hapi/blob/master/API.md#servermethodname-method-options) of hapi, defaults to: `{ expiresIn: 15 * 60 * 1000 }`
5656
* `responseValidation`: boolean, turn response validation on and off for hapi-swaggered routes, defaults to false
5757
* `auth`: authentication configuration [hapijs documentation](https://github.com/hapijs/hapi/blob/master/API.md#route-options) (default to undefined)
58+
* `securityDefinitions`: security definitions according to [swagger specs](https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md]
5859

5960
## Example
6061
Example configuration for hapi-swaggered + hapi-swaggered-ui
@@ -105,7 +106,7 @@ server.route({
105106
path: '/',
106107
method: 'GET',
107108
handler (request, h) {
108-
h.redirect('/docs');
109+
h.response().redirect('/docs');
109110
}
110111
});
111112

@@ -250,6 +251,20 @@ Specify an operationId for a route:
250251
}
251252
```
252253

254+
Specify an security options to a route / operation:
255+
256+
```js
257+
{
258+
options: {
259+
plugins: {
260+
'hapi-swaggered': {
261+
security: {}
262+
}
263+
}
264+
}
265+
}
266+
```
267+
253268
### Tag filtering
254269
Routes can be filtered for tags through the tags query parameter beside the requiredTags property which is always required to be present.
255270

lib/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ function register (plugin, options) {
3737
swagger: SWAGGER_VERSION,
3838
schemes: currentSettings.schemes,
3939
externalDocs: currentSettings.externalDocs,
40+
securityDefinitions: currentSettings.securityDefinitions,
4041
paths: resources.paths,
4142
definitions: resources.definitions,
4243
tags: utils.getTags(currentSettings)

lib/resources.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,10 @@ module.exports = function (settings, routes, tags) {
204204
operation.operationId = routesPluginOptions.operationId
205205
}
206206

207+
if (routesPluginOptions.security != null) {
208+
operation.security = routesPluginOptions.security
209+
}
210+
207211
if (_.includes(routeSettings.tags, 'deprecated')) {
208212
operation.deprecated = true
209213
}

lib/schema.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,8 @@ schemas.Swagger = Joi.object({
240240
// parameters: Joi.array().items(schemas.Parameter, schemas.Reference).optional()
241241
// responses: schemas.Responses,
242242
tags: Joi.array().items(schemas.Tag).optional(),
243-
externalDocs: schemas.ExternalDocs.optional()
243+
externalDocs: schemas.ExternalDocs.optional(),
244+
securityDefinitions: Joi.any().optional()
244245
}).meta({
245246
className: 'Swagger'
246247
})
@@ -267,6 +268,7 @@ schemas.PluginOptions = Joi.object({
267268
cache: Joi.any().optional(),
268269
tags: Joi.alternatives().try(Joi.object().pattern(/.*/, Joi.string()), Joi.array().items(schemas.Tag)),
269270
info: schemas.Info,
271+
securityDefinitions: Joi.any().optional(),
270272
host: Joi.string().optional(),
271273
schemes: Joi.array().items(Joi.string().valid(['http', 'https', 'ws', 'wss'])).optional(),
272274
auth: Joi.alternatives([
@@ -312,5 +314,6 @@ schemas.RoutesPluginOptions = Joi.object({
312314
schema: Joi.object().optional()
313315
})),
314316
custom: Joi.object().pattern(/^x-[A-Za-z]*-?[A-Za-z]*/, Joi.string().required()),
315-
operationId: Joi.string().optional()
317+
operationId: Joi.string().optional(),
318+
security: Joi.any().optional()
316319
}).optional()

0 commit comments

Comments
 (0)