Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

json-schema配下の最新化 #12312

Merged
merged 17 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
- Feat: 管理者がコントロールパネルからメールアドレスの照会を行えるようになりました
- Enhance: ローカリゼーションの更新
- Enhance: 依存関係の更新
- Enhance: json-schema(OpenAPIの戻り値として使用されるスキーマ定義)を出来る限り最新化 #12311

### Client
- Enhance: MFMでルビを振れるように
Expand Down
14 changes: 8 additions & 6 deletions packages/backend/src/core/entities/NotificationEntityService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,14 @@ export class NotificationEntityService implements OnModuleInit {
});
} else if (notification.type === 'renote:grouped') {
const users = await Promise.all(notification.userIds.map(userId => {
const user = hint?.packedUsers != null
? hint.packedUsers.get(userId)
: this.userEntityService.pack(userId!, { id: meId }, {
detail: false,
});
return user;
const packedUser = hint?.packedUsers != null ? hint.packedUsers.get(userId) : null;
if (packedUser) {
return packedUser;
}

return this.userEntityService.pack(userId, { id: meId }, {
detail: false,
});
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hint.packedUsers.get(userId)からundefinedを引き剥がすための対応です。
!マークで対応することも可能でしたが、lintの警告が出てしまったためこのような形になりました。
不都合あれば戻しますので、お手数ですがその際はご指摘願います。

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Misskeyのバックエンド見ていただければわかりますが普通に ! は使われている(lintを無視している)のでどっちでもいい気がいたします)(方針に関してはしゅいろ氏あたりに聞いてみてください)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ifで弾く書き方だと、読み手に「undefinedが入る可能性があるのか」と思わせかねないのでそのような可能性がないことが明らかな場合は ! で書くようにしてますね(とはいえ気軽には使いたくないのでlintのwarnは出すようにしてます)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここはundefinedになる可能性が十分あるので(packedUsersそのものも、packedUsersのなかにuserIdがない可能性もありえる)、今の実装でも良いのかなと思いつつ…
どうしたら良いのか分からなくなりつつあるので、方針を確認させて下さい:pray:

①このまま
②もとに戻す(ただしjson-schemaの型と合わない)
③もとに戻しつつ、hint.packedUsers.get(userId)!として型を合わせる
④json-schema側をundefined許容にする
⑤③をより安全にする(packedUsersのnullチェックだけじゃなく、hasでuserIdの有無を見る)

const user = hint?.packedUsers?.has(userId!)
	? hint.packedUsers.get(userId)!
	: this.userEntityService.pack(userId!, { id: meId }, {
		detail: false,
	});
return user;

}));
return await awaitAll({
id: notification.id,
Expand Down
8 changes: 6 additions & 2 deletions packages/backend/src/models/json-schema/announcement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,15 @@ export const packedAnnouncementSchema = {
type: 'string',
optional: false, nullable: false,
},
forYou: {
needConfirmationToRead: {
type: 'boolean',
optional: false, nullable: false,
},
needConfirmationToRead: {
silence: {
type: 'boolean',
optional: false, nullable: false,
},
forYou: {
type: 'boolean',
optional: false, nullable: false,
},
Expand Down
57 changes: 33 additions & 24 deletions packages/backend/src/models/json-schema/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,59 @@ export const packedChannelSchema = {
},
lastNotedAt: {
type: 'string',
optional: false, nullable: true,
nullable: true, optional: false,
format: 'date-time',
},
name: {
type: 'string',
optional: false, nullable: false,
},
description: {
type: 'string',
optional: false, nullable: true,
},
userId: {
type: 'string',
nullable: true, optional: false,
format: 'id',
},
bannerUrl: {
type: 'string',
format: 'url',
nullable: true, optional: false,
},
pinnedNoteIds: {
type: 'array',
nullable: false, optional: false,
items: {
type: 'string',
format: 'id',
},
},
color: {
type: 'string',
optional: false, nullable: false,
},
isArchived: {
type: 'boolean',
optional: false, nullable: false,
},
notesCount: {
usersCount: {
type: 'number',
nullable: false, optional: false,
},
usersCount: {
notesCount: {
type: 'number',
nullable: false, optional: false,
},
isSensitive: {
type: 'boolean',
optional: false, nullable: false,
},
allowRenoteToExternal: {
type: 'boolean',
optional: false, nullable: false,
},
isFollowing: {
type: 'boolean',
optional: true, nullable: false,
Expand All @@ -55,30 +80,14 @@ export const packedChannelSchema = {
type: 'boolean',
optional: true, nullable: false,
},
userId: {
type: 'string',
nullable: true, optional: false,
format: 'id',
},
pinnedNoteIds: {
pinnedNotes: {
type: 'array',
nullable: false, optional: false,
optional: true, nullable: false,
items: {
type: 'string',
format: 'id',
type: 'object',
optional: false, nullable: false,
ref: 'Note',
},
},
color: {
type: 'string',
optional: false, nullable: false,
},
isSensitive: {
type: 'boolean',
optional: false, nullable: false,
},
allowRenoteToExternal: {
type: 'boolean',
optional: false, nullable: false,
},
},
} as const;
8 changes: 4 additions & 4 deletions packages/backend/src/models/json-schema/clip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ export const packedClipSchema = {
type: 'boolean',
optional: false, nullable: false,
},
isFavorited: {
type: 'boolean',
optional: true, nullable: false,
},
favoritedCount: {
type: 'number',
optional: false, nullable: false,
},
isFavorited: {
type: 'boolean',
optional: true, nullable: false,
},
},
} as const;
2 changes: 1 addition & 1 deletion packages/backend/src/models/json-schema/drive-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const packedDriveFileSchema = {
},
url: {
type: 'string',
optional: false, nullable: true,
optional: false, nullable: false,
format: 'url',
},
thumbnailUrl: {
Expand Down
12 changes: 6 additions & 6 deletions packages/backend/src/models/json-schema/drive-folder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ export const packedDriveFolderSchema = {
type: 'string',
optional: false, nullable: false,
},
parentId: {
type: 'string',
optional: false, nullable: true,
format: 'id',
example: 'xxxxxxxxxx',
},
foldersCount: {
type: 'number',
optional: true, nullable: false,
Expand All @@ -29,12 +35,6 @@ export const packedDriveFolderSchema = {
type: 'number',
optional: true, nullable: false,
},
parentId: {
type: 'string',
optional: false, nullable: true,
format: 'id',
example: 'xxxxxxxxxx',
},
parent: {
type: 'object',
optional: true, nullable: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ export const packedFederationInstanceSchema = {
type: 'string',
optional: false, nullable: true,
},
isSilenced: {
type: 'boolean',
optional: false, nullable: false,
},
iconUrl: {
type: 'string',
optional: false, nullable: true,
Expand All @@ -93,11 +97,6 @@ export const packedFederationInstanceSchema = {
type: 'string',
optional: false, nullable: true,
},
isSilenced: {
type: "boolean",
optional: false,
nullable: false,
},
infoUpdatedAt: {
type: 'string',
optional: false, nullable: true,
Expand Down
18 changes: 9 additions & 9 deletions packages/backend/src/models/json-schema/flash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,26 @@ export const packedFlashSchema = {
optional: false, nullable: false,
format: 'date-time',
},
title: {
userId: {
type: 'string',
optional: false, nullable: false,
format: 'id',
},
summary: {
type: 'string',
user: {
type: 'object',
ref: 'UserLite',
optional: false, nullable: false,
},
script: {
title: {
type: 'string',
optional: false, nullable: false,
},
userId: {
summary: {
type: 'string',
optional: false, nullable: false,
format: 'id',
},
user: {
type: 'object',
ref: 'UserLite',
script: {
type: 'string',
optional: false, nullable: false,
},
likedCount: {
Expand Down
10 changes: 5 additions & 5 deletions packages/backend/src/models/json-schema/following.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ export const packedFollowingSchema = {
optional: false, nullable: false,
format: 'id',
},
followee: {
type: 'object',
optional: true, nullable: false,
ref: 'UserDetailed',
},
followerId: {
type: 'string',
optional: false, nullable: false,
format: 'id',
},
followee: {
type: 'object',
optional: true, nullable: false,
ref: 'UserDetailed',
},
follower: {
type: 'object',
optional: true, nullable: false,
Expand Down
24 changes: 16 additions & 8 deletions packages/backend/src/models/json-schema/gallery-post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,6 @@ export const packedGalleryPostSchema = {
optional: false, nullable: false,
format: 'date-time',
},
title: {
type: 'string',
optional: false, nullable: false,
},
description: {
type: 'string',
optional: false, nullable: true,
},
userId: {
type: 'string',
optional: false, nullable: false,
Expand All @@ -40,6 +32,14 @@ export const packedGalleryPostSchema = {
ref: 'UserLite',
optional: false, nullable: false,
},
title: {
type: 'string',
optional: false, nullable: false,
},
description: {
type: 'string',
optional: false, nullable: true,
},
fileIds: {
type: 'array',
optional: true, nullable: false,
Expand Down Expand Up @@ -70,5 +70,13 @@ export const packedGalleryPostSchema = {
type: 'boolean',
optional: false, nullable: false,
},
likedCount: {
type: 'number',
optional: false, nullable: false,
},
isLiked: {
type: 'boolean',
optional: true, nullable: false,
},
},
} as const;
28 changes: 12 additions & 16 deletions packages/backend/src/models/json-schema/note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,22 +127,18 @@ export const packedNoteSchema = {
channel: {
type: 'object',
optional: true, nullable: true,
items: {
type: 'object',
optional: false, nullable: false,
properties: {
id: {
type: 'string',
optional: false, nullable: false,
},
name: {
type: 'string',
optional: false, nullable: true,
},
isSensitive: {
type: 'boolean',
optional: true, nullable: false,
},
properties: {
id: {
type: 'string',
optional: false, nullable: false,
},
name: {
type: 'string',
optional: false, nullable: true,
},
isSensitive: {
type: 'boolean',
optional: true, nullable: false,
},
},
},
Expand Down
26 changes: 11 additions & 15 deletions packages/backend/src/models/json-schema/notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,9 @@ export const packedNotificationSchema = {
type: 'string',
optional: true, nullable: true,
},
choice: {
type: 'number',
optional: true, nullable: true,
},
invitation: {
type: 'object',
optional: true, nullable: true,
achievement: {
type: 'string',
optional: true, nullable: false,
},
body: {
type: 'string',
Expand Down Expand Up @@ -81,14 +77,14 @@ export const packedNotificationSchema = {
required: ['user', 'reaction'],
},
},
},
users: {
type: 'array',
optional: true, nullable: true,
items: {
type: 'object',
ref: 'UserLite',
optional: false, nullable: false,
users: {
type: 'array',
optional: true, nullable: true,
items: {
type: 'object',
ref: 'UserLite',
optional: false, nullable: false,
},
},
},
} as const;
Loading
Loading