From a78b048720800973925b89455237de5c51bd780c Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 20 May 2019 22:01:32 +0900 Subject: [PATCH] Improve API doc --- src/models/repositories/note-favorite.ts | 31 ++++++++++++++++++++++++ src/server/api/endpoints/i/favorites.ts | 13 +++++++++- src/server/api/openapi/schemas.ts | 4 ++- 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/src/models/repositories/note-favorite.ts b/src/models/repositories/note-favorite.ts index b5875802fb..01064f3065 100644 --- a/src/models/repositories/note-favorite.ts +++ b/src/models/repositories/note-favorite.ts @@ -2,6 +2,7 @@ import { EntityRepository, Repository } from 'typeorm'; import { NoteFavorite } from '../entities/note-favorite'; import { Notes } from '..'; import { ensure } from '../../prelude/ensure'; +import { types, bool } from '../../misc/schema'; @EntityRepository(NoteFavorite) export class NoteFavoriteRepository extends Repository { @@ -26,3 +27,33 @@ export class NoteFavoriteRepository extends Repository { return Promise.all(favorites.map(x => this.pack(x, me))); } } + +export const packedNoteFavoriteSchema = { + type: types.object, + optional: bool.false, nullable: bool.false, + properties: { + id: { + type: types.string, + optional: bool.false, nullable: bool.false, + format: 'id', + description: 'The unique identifier for this favorite.', + example: 'xxxxxxxxxx', + }, + createdAt: { + type: types.string, + optional: bool.false, nullable: bool.false, + format: 'date-time', + description: 'The date that the favorite was created.' + }, + note: { + type: types.object, + optional: bool.false, nullable: bool.false, + ref: 'Note', + }, + noteId: { + type: types.string, + optional: bool.false, nullable: bool.false, + format: 'id', + }, + }, +}; diff --git a/src/server/api/endpoints/i/favorites.ts b/src/server/api/endpoints/i/favorites.ts index aad706545a..d1e90dd15c 100644 --- a/src/server/api/endpoints/i/favorites.ts +++ b/src/server/api/endpoints/i/favorites.ts @@ -3,6 +3,7 @@ import { ID } from '../../../../misc/cafy-id'; import define from '../../define'; import { NoteFavorites } from '../../../../models'; import { makePaginationQuery } from '../../common/make-pagination-query'; +import { types, bool } from '../../../../misc/schema'; export const meta = { desc: { @@ -29,7 +30,17 @@ export const meta = { untilId: { validator: $.optional.type(ID), }, - } + }, + + res: { + type: types.array, + optional: bool.false, nullable: bool.false, + items: { + type: types.object, + optional: bool.false, nullable: bool.false, + ref: 'NoteFavorite', + } + }, }; export default define(meta, async (ps, user) => { diff --git a/src/server/api/openapi/schemas.ts b/src/server/api/openapi/schemas.ts index 32f69bdef3..0a49607f05 100644 --- a/src/server/api/openapi/schemas.ts +++ b/src/server/api/openapi/schemas.ts @@ -14,6 +14,7 @@ import { packedNoteReactionSchema } from '../../../models/repositories/note-reac import { packedHashtagSchema } from '../../../models/repositories/hashtag'; import { packedPageSchema } from '../../../models/repositories/page'; import { packedUserGroupSchema } from '../../../models/repositories/user-group'; +import { packedNoteFavoriteSchema } from '../../../models/repositories/note-favorite'; export function convertSchemaToOpenApiSchema(schema: Schema) { const res: any = schema; @@ -71,13 +72,14 @@ export const schemas = { App: convertSchemaToOpenApiSchema(packedAppSchema), MessagingMessage: convertSchemaToOpenApiSchema(packedMessagingMessageSchema), Note: convertSchemaToOpenApiSchema(packedNoteSchema), + NoteReaction: convertSchemaToOpenApiSchema(packedNoteReactionSchema), + NoteFavorite: convertSchemaToOpenApiSchema(packedNoteFavoriteSchema), Notification: convertSchemaToOpenApiSchema(packedNotificationSchema), DriveFile: convertSchemaToOpenApiSchema(packedDriveFileSchema), DriveFolder: convertSchemaToOpenApiSchema(packedDriveFolderSchema), Following: convertSchemaToOpenApiSchema(packedFollowingSchema), Muting: convertSchemaToOpenApiSchema(packedMutingSchema), Blocking: convertSchemaToOpenApiSchema(packedBlockingSchema), - NoteReaction: convertSchemaToOpenApiSchema(packedNoteReactionSchema), Hashtag: convertSchemaToOpenApiSchema(packedHashtagSchema), Page: convertSchemaToOpenApiSchema(packedPageSchema), };