diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2019-04-15 12:23:20 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2019-04-15 12:23:20 +0900 |
| commit | d040dc19bce8635dc9a0646a83c44ad78e2855d7 (patch) | |
| tree | 6071ab5d3893f3e4453c887764d646aa6483df33 /src/server/api/openapi/description.ts | |
| parent | Merge branch 'develop' (diff) | |
| parent | 11.0.2 (diff) | |
| download | misskey-d040dc19bce8635dc9a0646a83c44ad78e2855d7.tar.gz misskey-d040dc19bce8635dc9a0646a83c44ad78e2855d7.tar.bz2 misskey-d040dc19bce8635dc9a0646a83c44ad78e2855d7.zip | |
Merge branch 'develop'
Diffstat (limited to 'src/server/api/openapi/description.ts')
| -rw-r--r-- | src/server/api/openapi/description.ts | 55 |
1 files changed, 53 insertions, 2 deletions
diff --git a/src/server/api/openapi/description.ts b/src/server/api/openapi/description.ts index 04a0b4c719..0a4c8699d1 100644 --- a/src/server/api/openapi/description.ts +++ b/src/server/api/openapi/description.ts @@ -1,6 +1,49 @@ import config from '../../../config'; +import endpoints from '../endpoints'; +import * as locale from '../../../../locales/'; +import { fromEntries } from '../../../prelude/array'; +import { kinds as kindsList } from '../kinds'; + +export interface IKindInfo { + endpoints: string[]; + descs: { [x: string]: string; }; +} + +export function kinds() { + const kinds = fromEntries( + kindsList + .map(k => [k, { + endpoints: [], + descs: fromEntries( + Object.keys(locale) + .map(l => [l, locale[l].common.permissions[k] as string] as [string, string]) + ) as { [x: string]: string; } + }] as [ string, IKindInfo ]) + ) as { [x: string]: IKindInfo; }; + + const errors = [] as string[][]; + + for (const endpoint of endpoints.filter(ep => !ep.meta.secure)) { + if (endpoint.meta.kind) { + const kind = endpoint.meta.kind; + if (kind in kinds) kinds[kind].endpoints.push(endpoint.name); + else errors.push([kind, endpoint.name]); + } + } + + if (errors.length > 0) throw Error('\n ' + errors.map((e) => `Unknown kind (permission) "${e[0]}" found at ${e[1]}.`).join('\n ')); + + return kinds; +} + +export function getDescription(lang = 'ja-JP'): string { + const permissionTable = (Object.entries(kinds()) as [string, IKindInfo][]) + .map(e => `|${e[0]}|${e[1].descs[lang]}|${e[1].endpoints.map(f => `[${f}](#operation/${f})`).join(', ')}|`) + .join('\n'); + + const descriptions = { + 'ja-JP': `**Misskey is a decentralized microblogging platform.** -export const description = ` ## Usage **APIはすべてPOSTでリクエスト/レスポンスともにJSON形式です。** 一部のAPIはリクエストに認証情報(APIキー)が必要です。リクエストの際に\`i\`というパラメータでAPIキーを添付してください。 @@ -44,4 +87,12 @@ APIキーの生成方法を擬似コードで表すと次のようになりま \`\`\` js const i = sha256(userToken + secretKey); \`\`\` -`; + +## Permissions +|Permisson (kind)|Description|Endpoints| +|:--|:--|:--| +${permissionTable} +` + } as { [x: string]: string }; + return lang in descriptions ? descriptions[lang] : descriptions['ja-JP']; +} |