-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
バックエンドが生成するapi.jsonからmisskey-jsの型を作成する #12434
バックエンドが生成するapi.jsonからmisskey-jsの型を作成する #12434
Conversation
(WIPとのことなのでDraftにしておきました!準備ができればReady for reviewを押してください) |
めも 自動生成したやつにないInstance federation/instances
↑api.jsonの生成ロジックとAjvのロジックが噛み合わなくて辛かったのでやめた |
# Conflicts: # packages/misskey-js/src/api.types.ts # packages/misskey-js/src/entities.ts
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## develop #12434 +/- ##
===========================================
+ Coverage 78.71% 78.76% +0.04%
===========================================
Files 951 954 +3
Lines 103427 103792 +365
Branches 8330 8327 -3
===========================================
+ Hits 81417 81754 +337
- Misses 22010 22038 +28 ☔ View full report in Codecov by Sentry. |
このPRによるapi.jsonの差分 差分はこちら--- base
+++ head
@@ -347,6 +347,82 @@
"notesPerOneAd": {
"type": "number",
"nullable": false
+ },
+ "backgroundImageUrl": {
+ "type": "string",
+ "nullable": true
+ },
+ "deeplAuthKey": {
+ "type": "string",
+ "nullable": true
+ },
+ "deeplIsPro": {
+ "type": "boolean",
+ "nullable": false
+ },
+ "defaultDarkTheme": {
+ "type": "string",
+ "nullable": true
+ },
+ "defaultLightTheme": {
+ "type": "string",
+ "nullable": true
+ },
+ "description": {
+ "type": "string",
+ "nullable": true
+ },
+ "disableRegistration": {
+ "type": "boolean",
+ "nullable": false
+ },
+ "impressumUrl": {
+ "type": "string",
+ "nullable": true
+ },
+ "maintainerEmail": {
+ "type": "string",
+ "nullable": true
+ },
+ "maintainerName": {
+ "type": "string",
+ "nullable": true
+ },
+ "name": {
+ "type": "string",
+ "nullable": true
+ },
+ "objectStorageS3ForcePathStyle": {
+ "type": "boolean",
+ "nullable": false
+ },
+ "privacyPolicyUrl": {
+ "type": "string",
+ "nullable": true
+ },
+ "repositoryUrl": {
+ "type": "string",
+ "nullable": false
+ },
+ "summalyProxy": {
+ "type": "string",
+ "nullable": true
+ },
+ "themeColor": {
+ "type": "string",
+ "nullable": true
+ },
+ "tosUrl": {
+ "type": "string",
+ "nullable": true
+ },
+ "uri": {
+ "type": "string",
+ "nullable": false
+ },
+ "version": {
+ "type": "string",
+ "nullable": false
}
},
"required": [
@@ -419,7 +495,26 @@
"perRemoteUserUserTimelineCacheMax",
"perUserHomeTimelineCacheMax",
"perUserListTimelineCacheMax",
- "notesPerOneAd"
+ "notesPerOneAd",
+ "backgroundImageUrl",
+ "deeplAuthKey",
+ "deeplIsPro",
+ "defaultDarkTheme",
+ "defaultLightTheme",
+ "description",
+ "disableRegistration",
+ "impressumUrl",
+ "maintainerEmail",
+ "maintainerName",
+ "name",
+ "objectStorageS3ForcePathStyle",
+ "privacyPolicyUrl",
+ "repositoryUrl",
+ "summalyProxy",
+ "themeColor",
+ "tosUrl",
+ "uri",
+ "version"
]
}
}
@@ -30342,7 +30437,24 @@
"default": 0
},
"sort": {
- "type": "string"
+ "type": "string",
+ "nullable": true,
+ "enum": [
+ "+pubSub",
+ "-pubSub",
+ "+notes",
+ "-notes",
+ "+users",
+ "-users",
+ "+following",
+ "-following",
+ "+followers",
+ "-followers",
+ "+firstRetrievedAt",
+ "-firstRetrievedAt",
+ "+latestRequestReceivedAt",
+ "-latestRequestReceivedAt"
+ ]
}
}
}
@@ -30535,7 +30647,24 @@
"default": 0
},
"sort": {
- "type": "string"
+ "type": "string",
+ "nullable": true,
+ "enum": [
+ "+pubSub",
+ "-pubSub",
+ "+notes",
+ "-notes",
+ "+users",
+ "-users",
+ "+following",
+ "-following",
+ "+followers",
+ "-followers",
+ "+firstRetrievedAt",
+ "-firstRetrievedAt",
+ "+latestRequestReceivedAt",
+ "-latestRequestReceivedAt"
+ ]
}
}
}
@@ -41970,6 +42099,33 @@
"objectStorage",
"serviceWorker"
]
+ },
+ "backgroundImageUrl": {
+ "type": "string",
+ "nullable": true
+ },
+ "impressumUrl": {
+ "type": "string",
+ "nullable": true
+ },
+ "logoImageUrl": {
+ "type": "string",
+ "nullable": true
+ },
+ "privacyPolicyUrl": {
+ "type": "string",
+ "nullable": true
+ },
+ "serverRules": {
+ "type": "array",
+ "nullable": false,
+ "items": {
+ "type": "string"
+ }
+ },
+ "themeColor": {
+ "type": "string",
+ "nullable": true
}
},
"required": [
@@ -42011,7 +42167,13 @@
"enableServiceWorker",
"translatorAvailable",
"proxyAccountName",
- "mediaProxy"
+ "mediaProxy",
+ "backgroundImageUrl",
+ "impressumUrl",
+ "logoImageUrl",
+ "privacyPolicyUrl",
+ "serverRules",
+ "themeColor"
]
}
} |
(CIめっちゃこけてる) |
# Conflicts: # package.json # pnpm-lock.yaml
suspended = instance?.isSuspended ?? false; | ||
isBlocked = instance?.isBlocked ?? false; | ||
isSilenced = instance?.isSilenced ?? false; | ||
faviconUrl = getProxiedImageUrlNullable(instance?.faviconUrl, 'preview') ?? getProxiedImageUrlNullable(instance?.iconUrl, 'preview'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
federation/show-instance
は204を返すこともあるので、bodyが空だった時に初期値を入れるようにしています
await os.api('admin/update-meta', { | ||
silencedHosts: isSilenced ? meta.silencedHosts.concat([host]) : meta.silencedHosts.filter(x => x !== host), | ||
silencedHosts: isSilenced ? silencedHosts.concat([host]) : silencedHosts.filter(x => x !== host), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
silencedHosts
は型定義上undefinedになりえるので、その場合はデフォルト値として空配列を使用する措置をしました
return ''; | ||
} | ||
|
||
return getProxiedImageUrl(instance.iconUrl, 'preview'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
iconUrl
はDB定義上nullになりえるのでこうしています
(呼び元にてv-ifで制御されている)
data: P = {} as any, | ||
token?: string | null | undefined, | ||
signal?: AbortSignal, | ||
): Promise<Misskey.api.SwitchCaseResponseType<E, P>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
misskey-js側で定義されていたものをexport typeして持ち込みました。
$switch/$caseを使った特殊な型定義で、リクエストによりレスポンスの型定義が動的に切り替わる仕組みです。
res.requests.received.splice(0, 1); | ||
chartValues = res.requests.received; | ||
res['requests.received'].splice(0, 1); | ||
chartValues = res['requests.received']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
返ってくる値の形が↓のようになっており、エラーとなっていましたので値の参照方法を変えています
https://github.com/samunohito/misskey/blob/c2370a1be631355e709c47d3b5e9469906116b84/packages/backend/src/core/chart/charts/entities/instance.ts
messagingChannel.on('message', message => { | ||
expectType<Misskey.entities.MessagingMessage>(message); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
messagingは既に存在しないので削除しています
#9919
id: MessagingMessage['id']; | ||
}; | ||
}; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
メッセージ機能は廃止になった経緯を観測したので削除しています(未使用の型定義整理の一環)
#9919
readyということはもうレビューしてもよい状態ということで合ってるかしら? |
@syuilo |
🙏🏻 🙏🏻 🙏🏻 🙏🏻 🙏🏻 |
function generateVersionHeaderComment(openApiDocs: OpenAPIV3.Document): string { | ||
const contents = { | ||
version: openApiDocs.info.version, | ||
generatedAt: new Date().toISOString(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
生成日時がコメントで入るようになっていますが、コンフリクト解消の手間を考えると無くても良い気がします。いかがでしょうか?
* ひとまず生成できるところまで * ファイル構成整理 * 生成コマンド整理 * misskey-jsへの組み込み * fix generator.ts * wip * fix generator.ts * fix package.json * 生成ロジックの調整 * 型レベルでのswitch-case機構をmisskey-jsからfrontendに持ち込めるようにした * 型チェック用のtsconfig.jsonを作成 * 他のエンドポイントを呼ぶ関数にも適用 * 未使用エンティティなどを削除 * misskey-js側で手動定義されていた型を自動生成された型に移行(ただしapi.jsonがvalidでなくなってしまったので後で修正する) * messagingは廃止されている(テストのビルドエラー解消) * validなapi.jsonを出力できるように修正 * 修正漏れ対応 * Ajvに怒られて起動できなかったところを修正 * fix ci(途中) * パラメータenumをやめる * add command * add api.json * 都度自動生成をやめる * 一気通貫スクリプト修正 * fix ci * 生成ロジック修正 * フロントの型チェックは結局やらなかったので戻しておく * fix pnpm-lock.yaml * add README.md --------- Co-authored-by: osamu <[email protected]> Co-authored-by: syuilo <[email protected]>
What
#12410 の対応です。
この対応により、misskey-jsの型情報をバックエンドに追従させやすくなります。
Why
fix #12410
Additional info (optional)
openapi-typescript
を使用してapi.jsonから型情報を作成…みたいな感じで進めています。
backend/frontendにも変更ファイルが多数存在していますが、その内訳は以下のとおりです。型に関する内容が中心で、トランスパイル後の動きに影響があるものはほぼ無いと思われます(ロジックに手を入れた所は差分にコメントします)
Checklist