( input: JsonSchemaInput, )
| 71 | * Validate a function schema. |
| 72 | */ |
| 73 | export const validateFunctionSchema = ( |
| 74 | input: JsonSchemaInput, |
| 75 | ): { path: string; error: string }[] => { |
| 76 | delete input.properties?.undefined; |
| 77 | |
| 78 | if (!input || !input.properties) { |
| 79 | return [{ path: "", error: "Schema must be defined" }]; |
| 80 | } |
| 81 | |
| 82 | const errors = Object.keys(input.properties) |
| 83 | .map((key) => { |
| 84 | return validateProperty(key, input.properties[key]); |
| 85 | }) |
| 86 | .flat(); |
| 87 | |
| 88 | if (errors.length > 0) { |
| 89 | return errors; |
| 90 | } |
| 91 | |
| 92 | const ajv = new Ajv(); |
| 93 | addFormats(ajv); |
| 94 | |
| 95 | try { |
| 96 | ajv.compile({ |
| 97 | ...input, |
| 98 | $schema: undefined, |
| 99 | }); |
| 100 | } catch (error) { |
| 101 | if (error instanceof Error) { |
| 102 | return ajvErrorToFailures(error); |
| 103 | } |
| 104 | throw new AgentRPCError("Unknown JSON schema compilation error", { |
| 105 | error, |
| 106 | }); |
| 107 | } |
| 108 | |
| 109 | return []; |
| 110 | }; |
| 111 | |
| 112 | /** |
| 113 | * Recursively validate $.properties |
no test coverage detected