Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Be less restrictive #8

Closed
wants to merge 4 commits into from

2 participants

Commits on Mar 27, 2013
  1. @Filirom1

    be less restrictive

    Filirom1 authored
Commits on Mar 28, 2013
  1. @Filirom1

    respect coding style

    Filirom1 authored
  2. @Filirom1

    add unit tests

    Filirom1 authored
  3. @Filirom1
This page is out of date. Refresh to see the latest.
Showing with 40 additions and 4 deletions.
  1. +2 −2 src/generator.coffee
  2. +38 −2 test/apiGeneration.coffee
View
4 src/generator.coffee
@@ -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
40 test/apiGeneration.coffee
@@ -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()
Something went wrong with that request. Please try again.