2019-04-23 13:35:26 +00:00
|
|
|
import { packedUserSchema } from '../../../models/repositories/user';
|
2021-03-23 08:43:07 +00:00
|
|
|
import { Schema } from '@/misc/schema';
|
2019-04-23 13:35:26 +00:00
|
|
|
import { packedNoteSchema } from '../../../models/repositories/note';
|
|
|
|
import { packedUserListSchema } from '../../../models/repositories/user-list';
|
|
|
|
import { packedAppSchema } from '../../../models/repositories/app';
|
|
|
|
import { packedMessagingMessageSchema } from '../../../models/repositories/messaging-message';
|
|
|
|
import { packedNotificationSchema } from '../../../models/repositories/notification';
|
|
|
|
import { packedDriveFileSchema } from '../../../models/repositories/drive-file';
|
|
|
|
import { packedDriveFolderSchema } from '../../../models/repositories/drive-folder';
|
|
|
|
import { packedFollowingSchema } from '../../../models/repositories/following';
|
|
|
|
import { packedMutingSchema } from '../../../models/repositories/muting';
|
|
|
|
import { packedBlockingSchema } from '../../../models/repositories/blocking';
|
|
|
|
import { packedNoteReactionSchema } from '../../../models/repositories/note-reaction';
|
2019-04-25 04:25:10 +00:00
|
|
|
import { packedHashtagSchema } from '../../../models/repositories/hashtag';
|
2019-04-30 19:44:46 +00:00
|
|
|
import { packedPageSchema } from '../../../models/repositories/page';
|
2019-05-18 11:36:33 +00:00
|
|
|
import { packedUserGroupSchema } from '../../../models/repositories/user-group';
|
2019-05-20 13:01:32 +00:00
|
|
|
import { packedNoteFavoriteSchema } from '../../../models/repositories/note-favorite';
|
2020-08-21 19:25:47 +00:00
|
|
|
import { packedChannelSchema } from '../../../models/repositories/channel';
|
2021-03-06 13:34:11 +00:00
|
|
|
import { packedAntennaSchema } from '../../../models/repositories/antenna';
|
|
|
|
import { packedClipSchema } from '../../../models/repositories/clip';
|
|
|
|
import { packedFederationInstanceSchema } from '../../../models/repositories/federation-instance';
|
|
|
|
import { packedQueueCountSchema } from '../../../models/repositories/queue';
|
2019-04-23 13:35:26 +00:00
|
|
|
|
|
|
|
export function convertSchemaToOpenApiSchema(schema: Schema) {
|
|
|
|
const res: any = schema;
|
|
|
|
|
|
|
|
if (schema.type === 'object' && schema.properties) {
|
2019-05-05 00:27:55 +00:00
|
|
|
res.required = Object.entries(schema.properties).filter(([k, v]) => !v.optional).map(([k]) => k);
|
2019-04-23 13:35:26 +00:00
|
|
|
|
|
|
|
for (const k of Object.keys(schema.properties)) {
|
|
|
|
res.properties[k] = convertSchemaToOpenApiSchema(schema.properties[k]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (schema.type === 'array' && schema.items) {
|
|
|
|
res.items = convertSchemaToOpenApiSchema(schema.items);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (schema.ref) {
|
|
|
|
res.$ref = `#/components/schemas/${schema.ref}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2019-02-23 19:08:08 +00:00
|
|
|
export const schemas = {
|
|
|
|
Error: {
|
|
|
|
type: 'object',
|
|
|
|
properties: {
|
|
|
|
error: {
|
|
|
|
type: 'object',
|
|
|
|
description: 'An error object.',
|
|
|
|
properties: {
|
|
|
|
code: {
|
|
|
|
type: 'string',
|
2019-02-23 19:27:09 +00:00
|
|
|
description: 'An error code. Unique within the endpoint.',
|
2019-02-23 19:08:08 +00:00
|
|
|
},
|
|
|
|
message: {
|
|
|
|
type: 'string',
|
|
|
|
description: 'An error message.',
|
|
|
|
},
|
|
|
|
id: {
|
|
|
|
type: 'string',
|
|
|
|
format: 'uuid',
|
|
|
|
description: 'An error ID. This ID is static.',
|
|
|
|
}
|
|
|
|
},
|
|
|
|
required: ['code', 'id', 'message']
|
|
|
|
},
|
|
|
|
},
|
|
|
|
required: ['error']
|
|
|
|
},
|
|
|
|
|
2019-04-23 13:35:26 +00:00
|
|
|
User: convertSchemaToOpenApiSchema(packedUserSchema),
|
|
|
|
UserList: convertSchemaToOpenApiSchema(packedUserListSchema),
|
2019-05-18 11:36:33 +00:00
|
|
|
UserGroup: convertSchemaToOpenApiSchema(packedUserGroupSchema),
|
2019-04-23 13:35:26 +00:00
|
|
|
App: convertSchemaToOpenApiSchema(packedAppSchema),
|
|
|
|
MessagingMessage: convertSchemaToOpenApiSchema(packedMessagingMessageSchema),
|
|
|
|
Note: convertSchemaToOpenApiSchema(packedNoteSchema),
|
2019-05-20 13:01:32 +00:00
|
|
|
NoteReaction: convertSchemaToOpenApiSchema(packedNoteReactionSchema),
|
|
|
|
NoteFavorite: convertSchemaToOpenApiSchema(packedNoteFavoriteSchema),
|
2019-04-23 13:35:26 +00:00
|
|
|
Notification: convertSchemaToOpenApiSchema(packedNotificationSchema),
|
|
|
|
DriveFile: convertSchemaToOpenApiSchema(packedDriveFileSchema),
|
|
|
|
DriveFolder: convertSchemaToOpenApiSchema(packedDriveFolderSchema),
|
|
|
|
Following: convertSchemaToOpenApiSchema(packedFollowingSchema),
|
|
|
|
Muting: convertSchemaToOpenApiSchema(packedMutingSchema),
|
|
|
|
Blocking: convertSchemaToOpenApiSchema(packedBlockingSchema),
|
2019-04-25 04:25:10 +00:00
|
|
|
Hashtag: convertSchemaToOpenApiSchema(packedHashtagSchema),
|
2019-04-30 19:44:46 +00:00
|
|
|
Page: convertSchemaToOpenApiSchema(packedPageSchema),
|
2020-08-21 19:25:47 +00:00
|
|
|
Channel: convertSchemaToOpenApiSchema(packedChannelSchema),
|
2021-03-06 13:34:11 +00:00
|
|
|
QueueCount: convertSchemaToOpenApiSchema(packedQueueCountSchema),
|
|
|
|
Antenna: convertSchemaToOpenApiSchema(packedAntennaSchema),
|
|
|
|
Clip: convertSchemaToOpenApiSchema(packedClipSchema),
|
|
|
|
FederationInstance: convertSchemaToOpenApiSchema(packedFederationInstanceSchema),
|
2019-02-23 19:08:08 +00:00
|
|
|
};
|