MCPcopy Create free account
hub / github.com/Writesonic/GPTRouter / validateData

Function validateData

src/utils/schemaValidator.ts:11–25  ·  view source on GitHub ↗
(schema: TObject, data: any)

Source from the content-addressed store, hash-verified

9 * @throws {Error} - If the data does not match the schema
10 */
11export const validateData = <T>(schema: TObject, data: any): T => {
12 const C = TypeCompiler.Compile(schema);
13 // remove extra fields from data
14 const properties = schema.properties;
15 for (const key in data) {
16 if (data.hasOwnProperty(key) && !properties?.[key]) {
17 delete data[key];
18 }
19 }
20 const isValid = C.Check(data);
21 if (isValid) {
22 return data as T;
23 }
24 throw new Error(JSON.stringify([...C.Errors(data)].map(({ path, message }) => ({ path, message }))));
25};

Callers 6

validateParamsMethod · 0.90
validateParamsMethod · 0.90
validateParamsMethod · 0.90
validateParamsMethod · 0.90
validateParamsMethod · 0.90
validateParamsMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected