1 | import type {AnySchemaObject} from "../../types"
|
2 | import type {SchemaObjCxt} from ".."
|
3 | import type {JSONType, RuleGroup, Rule} from "../rules"
|
4 |
|
5 | export function schemaHasRulesForType(
|
6 | {schema, self}: SchemaObjCxt,
|
7 | type: JSONType
|
8 | ): boolean | undefined {
|
9 | const group = self.RULES.types[type]
|
10 | return group && group !== true && shouldUseGroup(schema, group)
|
11 | }
|
12 |
|
13 | export function shouldUseGroup(schema: AnySchemaObject, group: RuleGroup): boolean {
|
14 | return group.rules.some((rule) => shouldUseRule(schema, rule))
|
15 | }
|
16 |
|
17 | export function shouldUseRule(schema: AnySchemaObject, rule: Rule): boolean | undefined {
|
18 | return (
|
19 | schema[rule.keyword] !== undefined ||
|
20 | rule.definition.implements?.some((kwd) => schema[kwd] !== undefined)
|
21 | )
|
22 | }
|