From 168d13d6e687b87906b2dfd8f7206d03cec32bdc Mon Sep 17 00:00:00 2001
From: syuilo <syuilotan@yahoo.co.jp>
Date: Mon, 16 Jul 2018 06:19:19 +0900
Subject: [PATCH] Improve docs

---
 locales/ja.yml                  |  2 ++
 src/docs/api/endpoints/view.pug | 15 +++++++++++----
 src/docs/style.styl             |  4 ++--
 src/server/api/endpoints/i.ts   | 13 ++++++++++---
 src/server/web/docs.ts          |  3 +--
 5 files changed, 26 insertions(+), 11 deletions(-)

diff --git a/locales/ja.yml b/locales/ja.yml
index 0df702c600..7e98a505ec 100644
--- a/locales/ja.yml
+++ b/locales/ja.yml
@@ -1098,7 +1098,9 @@ docs:
       properties: "プロパティ"
     endpoints:
       params: "パラメータ"
+      no-params: "パラメータはありません"
       res: "レスポンス"
+      require-credential: "このエンドポイントは認証情報が必須です。"
     props:
       name: "名前"
       type: "型"
diff --git a/src/docs/api/endpoints/view.pug b/src/docs/api/endpoints/view.pug
index 809fc07204..e7bfba086e 100644
--- a/src/docs/api/endpoints/view.pug
+++ b/src/docs/api/endpoints/view.pug
@@ -5,7 +5,7 @@ block meta
 	link(rel="stylesheet" href="/docs/assets/api/endpoints/style.css")
 
 block main
-	h1= endpoint
+	h1= title
 
 	p#url
 		span.method POST
@@ -14,10 +14,13 @@ block main
 			| /
 		span.path= url.path
 
-	if desc
-		p#desc= desc[lang] || desc['ja']
+	if endpoint.desc
+		p#desc= endpoint.desc[lang] || endpoint.desc['ja']
 
-	if params
+	if endpoint.requireCredential
+		div.ui.info: p= i18n('docs.api.endpoints.require-credential')
+
+	if params && Object.keys(params).length > 0
 		section
 			h2= i18n('docs.api.endpoints.params')
 			+propTable(params)
@@ -27,6 +30,10 @@ block main
 					section(id= paramDef.name)
 						h3= paramDef.name
 						+propTable(paramDef.params)
+	if params && Object.keys(params).length == 0
+		section
+			h2= i18n('docs.api.endpoints.params')
+			p= i18n('docs.api.endpoints.no-params')
 
 	if res
 		section
diff --git a/src/docs/style.styl b/src/docs/style.styl
index d31da7e8ee..95b5b0da52 100644
--- a/src/docs/style.styl
+++ b/src/docs/style.styl
@@ -7,7 +7,7 @@ body
 	word-break break-word
 
 main
-	margin 0 0 0 300px
+	margin 0 0 0 330px
 	padding 64px
 	width 100%
 	max-width 800px
@@ -53,7 +53,7 @@ nav
 	z-index 10000
 	top 0
 	left 0
-	width 300px
+	width 330px
 	height 100%
 	overflow auto
 	padding 32px
diff --git a/src/server/api/endpoints/i.ts b/src/server/api/endpoints/i.ts
index 150ab34a0f..8219100d60 100644
--- a/src/server/api/endpoints/i.ts
+++ b/src/server/api/endpoints/i.ts
@@ -1,9 +1,16 @@
 import User, { pack, ILocalUser } from '../../../models/user';
 import { IApp } from '../../../models/app';
 
-/**
- * Show myself
- */
+export const meta = {
+	desc: {
+		ja: '自分のアカウント情報を取得します。'
+	},
+
+	requireCredential: true,
+
+	params: {}
+};
+
 export default (params: any, user: ILocalUser, app: IApp) => new Promise(async (res, rej) => {
 	const isSecure = user != null && app == null;
 
diff --git a/src/server/web/docs.ts b/src/server/web/docs.ts
index f203815a5d..4d212bbeab 100644
--- a/src/server/web/docs.ts
+++ b/src/server/web/docs.ts
@@ -173,12 +173,11 @@ router.get('/*/api/endpoints/*', async ctx => {
 
 	const vars = {
 		title: name,
-		endpoint: name,
+		endpoint: ep.meta,
 		url: {
 			host: config.api_url,
 			path: name
 		},
-		desc: ep.meta.desc,
 		// @ts-ignore
 		params: ep.meta.params ? sortParams(Object.entries(ep.meta.params).map(([k, v]) => parseParamDefinition(k, v))) : null,
 		paramDefs: ep.meta.params ? extractParamDefRef(Object.entries(ep.meta.params).map(([k, v]) => v)) : null,