parent
2898add86a
commit
c90c32d62a
|
@ -3,8 +3,6 @@
|
||||||
* 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,
|
||||||
|
@ -136,19 +134,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<T> = {
|
type OfSchema = {
|
||||||
readonly anyOf?: ReadonlyArray<T>;
|
readonly anyOf?: ReadonlyArray<Schema>;
|
||||||
readonly oneOf?: ReadonlyArray<T>;
|
readonly oneOf?: ReadonlyArray<Schema>;
|
||||||
readonly allOf?: ReadonlyArray<T>;
|
readonly allOf?: ReadonlyArray<Schema>;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface SchemaFactory<T> extends OfSchema<T> {
|
export interface Schema extends OfSchema {
|
||||||
readonly type?: TypeStringef;
|
readonly type?: TypeStringef;
|
||||||
readonly nullable?: boolean;
|
readonly nullable?: boolean;
|
||||||
readonly optional?: boolean;
|
readonly optional?: boolean;
|
||||||
readonly prefixItems?: ReadonlyArray<T>;
|
readonly prefixItems?: ReadonlyArray<Schema>;
|
||||||
readonly items?: T;
|
readonly items?: Schema;
|
||||||
readonly unevaluatedItems?: T | boolean;
|
readonly unevaluatedItems?: Schema | 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;
|
||||||
|
@ -165,10 +163,6 @@ interface SchemaFactory<T> extends OfSchema<T> {
|
||||||
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
|
||||||
|
@ -235,7 +229,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> ? (
|
p['items'] extends OfSchema ? (
|
||||||
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,8 +4,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { permissions } from 'misskey-js';
|
import { permissions } from 'misskey-js';
|
||||||
import type { ApiErrorInput } from '@/server/api/error.js';
|
import type { KeyOf, Schema } from '@/misc/json-schema.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';
|
||||||
|
@ -781,10 +780,14 @@ interface IEndpointMetaBase {
|
||||||
readonly tags?: ReadonlyArray<string>;
|
readonly tags?: ReadonlyArray<string>;
|
||||||
|
|
||||||
readonly errors?: {
|
readonly errors?: {
|
||||||
readonly [key: string]: ApiErrorInput;
|
readonly [key: string]: {
|
||||||
|
readonly message: string;
|
||||||
|
readonly code: string;
|
||||||
|
readonly id: string;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
readonly res?: ValidatableSchema;
|
readonly res?: Schema;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* このエンドポイントにリクエストするのにユーザー情報が必須か否か
|
* このエンドポイントにリクエストするのにユーザー情報が必須か否か
|
||||||
|
|
|
@ -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, ValidatableSchema } from '@/misc/json-schema.js';
|
import type { Schema } 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 ValidatableSchema;
|
} as const satisfies Schema;
|
||||||
|
|
||||||
@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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export type ApiErrorInput = { message: string, code: string, id: string, kind?: 'client' | 'server' | 'permission', httpStatusCode?: number };
|
type E = { 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?: ApiErrorInput | null | undefined, info?: any | null | undefined) {
|
constructor(err?: E | 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