-
Notifications
You must be signed in to change notification settings - Fork 280
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1622 from apiaryio/update-gavel
Updates Gavel for JSON Schema Draft 6/7 support
- Loading branch information
Showing
6 changed files
with
173 additions
and
7 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
21 changes: 21 additions & 0 deletions
21
packages/dredd/test/fixtures/json-schema-draft-7-boolean.apib
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,21 @@ | ||
FORMAT: 1A | ||
|
||
# Machines API | ||
|
||
# Group Machines | ||
|
||
# Machines collection [/machines/{id}] | ||
+ Parameters | ||
+ id: 1 (number) | ||
|
||
## Get Machines [GET] | ||
|
||
+ Request (application/json) | ||
+ Parameters | ||
+ id: 2 (number) | ||
|
||
+ Response 200 (application/json; charset=utf-8) | ||
|
||
+ Schema | ||
|
||
true |
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,32 @@ | ||
FORMAT: 1A | ||
|
||
# Machines API | ||
|
||
# Group Machines | ||
|
||
# Machines collection [/machines] | ||
|
||
## Get Machines [GET] | ||
|
||
- Response 200 (application/json; charset=utf-8) | ||
|
||
+ Schema | ||
|
||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"type": "array", | ||
"items": { | ||
"type": "object", | ||
"properties": { | ||
"type": { | ||
"type": "string", | ||
"const": "bulldozer" | ||
}, | ||
"name": { | ||
"not": { | ||
"type": "number" | ||
} | ||
} | ||
} | ||
} | ||
} |
112 changes: 112 additions & 0 deletions
112
packages/dredd/test/integration/json-schema-draft-7-test.js
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,112 @@ | ||
import { assert } from 'chai'; | ||
|
||
import Dredd from '../../lib/Dredd'; | ||
import { runDreddWithServer, createServer } from './helpers'; | ||
|
||
describe('Given API Blueprint with JSON Schema Draft 7', () => { | ||
describe('given explicit version of JSON Schema', () => { | ||
const FIXTURE_PATH = './test/fixtures/json-schema-draft-7.apib'; | ||
|
||
describe('given actual data matches the schema', () => { | ||
let runtimeInfo; | ||
|
||
before((done) => { | ||
const app = createServer(); | ||
app.get('/machines', (req, res) => { | ||
res.json([{ type: 'bulldozer', name: 'willy' }]); | ||
}); | ||
|
||
const dredd = new Dredd({ | ||
path: FIXTURE_PATH, | ||
}); | ||
|
||
runDreddWithServer(dredd, app, (error, info) => { | ||
runtimeInfo = info; | ||
done(error); | ||
}); | ||
}); | ||
|
||
it('should output no failures or errors', () => { | ||
assert.equal( | ||
runtimeInfo.dredd.stats.failures + runtimeInfo.dredd.stats.errors, | ||
0, | ||
); | ||
}); | ||
|
||
it('should result into passing test', () => { | ||
assert.equal(runtimeInfo.dredd.stats.passes, 1); | ||
}); | ||
}); | ||
|
||
describe('given actual data does not match the schema', () => { | ||
let runtimeInfo; | ||
|
||
before((done) => { | ||
const app = createServer(); | ||
app.get('/machines', (req, res) => { | ||
res.json([{ type: 'unknown', name: 'willy' }]); | ||
}); | ||
|
||
const dredd = new Dredd({ | ||
path: FIXTURE_PATH, | ||
}); | ||
|
||
runDreddWithServer(dredd, app, (error, info) => { | ||
runtimeInfo = info; | ||
done(error); | ||
}); | ||
}); | ||
|
||
it('should result into 1 failing test', () => { | ||
assert.equal(runtimeInfo.dredd.stats.failures, 1); | ||
}); | ||
|
||
it('should output an error about unknown "type" enum value', () => { | ||
assert.match( | ||
runtimeInfo.dredd.logging, | ||
/data\/0\/type should be equal to constant/, | ||
); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('given a single Boolean value as a JSON Schema', () => { | ||
const FIXTURE_PATH = './test/fixtures/json-schema-draft-7-boolean.apib'; | ||
|
||
describe('given schema equals "true"', () => { | ||
let runtimeInfo; | ||
|
||
before((done) => { | ||
const app = createServer(); | ||
app.get('/machines/:id', (req, res) => { | ||
const { id } = req.params; | ||
const machines = [{ type: 'bulldozer', name: 'willy' }]; | ||
res.json(machines[id] || {}); | ||
}); | ||
|
||
const dredd = new Dredd({ | ||
path: FIXTURE_PATH, | ||
}); | ||
|
||
runDreddWithServer(dredd, app, (error, info) => { | ||
runtimeInfo = info; | ||
done(error); | ||
}); | ||
}); | ||
|
||
it('should recognize schema as Draft 7', () => { | ||
// No invalid schema version error from Gavel and no failing tests | ||
// implies the schema version was properly inferred as Draft 7. | ||
assert.notMatch(runtimeInfo.dredd.logging, /not a valid draft/); | ||
assert.equal( | ||
runtimeInfo.dredd.stats.failures + runtimeInfo.dredd.stats.errors, | ||
0, | ||
); | ||
}); | ||
|
||
it('should always result into passing test', () => { | ||
assert.equal(runtimeInfo.dredd.stats.passes, 1); | ||
}); | ||
}); | ||
}); | ||
}); |
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