Skip to content

Commit

Permalink
v1.2.0:
Browse files Browse the repository at this point in the history
- allow body parameter to be facultative
- fix packaging issues with coffee. Only contributors need to install it globally (as well as mocha)
  • Loading branch information
feugy committed Feb 20, 2013
1 parent b177a9c commit 17c8190
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
-p
test
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,15 @@
"url": "https://github.com/feugy/swagger-jack"
},
"license": "MIT",
"version": "1.1.0",
"version": "1.2.0",
"main": "lib/index.js",
"engines": {
"node": "+0.8.0"
},
"scripts": {
"test": "NODE_ENV=test mocha --compilers coffee:coffee-script -R spec",
"testwin": "(set NODE_ENV=test) & mocha --compilers coffee:coffee-script -R spec",
"preinstall": "npm install -g coffee-script mocha",
"postinstall": "coffee --bare -o lib -c src"
"prepublish": "coffee --bare -o lib -c src"
},
"dependencies": {
"async": "0.1.22",
Expand Down
2 changes: 1 addition & 1 deletion src/validator.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ validate = (req, path, specs, next) ->
if type is 'file'
value = req.files?[spec.name]
# specific case of files: do not validate with json-gate
return done if !(value?) then new Error "#{errPrefix} is required"
return done if !(value?) and spec.schema.schema.required then new Error "#{errPrefix} is required"
else
value = req.body[spec.name]
else
Expand Down
3 changes: 3 additions & 0 deletions test/apiValidation.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,9 @@ describe 'API validation tests', ->
it 'should primitive json body be required', (done) ->
postApi 'singleintbody', {'Content-Type': 'application/json'}, undefined, 400, {message: 'Bad Request'}, done

it 'should body parameter be optionnal', (done) ->
postApi 'optionnalbody', null, undefined, 200, {}, done

it 'should form-encoded body be required', (done) ->
postApi 'multiplebody', {'Content-Type': 'application/x-www-form-urlencoded'}, undefined, 400, {message: 'body parameter param1 is required'}, done

Expand Down
10 changes: 10 additions & 0 deletions test/fixtures/validatedApi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ apis:
paramType: body
required: true

- path: /api/optionnalbody
operations:

- httpMethod: POST
nickname: returnBody
parameters:

- dataType: int
paramType: body

- path: /api/multiplebody
operations:

Expand Down

0 comments on commit 17c8190

Please sign in to comment.