You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

validators.ts 857B

123456789101112131415161718192021222324252627
  1. import type { Schema } from 'jsonschema'
  2. import { Validator } from 'jsonschema'
  3. import draft07Schema from './draft-07.json'
  4. const validator = new Validator()
  5. export const draft07Validator = (schema: any) => {
  6. return validator.validate(schema, draft07Schema as unknown as Schema)
  7. }
  8. export const forbidBooleanProperties = (schema: any, path: string[] = []): string[] => {
  9. let errors: string[] = []
  10. if (schema && typeof schema === 'object' && schema.properties) {
  11. for (const [key, val] of Object.entries(schema.properties)) {
  12. if (typeof val === 'boolean') {
  13. errors.push(
  14. `Error: Property '${[...path, key].join('.')}' must not be a boolean schema`,
  15. )
  16. }
  17. else if (typeof val === 'object') {
  18. errors = errors.concat(forbidBooleanProperties(val, [...path, key]))
  19. }
  20. }
  21. }
  22. return errors
  23. }