Dredd/Gavel incorrectly validates response body as valid when a JSON schema contains definitions and $ref
See original GitHub issueI have noticed that dredd incorrectly marks my API responses as valid if I supply a JSON Schema that uses “definitions” as outlined here.
My server is returning the following JSON for a simple GET request:
{
"address": {
"street": "123 Test Street",
"postcode": "12345"
}
}
My API Blueprint has two test cases, one that validates the above JSON against a JSON Schema expecting the “address” object to contain three fields. The second request uses a JSON Schema that extracts the “address” object into a definition and references this with a JSON Pointer.
As expected the first request is failing with message body: At '/address/country' Missing required property: country
. But the second request is happily passing.
# Test Endpoint [/api.php]
Tests the validity of server responses against json-schema.
## Schema with no definitions [GET]
+ Response 200 (application/json; charset=utf-8)
+ Schema
{
"$schema": "http://json-schema.org/draft-04/schema",
"id": "schema-no-definitions",
"type": "object",
"properties": {
"address": {
"type": "object",
"properties": {
"street": {
"type": "string",
"minLength": 1
},
"postcode": {
"type": "string",
"minLength": 1
},
"country": {
"type": "string",
"minLength": 1
}
},
"required": [
"street", "postcode", "country"
]
}
},
"required" : [
"address"
]
}
## Test schema with definitions [GET]
+ Response 200 (application/json; charset=utf-8)
+ Schema
{
"$schema": "http://json-schema.org/draft-04/schema",
"id": "schema-definitions",
"definitions": {
"addressItem": {
"type": "object",
"properties": {
"street": {
"type": "string",
"minLength": 1
},
"postcode": {
"type": "string",
"minLength": 1
},
"country": {
"type": "string",
"minLength": 1
}
},
"required": [
"street", "postcode", "country"
]
}
},
"properties": {
"address": {
"$ref": "#/definitions/addressItem"
}
},
"required" : [
"address"
]
}
Should dredd/Gavel be supporting these JSON Schema features?
Issue Analytics
- State:
- Created 8 years ago
- Comments:10 (6 by maintainers)
Top Results From Across the Web
Json schema validation error - Stack Overflow
Therefore you receive an error about wrong type. JSON schema type MUST be single value or array of such strings: "array","boolean","integer"," ...
Read more >Invalid schema causes "should have required property '$ref ...
When an OpenAPI v3 Response Object contains a schema which has invalid schemas, an error is thrown saying: should have a required $ref...
Read more >Understanding JSON Schema
JSON Schema is a powerful tool for validating the structure of JSON data. However, learning to use it by reading its.
Read more >A Vocabulary for Structural Validation of JSON - JSON Schema
A string instance is valid against this keyword if its length is greater than, or equal to, the value of this keyword. The...
Read more >A Vocabulary for Structural Validation of JSON - JSON Schema
JSON Schema (application/schema+json) has several purposes, one of which is JSON instance validation. This document specifies a vocabulary for JSON Schema ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Does #767 also address this issue for swagger specifications? I would assume so, since I am using swagger 2.0 which utilizes json schema draft 4.
Only asking because I just installed from master and seem to be having this problem still.
EDIT: Scratch that, it was an error on my end where the dredd CLI command was still looking at the build installed from npm. Master seems to be working fine, thank you!
Should be fixed in Dredd v3.4.2.