Skip to content

Commit

Permalink
Includes .schema.json in the filter
Browse files Browse the repository at this point in the history
  • Loading branch information
dalcib committed Apr 12, 2021
1 parent 84b1fdd commit a5c1674
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ By default, this plugin only compiles ["secure" schemas][secure]. This can be di

### `filter`

By default, only files with a `.schema` extension are compiled. If you have different requirements you can pass a Regexp to `filter` for the plugin to use.
By default, files with a `.schema` or a `.schema.json` extension are compiled. If you have different requirements you can pass a Regexp to `filter` for the plugin to use.

### `addFormats`

Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const ajvSecure = new Ajv({ strictTypes: false })
const isSchemaSecure = ajvSecure.compile(require('ajv/lib/refs/json-schema-secure.json'))

module.exports = ({
filter = /\.schema$/,
filter = /\.schema$|\.schema\.json$/,
secure = true,
addFormats = true,
ajvOptions = {}
Expand Down
3 changes: 3 additions & 0 deletions test/ext.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const isNumber = require('./ext.schema.json')

console.log(isNumber(1))
3 changes: 3 additions & 0 deletions test/ext.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "number"
}
17 changes: 17 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,23 @@ tape.test('using custom matcher', function (t) {
})
})

tape.test('using .schema.json extension', function (t) {
bundle('ext.js', {}, function (err, src) {
if (err) {
t.fail(err)
}

vm.runInNewContext(src, {
console: { log: log }
})

function log (value) {
t.equal(value, true, 'passes')
t.end()
}
})
})

tape.test('secure schema by default', function (t) {
bundle('insecure.schema', {}, function (err, src) {
t.ok(err, 'does not compile insecure schema')
Expand Down

0 comments on commit a5c1674

Please sign in to comment.