Be less restrictive #8

Closed
wants to merge 4 commits into
from
Jump to file or symbol
Failed to load files and symbols.
+40 −4
Split
View
@@ -74,7 +74,7 @@ validateModel = (model, id, models) ->
# checks that model has an id
if model.id isnt id
throw new Error("model #{id} not declared with the same id")
- unless _.isObject(model.properties) and !_.isEmpty(model.properties)
+ unless !_.isEmpty(model.properties) or model.additionalProperties or !_.isEmpty(model.items)
throw new Error("model #{id} does not declares properties")
if models[id]?
throw new Error("model #{id} has already been defined")
@@ -225,4 +225,4 @@ module.exports = (app, descriptor, resources, options = {}) ->
return res.json(result)
- next()
+ next()
View
@@ -73,7 +73,7 @@ describe 'API generation tests', ->
]
, /Response not declared with the same id/
- it 'should fail on model with invalid id', ->
+ it 'should fail on model without properties', ->
assert.throws ->
swagger.generator express(), {}, [
api:
@@ -84,6 +84,42 @@ describe 'API generation tests', ->
]
, /Response1 does not declares properties/
+ it 'should not fail on model with properties', ->
+ swagger.generator express(), {}, [
+ api:
+ resourcePath: '/test'
+ apis: [path: '/test/1'],
+ models:
+ Response1:
+ id: 'Response1'
+ properties: name: type: 'string'
+ controller: require './fixtures/sourceCrud'
+ ]
+
+ it 'should not fail on model with additionalProperties', ->
+ swagger.generator express(), {}, [
+ api:
+ resourcePath: '/test'
+ apis: [path: '/test/1'],
+ models:
+ Response1:
+ id: 'Response1'
+ additionalProperties: {}
+ controller: require './fixtures/sourceCrud'
+ ]
+
+ it 'should not fail on model with items', ->
+ swagger.generator express(), {}, [
+ api:
+ resourcePath: '/test'
+ apis: [path: '/test/1'],
+ models:
+ Response1:
+ id: 'Response1'
+ items: type: 'string'
+ controller: require './fixtures/sourceCrud'
+ ]
+
it 'should fail on model already defined', ->
assert.throws ->
swagger.generator express(), {}, [
@@ -682,4 +718,4 @@ describe 'API generation tests', ->
nickname: 'remove'
]
]
- done()
+ done()