Skip to content

Commit 2da8e3a

Browse files
committed
Add additional schemas for get resource response and apply response
1 parent 12c1820 commit 2da8e3a

3 files changed

Lines changed: 78 additions & 0 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"$id": "https://www.codify.com/apply-response-data-schema.json",
4+
"title": "Apply Response Schema Data",
5+
"type": "null",
6+
"additionalProperties": false
7+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"$id": "https://www.codify.com/get-resources-response-data-schema.json",
4+
"title": "Get Resources Response Schema Data",
5+
"type": "object",
6+
"properties": {
7+
"resources": {
8+
"type": "array",
9+
"items": {
10+
"type": "object",
11+
"properties": {
12+
"type": {
13+
"$ref": "resource-schema.json#/properties/type"
14+
},
15+
"dependencies": {
16+
"type": "array",
17+
"items": {
18+
"type": "string"
19+
}
20+
}
21+
},
22+
"required": ["type"]
23+
}
24+
}
25+
},
26+
"required": ["resources"],
27+
"additionalProperties": false
28+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import Ajv2020 from "ajv/dist/2020";
2+
import schema from './get-resources-response-data-schema.json';
3+
import resourceSchema from '../resource-schema.json'
4+
import {it} from "mocha";
5+
import assert from "node:assert";
6+
7+
const ajv = new Ajv2020({
8+
strict: true,
9+
})
10+
ajv.addSchema(resourceSchema);
11+
12+
describe('Get resources response data schema', () => {
13+
it('compiles', () => {
14+
ajv.compile(schema);
15+
})
16+
17+
it("requires a type field to be specified", () => {
18+
const validate = ajv.compile(schema);
19+
assert.equal(validate({ resources: [
20+
{
21+
type: "typeA",
22+
dependencies: [
23+
"typeB"
24+
]
25+
},
26+
{
27+
type: "typeB"
28+
}
29+
]}), true)
30+
assert.equal(validate({
31+
resources: [
32+
{
33+
type: "typeA",
34+
dependencies: [
35+
"typeB"
36+
]
37+
},
38+
{}
39+
]
40+
}), false)
41+
})
42+
43+
})

0 commit comments

Comments
 (0)