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