This commit is contained in:
tamaina
2023-05-22 05:20:19 +00:00
parent 86f4e206f4
commit 1b6ac7888b
10 changed files with 68 additions and 51 deletions

View File

@@ -7,6 +7,7 @@ type TODO = Record<string, any>;
// NOTE: 極力この型を使うのは避け、UserLite か UserDetailed か明示するように
export type User = Packed<'User'>;
export type UserLite = Packed<'UserLite'>;
export type UserDetailed = Packed<'UserDetailed'>;
export type UserList = Packed<'UserList'>;

View File

@@ -35,6 +35,7 @@ import { packedEmojiDetailedSchema, packedEmojiSimpleSchema } from './schemas/em
import { packedFlashSchema } from './schemas/flash.js';
import { packedAdSchema } from './schemas/ad.js';
import { packedAnnouncementSchema } from './schemas/announcement.js';
import { Error, ApiError } from './schemas/error.js';
import type { JSONSchema7, JSONSchema7Definition, GetDef, GetRefs, GetKeys, UnionToArray } from 'schema-type';
export const refs = {
@@ -74,6 +75,9 @@ export const refs = {
Flash: packedFlashSchema,
Ad: packedAdSchema,
Announcement: packedAnnouncementSchema,
Error: Error,
ApiError: ApiError,
} as const satisfies { [x: string]: JSONSchema7Definition };
export type References = GetRefs<typeof refs>;

View File

@@ -17,6 +17,6 @@ export const packedBlockingSchema = {
'id',
'createdAt',
'blockeeId',
'blockee',
//'blockee',
],
} as const satisfies JSONSchema7Definition;

View File

@@ -0,0 +1,34 @@
import type { JSONSchema7Definition } from 'schema-type';
export const Error = {
$id: 'https://misskey-hub.net/api/schemas/Error',
type: 'object',
description: 'An error object.',
properties: {
code: {
type: 'string',
description: 'An error code. Unique within the endpoint.',
},
message: {
type: 'string',
description: 'An error message.',
},
id: {
type: 'string',
format: 'uuid',
description: 'An error ID. This ID is static.',
},
},
required: ['code', 'id', 'message'],
} as const satisfies JSONSchema7Definition;
export const ApiError = {
$id: 'https://misskey-hub.net/api/schemas/ApiError',
type: 'object',
properties: {
error: { $ref: 'https://misskey-hub.net/api/schemas/Error' },
},
required: ['error'],
} as const satisfies JSONSchema7Definition;

View File

@@ -97,4 +97,8 @@ describe('schemas', () => {
test('ad', () => {
type Ad = Packed<'Ad'>;
});
test('error', () => {
type Error = Packed<'Error'>;
type ApiError = Packed<'ApiError'>;
});
});

View File

@@ -20,7 +20,7 @@ describe('schemas', () => {
}
});
test('jointed schema (oneOf)', () => {
test('jointed schema', () => {
const req = getEndpointSchema('req', key as keyof Endpoints);
if (req) ajv.compile(req);
});