Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow select keyword #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/util/schema-validator.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
/* @flow */
import ajv from "ajv"
import keywordSwitch from "ajv-keywords/keywords/switch"
import keywordSelect from "ajv-keywords/keywords/select"

export function validate(schema: Object, body: mixed) {
const validator = ajv({
allErrors: true,
v5: true,
$data: true,
})

keywordSwitch(validator)
keywordSelect(validator)

if (validator.validate(schema, body)) return []
const validate = validator.compile(schema)
if (validate(body)) return []

const grouped = new Map
for (const error of validator.errors) {
Expand Down