Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

Wrong validation error message & wrong error path #840

Closed
basavind opened this issue Aug 3, 2017 · 4 comments
Closed

Wrong validation error message & wrong error path #840

basavind opened this issue Aug 3, 2017 · 4 comments

Comments

@basavind
Copy link

basavind commented Aug 3, 2017

Describe your problem

When I made mistake in my API Blueprint schema (hosted at apiary) and added field twice (also, apiary didn't show duplicate) in data structure which returns in an array of fixed-type in response, Dredd had thrown validation error for not valid JSON Schema draft v4 in response array items but not for field duplicate.

Simple APIB schema for bug reproduction:

# Data Structures

## Struct (object)
+ field (required)
+ field (required)

# test [GET /]

+ Response 200 (application/json)
    + Attributes (object)
        + data (required, array[Struct], fixed-type)

Thrown exception:

fail: body: JSON schema is not valid draft v4! Data does not match any schemas from "anyOf" at path "/properties/data/items"

The problem is in JSON schema generation from given APIB schema, because it adds duplicated field twice in "required array". Generated schema from Dredd details:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "data": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "field": {
            "type": "string"
          }
        },
        "required": [
          "field",
          "field"
        ]
      }
    }
  },
  "required": [
    "data"
  ]
}

What command line options do you use?

$ dredd https://jsapi.apiary.io/apis/test14283.apib http://127.0.0.1:3000

What is in your dredd.yml?

No config file, but with config but still reproduces

What's your dredd --version output?

dredd v4.1.2 (Darwin 16.6.0; x64)

Does dredd --level=debug uncover something?

Nothing unusual.

Can you send us failing test in a Pull Request?

Maybe yes, but not right now. And I don't know where you are testing APIB parsing and generating JSON Schema from it.

@honzajavorek
Copy link
Contributor

@basavind Thanks for filing this! That's amazing bug report. I think the problem is in how drafter is processing MSON. In my opinion it's responsibility of the parser to recognize the duplication, warn user about it and to internally provide JSON Schema with just one occurrance of the field in required. @apiaryio/adt what do you think?

@pksunkara
Copy link
Contributor

@honzajavorek Can you create an issue in drafter repo and link it here? Thanks.

@kylef
Copy link
Member

kylef commented May 24, 2019

apiaryio/drafter#493 has been fixed, @basavind can you please confirm this is working as intended.

@honzajavorek
Copy link
Contributor

Closing. Please comment under this issue or file a new one if the problem persists. Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants