Skip to content

Commit

Permalink
Merge pull request #45 from appersonlabs/master
Browse files Browse the repository at this point in the history
Add support for custom params on the OPERATION OBJECT
  • Loading branch information
z0mt3c committed Aug 29, 2015
2 parents 0aa08c5 + 87647da commit 1bdda1f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/resources.js
Expand Up @@ -196,6 +196,10 @@ module.exports = function (settings, routes, tags) {
operation.deprecated = true
}

if (routesPluginOptions.custom) {
operation = _.merge(operation, routesPluginOptions.custom)
}

utils.setNotEmpty(operation, 'tags', internals.prepareTags(path, routeSettings.tags, settings))
utils.setNotEmpty(operation, 'parameters', parameters)
utils.setNotEmpty(operation, 'summary', routeSettings.description)
Expand Down
3 changes: 2 additions & 1 deletion lib/schema.js
Expand Up @@ -132,7 +132,7 @@ schemas.Operation = Joi.object({
schemes: arrayOfStrings.optional(),
deprecated: Joi.boolean().optional(),
security: Joi.any()
}).meta({
}).pattern(/^x-[A-Za-z]*-?[A-Za-z]*/, Joi.string().optional()).meta({
className: 'Operation'
})

Expand Down Expand Up @@ -306,5 +306,6 @@ schemas.RoutesPluginOptions = Joi.object({
description: Joi.string().required(),
schema: Joi.object().optional()
})),
custom: Joi.object().pattern(/^x-[A-Za-z]*-?[A-Za-z]*/, Joi.string().required()),
operationId: Joi.string().optional()
}).optional()
24 changes: 24 additions & 0 deletions test/resources-test.js
Expand Up @@ -141,6 +141,30 @@ describe('resources', function () {
})
})

describe('custom params', function () {
it('allows params that start with x-', function (done) {
var resources = internals.resources(Hoek.applyToDefaults(baseRoute, {
path: '/foo',
config: {
plugins: {
'hapi-swaggered': {
custom: {
'x-test-foo': 'test value'
}
}
}
}
}))

expect(resources).to.exist()
expect(resources.paths['/foo'].get).to.include({
'x-test-foo': 'test value'
})

done()
})
})

describe('responses', function () {
// TODO: description, test with primary types + arrays
it('only response model', function (done) {
Expand Down

0 comments on commit 1bdda1f

Please sign in to comment.