(
subPath: string,
predicate: (schema: JsonSchema, rootSchema: JsonSchema) => boolean
)
| 135 | |
| 136 | export const schemaSubPathMatches = |
| 137 | ( |
| 138 | subPath: string, |
| 139 | predicate: (schema: JsonSchema, rootSchema: JsonSchema) => boolean |
| 140 | ): Tester => |
| 141 | ( |
| 142 | uischema: UISchemaElement, |
| 143 | schema: JsonSchema, |
| 144 | context: TesterContext |
| 145 | ): boolean => { |
| 146 | if (isEmpty(uischema) || !isControl(uischema)) { |
| 147 | return false; |
| 148 | } |
| 149 | const schemaPath = uischema.scope; |
| 150 | let currentDataSchema: JsonSchema = schema; |
| 151 | if (hasType(schema, 'object')) { |
| 152 | currentDataSchema = resolveSchema( |
| 153 | schema, |
| 154 | schemaPath, |
| 155 | context?.rootSchema |
| 156 | ); |
| 157 | } |
| 158 | currentDataSchema = get(currentDataSchema, subPath); |
| 159 | |
| 160 | if (currentDataSchema === undefined) { |
| 161 | return false; |
| 162 | } |
| 163 | |
| 164 | return predicate(currentDataSchema, context?.rootSchema); |
| 165 | }; |
| 166 | |
| 167 | /** |
| 168 | * Only applicable for Controls. |
no test coverage detected
searching dependent graphs…