Skip to content

Commit e6da89f

Browse files
authored
Removed all cached schemas (#94)
* Removed all cached schemas * Updated test
1 parent a763b6c commit e6da89f

File tree

2 files changed

+54
-5
lines changed

2 files changed

+54
-5
lines changed

index.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -802,11 +802,7 @@ function isValidSchema (schema, externalSchema) {
802802
})
803803
}
804804
ajv.compile(schema)
805-
if (externalSchema) {
806-
Object.keys(externalSchema).forEach(key => {
807-
ajv.removeSchema(key)
808-
})
809-
}
805+
ajv.removeSchema()
810806
}
811807

812808
module.exports = build

test/clean-cache.test.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
'use strict'
2+
3+
const test = require('tap').test
4+
const build = require('..')
5+
6+
test('Should clean the cache', (t) => {
7+
t.plan(1)
8+
9+
const schema = {
10+
$id: 'test',
11+
type: 'string'
12+
}
13+
14+
try {
15+
build(schema)
16+
build(schema)
17+
t.pass()
18+
} catch (err) {
19+
t.fail(err)
20+
}
21+
})
22+
23+
test('Should clean the cache with external schemas', (t) => {
24+
t.plan(1)
25+
26+
const schema = {
27+
$id: 'test',
28+
definitions: {
29+
def: {
30+
type: 'object',
31+
properties: {
32+
str: {
33+
type: 'string'
34+
}
35+
}
36+
}
37+
},
38+
type: 'object',
39+
properties: {
40+
obj: {
41+
$ref: '#/definitions/def'
42+
}
43+
}
44+
}
45+
46+
try {
47+
build(schema)
48+
build(schema)
49+
t.pass()
50+
} catch (err) {
51+
t.fail(err)
52+
}
53+
})

0 commit comments

Comments
 (0)