This repository has been archived by the owner on May 5, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for invalid body parameter handling.
* body parameters were being modified, making the module non idempotent. * Major refactoring for body param validation was performed.
- Loading branch information
Showing
4 changed files
with
149 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
module.exports = { | ||
validateArgs: { | ||
parameters: [ | ||
{ | ||
in: 'body', | ||
name: 'foo', | ||
required: true, | ||
schema: { | ||
$ref: '#/definitions/Test1' | ||
} | ||
} | ||
], | ||
|
||
schemas: { | ||
Test1: { | ||
properties: { | ||
foo: { | ||
type: 'string' | ||
} | ||
}, | ||
required: ['foo'] | ||
} | ||
} | ||
}, | ||
|
||
requestMethod: 'post', | ||
|
||
requestBody: { | ||
foo: 'asdf' | ||
}, | ||
|
||
path: '', | ||
|
||
statusCode: 200, | ||
|
||
responseBody: '"woot"' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
module.exports = { | ||
validateArgs: { | ||
parameters: [ | ||
{ | ||
in: 'body', | ||
name: 'foo', | ||
required: true, | ||
schema: { | ||
$ref: '#/definitions/Test1' | ||
} | ||
} | ||
], | ||
|
||
schemas: { | ||
Test1: { | ||
properties: { | ||
foo: { | ||
type: 'string' | ||
} | ||
}, | ||
required: ['foo'] | ||
} | ||
} | ||
}, | ||
|
||
requestMethod: 'post', | ||
|
||
requestBody: {}, | ||
|
||
path: '', | ||
|
||
statusCode: 400, | ||
|
||
responseBody: { | ||
'status': 400, | ||
'errors': [ | ||
{ | ||
'path': 'foo', | ||
'errorCode': 'required.openapi.validation', | ||
'message': 'instance requires property "foo"', | ||
'location': 'body' | ||
} | ||
] | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
var expect = require('chai').expect; | ||
var sut = require('../'); | ||
|
||
describe(require('../package.json').name, function() { | ||
it('should not modify the input parameters', function() { | ||
var initialArguments = createArguments(); | ||
sut(initialArguments); | ||
expect(initialArguments).to.eql(createArguments()); | ||
}); | ||
|
||
function createArguments() { | ||
return { | ||
parameters: [ | ||
{ | ||
in: 'body', | ||
name: 'User', | ||
schema: { | ||
$ref: '#/definitions/User' | ||
} | ||
} | ||
], | ||
|
||
schemas: { | ||
User: { | ||
properties: { | ||
name: { | ||
type: 'string' | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
} | ||
}); |