Skip to content

Commit

Permalink
Merge branch 'dev' into master; tag v0.17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Harvey committed Jan 25, 2021
2 parents 21244dd + 1074f2e commit e246fa6
Show file tree
Hide file tree
Showing 22 changed files with 1,753 additions and 610 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,29 @@ async function run() {
console.error(err.details) // more json-schema specifics; see <https://github.com/epoberezkin/ajv#validation-errors>
}


// example 2: require a package
const me = require('./me.json')
console.log(await sdoValidate(me, 'Person')) // return `true` if the document passes validation


// example 3: use a string (relative path) of the filename
const org = './my-org.jsonld'
console.log(await sdoValidate(org, 'Organization')) // return `true` if the document passes validation


// example 4: infer the schema from the `'@type'` property
await sdoValidate(school) // validates against the `Place` schema, since `school['@type'] === 'Place'`


// example 5: multiple types
const business = {
'@context': 'http://schema.org/',
'@type': ['Place', 'LocalBusiness'],
}
await sdoValidate(business) // validates against all schemata in the array


// example 6: default type is `Thing` (http://schema.org/Thing)
await sdoValidate({
'@context': 'http://schema.org/',
Expand All @@ -62,6 +67,13 @@ async function run() {
'@context': 'http://schema.org/',
// validates against the `Thing` schema, since property '@type' is missing
})


// example 7: pass options object to Ajv constructor
// (see https://github.com/ajv-validator/ajv/blob/master/docs/api.md#options)
await sdoValiate(data, type, {
strict: true,
});
}
```

Expand Down
51 changes: 26 additions & 25 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
const fs = require('fs')
const path = require('path')
const url = require('url')

const gulp = require('gulp')
const mocha = require('gulp-mocha');
const typedoc = require('gulp-typedoc')
const typescript = require('gulp-typescript')
const Ajv = require('ajv')
const {default: Ajv} = require('ajv');
// require('ts-node') // DO NOT REMOVE … peerDependency of `gulp-mocha`
// require('typedoc') // DO NOT REMOVE … peerDependency of `gulp-typedoc`
// require('typescript') // DO NOT REMOVE … peerDependency of `gulp-typescript`

const tsconfig = require('./tsconfig.json')


function dist_index() {
return gulp.src('./src/{index,build}.ts')
return gulp.src('./src/{index,build,sdo-ld}.ts')
.pipe(typescript(tsconfig.compilerOptions))
.pipe(gulp.dest('./dist/'))
}

async function validate() {
const sdo_jsd = require('./index.js')
new Ajv()
new Ajv({
strictTuples: false,
})
.addMetaSchema(await sdo_jsd.META_SCHEMATA)
.addSchema(await sdo_jsd.JSONLD_SCHEMA)
.addSchema(await sdo_jsd.SCHEMATA)
Expand All @@ -36,19 +39,12 @@ async function dist() {
])
}

async function test() {
const sdo_jsd = require('./index.js')
return Promise.all((await fs.promises.readdir('./test')).map(async (file) => {
const filepath = path.resolve(__dirname, './test/', file)
let returned;
try {
returned = await sdo_jsd.sdoValidate(filepath)
console.log(`The example ${file} is valid.`)
} catch (e) {
console.error(`The example ${file} failed!`, e.details || e)
}
return returned
}))
function test() {
return gulp.src('./test/**/*.ts')
.pipe(mocha({
require: 'ts-node/register',
}))
;
}

function docs() {
Expand All @@ -59,15 +55,20 @@ function docs() {
const build = gulp.series(
dist_index,
validate,
dist,
gulp.parallel(test, docs)
)
gulp.parallel(
test,
gulp.series(
dist,
docs,
),
),
);

module.exports = {
dist_index,
validate,
dist,
test,
docs,
build,
dist_index,
validate,
test,
dist,
docs,
}
1 change: 1 addition & 0 deletions meta/member.jsd
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"required": ["anyOf"],
"properties": {
"anyOf": {
"minItems": 1,
"maxItems": 2,
"items": [
{ "const": { "$ref": "#/definitions/ExpectedType" } },
Expand Down
Loading

0 comments on commit e246fa6

Please sign in to comment.