2023-07-27 00:31:52 -05:00
|
|
|
/*
|
2024-02-13 09:59:27 -06:00
|
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 00:31:52 -05:00
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2023-02-25 20:28:05 -06:00
|
|
|
import Ajv from 'ajv';
|
2024-03-06 18:51:57 -06:00
|
|
|
import { Schema } from '@/misc/json-schema.js';
|
2023-02-25 20:28:05 -06:00
|
|
|
|
|
|
|
export const getValidator = (paramDef: Schema) => {
|
2024-03-06 18:51:57 -06:00
|
|
|
const ajv = new Ajv.default({
|
2023-07-27 00:31:52 -05:00
|
|
|
useDefaults: true,
|
|
|
|
});
|
|
|
|
ajv.addFormat('misskey:id', /^[a-zA-Z0-9]+$/);
|
2023-02-25 20:28:05 -06:00
|
|
|
|
2023-07-27 00:31:52 -05:00
|
|
|
return ajv.compile(paramDef);
|
|
|
|
};
|