( key: string, value: JsonSchema, )
| 113 | * Recursively validate $.properties |
| 114 | */ |
| 115 | const validateProperty = ( |
| 116 | key: string, |
| 117 | value: JsonSchema, |
| 118 | ): ValidationError[] => { |
| 119 | let errors: ValidationError[] = []; |
| 120 | try { |
| 121 | validatePropertyName(key); |
| 122 | } catch (error) { |
| 123 | if (error instanceof Error) { |
| 124 | errors.push({ |
| 125 | path: `${key}`, |
| 126 | error: error.message, |
| 127 | }); |
| 128 | } else { |
| 129 | throw error; |
| 130 | } |
| 131 | } |
| 132 | if (value && typeof value === "object" && "properties" in value) { |
| 133 | const properties = (value.properties as Record<string, JsonSchema>) || {}; |
| 134 | |
| 135 | errors = errors.concat( |
| 136 | Object.keys(properties) |
| 137 | .map((key) => { |
| 138 | return validateProperty(key, properties[key]); |
| 139 | }) |
| 140 | .flat(), |
| 141 | ); |
| 142 | } |
| 143 | |
| 144 | return errors; |
| 145 | }; |
| 146 | |
| 147 | /* |
| 148 | * Accepts an AJV compilation error and extracts the error details from the message. |
no test coverage detected