Skip to content
This repository has been archived by the owner on Dec 2, 2024. It is now read-only.

Be less restrictive #8

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/generator.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -225,4 +225,4 @@ module.exports = (app, descriptor, resources, options = {}) ->

return res.json(result)

next()
next()
40 changes: 38 additions & 2 deletions test/apiGeneration.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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(), {}, [
Expand Down Expand Up @@ -682,4 +718,4 @@ describe 'API generation tests', ->
nickname: 'remove'
]
]
done()
done()