fix
This commit is contained in:
parent
619b4fdf52
commit
22adc78906
|
@ -3,6 +3,8 @@
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import type { SomeJTDSchemaType } from 'ajv/dist/core.js';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
packedMeDetailedOnlySchema,
|
packedMeDetailedOnlySchema,
|
||||||
packedMeDetailedSchema,
|
packedMeDetailedSchema,
|
||||||
|
@ -134,19 +136,19 @@ type StringDefToType<T extends TypeStringef> =
|
||||||
any;
|
any;
|
||||||
|
|
||||||
// https://swagger.io/specification/?sbsearch=optional#schema-object
|
// https://swagger.io/specification/?sbsearch=optional#schema-object
|
||||||
type OfSchema = {
|
type OfSchema<T> = {
|
||||||
readonly anyOf?: ReadonlyArray<Schema>;
|
readonly anyOf?: ReadonlyArray<T>;
|
||||||
readonly oneOf?: ReadonlyArray<Schema>;
|
readonly oneOf?: ReadonlyArray<T>;
|
||||||
readonly allOf?: ReadonlyArray<Schema>;
|
readonly allOf?: ReadonlyArray<T>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Schema extends OfSchema {
|
interface SchemaFactory<T> extends OfSchema<T> {
|
||||||
readonly type?: TypeStringef;
|
readonly type?: TypeStringef;
|
||||||
readonly nullable?: boolean;
|
readonly nullable?: boolean;
|
||||||
readonly optional?: boolean;
|
readonly optional?: boolean;
|
||||||
readonly prefixItems?: ReadonlyArray<Schema>;
|
readonly prefixItems?: ReadonlyArray<T>;
|
||||||
readonly items?: Schema;
|
readonly items?: T;
|
||||||
readonly unevaluatedItems?: Schema | boolean;
|
readonly unevaluatedItems?: T | boolean;
|
||||||
readonly properties?: Obj;
|
readonly properties?: Obj;
|
||||||
readonly required?: ReadonlyArray<Extract<keyof NonNullable<this['properties']>, string>>;
|
readonly required?: ReadonlyArray<Extract<keyof NonNullable<this['properties']>, string>>;
|
||||||
readonly description?: string;
|
readonly description?: string;
|
||||||
|
@ -163,6 +165,10 @@ export interface Schema extends OfSchema {
|
||||||
readonly pattern?: string;
|
readonly pattern?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type Schema = SchemaFactory<Schema>;
|
||||||
|
|
||||||
|
export type ValidatableSchema = SchemaFactory<Schema & SomeJTDSchemaType> & SomeJTDSchemaType;
|
||||||
|
|
||||||
type RequiredPropertyNames<s extends Obj> = {
|
type RequiredPropertyNames<s extends Obj> = {
|
||||||
[K in keyof s]:
|
[K in keyof s]:
|
||||||
// K is not optional
|
// K is not optional
|
||||||
|
@ -229,7 +235,7 @@ export type SchemaTypeDef<p extends Schema> =
|
||||||
p['type'] extends 'boolean' ? boolean :
|
p['type'] extends 'boolean' ? boolean :
|
||||||
p['type'] extends 'object' ? ObjectSchemaTypeDef<p> :
|
p['type'] extends 'object' ? ObjectSchemaTypeDef<p> :
|
||||||
p['type'] extends 'array' ? (
|
p['type'] extends 'array' ? (
|
||||||
p['items'] extends OfSchema ? (
|
p['items'] extends OfSchema<p> ? (
|
||||||
p['items']['anyOf'] extends ReadonlyArray<Schema> ? UnionSchemaType<NonNullable<p['items']['anyOf']>>[] :
|
p['items']['anyOf'] extends ReadonlyArray<Schema> ? UnionSchemaType<NonNullable<p['items']['anyOf']>>[] :
|
||||||
p['items']['oneOf'] extends ReadonlyArray<Schema> ? ArrayUnion<UnionSchemaType<NonNullable<p['items']['oneOf']>>> :
|
p['items']['oneOf'] extends ReadonlyArray<Schema> ? ArrayUnion<UnionSchemaType<NonNullable<p['items']['oneOf']>>> :
|
||||||
p['items']['allOf'] extends ReadonlyArray<Schema> ? UnionToIntersection<UnionSchemaType<NonNullable<p['items']['allOf']>>>[] :
|
p['items']['allOf'] extends ReadonlyArray<Schema> ? UnionToIntersection<UnionSchemaType<NonNullable<p['items']['allOf']>>>[] :
|
||||||
|
|
|
@ -4,7 +4,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { permissions } from 'misskey-js';
|
import { permissions } from 'misskey-js';
|
||||||
import type { KeyOf, Schema } from '@/misc/json-schema.js';
|
import type { ApiErrorInput } from '@/server/api/error.js';
|
||||||
|
import type { KeyOf, ValidatableSchema } from '@/misc/json-schema.js';
|
||||||
|
|
||||||
import * as ep___admin_abuseReport_notificationRecipient_list
|
import * as ep___admin_abuseReport_notificationRecipient_list
|
||||||
from '@/server/api/endpoints/admin/abuse-report/notification-recipient/list.js';
|
from '@/server/api/endpoints/admin/abuse-report/notification-recipient/list.js';
|
||||||
|
@ -780,14 +781,10 @@ interface IEndpointMetaBase {
|
||||||
readonly tags?: ReadonlyArray<string>;
|
readonly tags?: ReadonlyArray<string>;
|
||||||
|
|
||||||
readonly errors?: {
|
readonly errors?: {
|
||||||
readonly [key: string]: {
|
readonly [key: string]: ApiErrorInput;
|
||||||
readonly message: string;
|
|
||||||
readonly code: string;
|
|
||||||
readonly id: string;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
readonly res?: Schema;
|
readonly res?: ValidatableSchema;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* このエンドポイントにリクエストするのにユーザー情報が必須か否か
|
* このエンドポイントにリクエストするのにユーザー情報が必須か否か
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
import { Inject, Injectable } from '@nestjs/common';
|
import { Inject, Injectable } from '@nestjs/common';
|
||||||
import { Endpoint } from '@/server/api/endpoint-base.js';
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
||||||
import type { IEndpointMeta } from '@/server/api/endpoints.js';
|
import type { IEndpointMeta } from '@/server/api/endpoints.js';
|
||||||
import type { Schema } from '@/misc/json-schema.js';
|
import type { Schema, ValidatableSchema } from '@/misc/json-schema.js';
|
||||||
import type { AppsRepository } from '@/models/_.js';
|
import type { AppsRepository } from '@/models/_.js';
|
||||||
import { IdService } from '@/core/IdService.js';
|
import { IdService } from '@/core/IdService.js';
|
||||||
import { unique } from '@/misc/prelude/array.js';
|
import { unique } from '@/misc/prelude/array.js';
|
||||||
|
@ -37,7 +37,7 @@ export const paramDef = {
|
||||||
callbackUrl: { type: 'string', nullable: true },
|
callbackUrl: { type: 'string', nullable: true },
|
||||||
},
|
},
|
||||||
required: ['name', 'description', 'permission'],
|
required: ['name', 'description', 'permission'],
|
||||||
} as const satisfies Schema;
|
} as const satisfies ValidatableSchema;
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export
|
export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
|
|
||||||
type E = { message: string, code: string, id: string, kind?: 'client' | 'server' | 'permission', httpStatusCode?: number };
|
export type ApiErrorInput = { message: string, code: string, id: string, kind?: 'client' | 'server' | 'permission', httpStatusCode?: number };
|
||||||
|
|
||||||
export class ApiError extends Error {
|
export class ApiError extends Error {
|
||||||
public message: string;
|
public message: string;
|
||||||
|
@ -13,7 +13,7 @@ export class ApiError extends Error {
|
||||||
public httpStatusCode?: number;
|
public httpStatusCode?: number;
|
||||||
public info?: any;
|
public info?: any;
|
||||||
|
|
||||||
constructor(err?: E | null | undefined, info?: any | null | undefined) {
|
constructor(err?: ApiErrorInput | null | undefined, info?: any | null | undefined) {
|
||||||
if (err == null) err = {
|
if (err == null) err = {
|
||||||
message: 'Internal error occurred. Please contact us if the error persists.',
|
message: 'Internal error occurred. Please contact us if the error persists.',
|
||||||
code: 'INTERNAL_ERROR',
|
code: 'INTERNAL_ERROR',
|
||||||
|
|
Loading…
Reference in New Issue