Ajvに怒られて起動できなかったところを修正
This commit is contained in:
parent
058ccb94ab
commit
508e18cf2a
|
|
@ -9,6 +9,7 @@ import type { Schema, SchemaType } from '@/misc/json-schema.js';
|
|||
import type { MiLocalUser } from '@/models/User.js';
|
||||
import type { MiAccessToken } from '@/models/AccessToken.js';
|
||||
import { ApiError } from './error.js';
|
||||
import { omitAjvNotSupportProperty } from './openapi/schemas.js';
|
||||
import type { IEndpointMeta } from './endpoints.js';
|
||||
|
||||
const Ajv = _Ajv.default;
|
||||
|
|
@ -35,7 +36,8 @@ export abstract class Endpoint<T extends IEndpointMeta, Ps extends Schema> {
|
|||
public exec: (params: any, user: T['requireCredential'] extends true ? MiLocalUser : MiLocalUser | null, token: MiAccessToken | null, file?: File, ip?: string | null, headers?: Record<string, string> | null) => Promise<any>;
|
||||
|
||||
constructor(meta: T, paramDef: Ps, cb: Executor<T, Ps>) {
|
||||
const validate = ajv.compile(paramDef);
|
||||
const ajvSchema = omitAjvNotSupportProperty(paramDef);
|
||||
const validate = ajv.compile(ajvSchema);
|
||||
|
||||
this.exec = (params: any, user: T['requireCredential'] extends true ? MiLocalUser : MiLocalUser | null, token: MiAccessToken | null, file?: File, ip?: string | null, headers?: Record<string, string> | null) => {
|
||||
let cleanup: undefined | (() => void) = undefined;
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ export const paramDef = {
|
|||
offset: { type: 'integer', default: 0 },
|
||||
sort: {
|
||||
type: 'string',
|
||||
optional: true, nullable: true,
|
||||
nullable: true,
|
||||
enum: [
|
||||
'+pubSub',
|
||||
'-pubSub',
|
||||
|
|
|
|||
|
|
@ -43,6 +43,19 @@ export function convertSchemaToOpenApiSchema(schema: Schema) {
|
|||
return res;
|
||||
}
|
||||
|
||||
export function omitAjvNotSupportProperty(schema: Schema): Schema {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const { optional, ref, ...res } = JSON.parse(JSON.stringify(schema)) as Schema;
|
||||
|
||||
if (res.type === 'object' && res.properties) {
|
||||
for (const k of Object.keys(res.properties)) {
|
||||
res.properties[k] = omitAjvNotSupportProperty(res.properties[k]);
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
export const schemas = {
|
||||
Error: {
|
||||
type: 'object',
|
||||
|
|
|
|||
Loading…
Reference in New Issue