Comments (8)
Thanks for the report, that should fail and we'll take a look.
from dredd.
Here is a very simple sample that demonstrates the problem that I am having:
https://github.com/mgaut72/dredd_incorrect_schema_validation
from dredd.
@mgaut72 Can definitely reproduce this locally. Validation is handled by gavel which in turn calls amanda for schema validations.
Just a note for investigating this issue:
- Type validation is handled here
- And in particular the isNumber method (which should be called)
Haven't yet installed gavel and amanda locally to figure out exactly where this issue is happening, but the test project definitely helps.
from dredd.
I just did a quick test, and it also turns out that if you set the schema to
...
"token": {
"type":"string",
"required":flase
}
...
then omit the token part of the response in api.py, the dredd test still fails, saying that "token is required".
I know nothing about your codebase, nor about coffeescript, but this line, taken completely out of context, seems of interest?
expected['schema'] = response['schema'] if response['schema']
perhaps response['schema'] is false-y, and gavel is taking to determining what the schema is based on parsing the expected response body?
from dredd.
I get this output when running with -d
expected:
headers:
Content-Type: application/json
body:
{
"data": {
"token": "234khsdfs9d8fsdf",
"expires": 1424641830
}
}
status: 200
schema:
{
"type": "object",
"required": true,
"properties": {
"data": {
"type": "object",
"required": true,
"properties": {
"expires": {
"type": "number",
"required": true
},
"token": {
"type": "string",
"required": true
}
}
}
}
}
Which suggests that the expected['schema']
is getting set (it would be blank otherwise). Just to be safe, I added:
expected['schema'] = response['schema'] if response['schema']
if response['schema']
console.log 'Schema is truthy'
and got this output:
info: Beginning Dredd testing...
Schema is truthy
So it was a good thought, but it doesn't appear that's the issue...I also tried printing transaction.expected
right before it gets passed to gavel.isValid
, and it's definitely the right schema there. That leads me to believe it's something in gavel, since Amanda looks like it's handling numbers properly at first glance.
from dredd.
@ecordell should I move this over to the gavel.js issues, or how should this proceed?
from dredd.
I have the same problem and by looking at both Dredd and Gavel it seems there is a mismatch between the domain model for the expected request/response in Gavel (in http-response-test.coffee and sampleHttpResponseSchema in fixtures.coffee) with what Dredd (in execute-transaction.coffee) sends to Gavel.
It seems like the gavel model has an 'expected' object as part of the expected http response and the schema should be set on the inner expected object vs the top level object.
Any chance to get someone to try to match them?
from dredd.
Looking into this and @fdragu is indeed right! There is a domain model mismatch between what Gavel.js expects and what is Dredd feeding in:
Gavel's input from Dredd (the expected
value in this call:
gavel.isValid real, expected, 'response', (error, isValid) ->`
)
is:
{ headers: { 'Content-Type': 'application/json' },
body: '{\n "data": {\n "token": "234khsdfs9d8fsdf",\n "expires": 1424641830\n }\n}\n',
status: '200',
schema: '{\n "type":"object",\n "required":true,\n "properties":{\n "data": {\n "type":"object",\n "required":true,\n "properties":{\n "expires": {\n "type":"number",\n "required":true\n },\n "token": {\n "type":"string",\n "required":true\n }\n }\n }\n }\n}\n' }
However Gavel.js expects (and takes) this:
{ statusCode: undefined,
statusMessage: undefined,
headers: { 'Content-Type': 'application/json' },
body: '{\n "data": {\n "token": "234khsdfs9d8fsdf",\n "expires": 1424641830\n }\n}\n',
headersSchema: undefined,
bodySchema: undefined }
I will fix it.
from dredd.
Related Issues (20)
- Package dependency triggers NPM advisory (1179) HOT 5
- [Question] How to send form-data (not file, it's string)? HOT 1
- Skipped tests when using square brackets in get parameter name HOT 5
- Package dependency triggers NPM advisory (1696) HOT 1
- [Suggestion] Add timeout
- vulnerability CVE-2020-7598 is introduced by package minimist HOT 1
- dredd init fails when travis ci integration is requested HOT 1
- API description parser error
- oneOf doesn't work as expected
- [Question] Is it possible to split hooks.js?
- Update latest image on Dockerhub
- Add the ability to issue warnings instead of errors for hyphens in Openapi request parameters.
- Dredd doesn't make consistency check between OpenAPI schema and example
- Improved documentation for running dredd in CI / docker
- Empty body with x-www-form-urlencoded
- Multiple status code exclusion in if statement in webhook
- Issues on Paramaeters Example with Swagger.JSON
- Request library is deprecated
- Head type requests not working
- Is `dredd` dead? Please don't abandon this amazing project! HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dredd.