Skip to content

Commit

Permalink
Add definitions models support (#73)
Browse files Browse the repository at this point in the history
* Add definitions models support

* Add test for definitions. Add it to swaggerInfo and additional assert to "fastify.swagger basic properties" test

* Move defenitions test to separeted test block
  • Loading branch information
heyas authored and mcollina committed May 19, 2018
1 parent b1282dd commit b22ddc6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
2 changes: 2 additions & 0 deletions dynamic.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module.exports = function (fastify, opts, next) {
const schemes = opts.swagger.schemes || null
const consumes = opts.swagger.consumes || null
const produces = opts.swagger.produces || null
const definitions = opts.swagger.definitions || null
const basePath = opts.swagger.basePath || null
const securityDefinitions = opts.swagger.securityDefinitions || null
const security = opts.swagger.security || null
Expand Down Expand Up @@ -69,6 +70,7 @@ module.exports = function (fastify, opts, next) {
if (basePath) swaggerObject.basePath = basePath
if (consumes) swaggerObject.consumes = consumes
if (produces) swaggerObject.produces = produces
if (definitions) swaggerObject.definitions = definitions
if (securityDefinitions) {
swaggerObject.securityDefinitions = securityDefinitions
}
Expand Down
37 changes: 36 additions & 1 deletion test/swagger.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ test('fastify.swagger basic properties', t => {
t.error(err)

const swaggerObject = fastify.swagger()

t.equal(swaggerObject.info, swaggerInfo.swagger.info)
t.equal(swaggerObject.host, swaggerInfo.swagger.host)
t.equal(swaggerObject.schemes, swaggerInfo.swagger.schemes)
Expand All @@ -288,6 +287,42 @@ test('fastify.swagger basic properties', t => {
})
})

test('fastify.swagger definitions', t => {
t.plan(2)
const fastify = Fastify()

fastify.register(fastifySwagger, swaggerInfo)

const opts = {
schema: {
definitions: {
'ExampleModel': {
'type': 'object',
'properties': {
'id': {
'type': 'integer',
'description': 'Some id'
},
'name': {
'type': 'string',
'description': 'Name of smthng'
}
}
}
}
}
}

fastify.get('/', opts, () => {})

fastify.ready(err => {
t.error(err)

const swaggerObject = fastify.swagger()
t.equal(swaggerObject.definitions, swaggerInfo.swagger.definitions)
})
})

test('hide support', t => {
t.plan(2)
const fastify = Fastify()
Expand Down

0 comments on commit b22ddc6

Please sign in to comment.