Coder Social home page Coder Social logo

Comments (8)

Almad avatar Almad commented on May 16, 2024

Thanks for the report, that should fail and we'll take a look.

from dredd.

mgaut72 avatar mgaut72 commented on May 16, 2024

Here is a very simple sample that demonstrates the problem that I am having:

https://github.com/mgaut72/dredd_incorrect_schema_validation

from dredd.

ecordell avatar ecordell commented on May 16, 2024

@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.

mgaut72 avatar mgaut72 commented on May 16, 2024

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.

ecordell avatar ecordell commented on May 16, 2024

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.

mgaut72 avatar mgaut72 commented on May 16, 2024

@ecordell should I move this over to the gavel.js issues, or how should this proceed?

from dredd.

fdragu avatar fdragu commented on May 16, 2024

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.

zdne avatar zdne commented on May 16, 2024

@ecordell @mgaut72

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.