From 3a02a7dad891400045a7fd0ba6eed99953eddab0 Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 16 Jul 2018 03:53:03 +0900 Subject: [PATCH] =?UTF-8?q?=E8=89=AF=E3=81=84=E6=84=9F=E3=81=98=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/docs/api/endpoints/view.pug | 20 +++++++++++--------- src/docs/base.pug | 2 +- src/docs/style.styl | 4 ++++ src/server/api/endpoints.ts | 6 ++++++ src/server/web/docs.ts | 14 +++++++------- 5 files changed, 29 insertions(+), 17 deletions(-) diff --git a/src/docs/api/endpoints/view.pug b/src/docs/api/endpoints/view.pug index 4daaad771..809fc0720 100644 --- a/src/docs/api/endpoints/view.pug +++ b/src/docs/api/endpoints/view.pug @@ -14,17 +14,19 @@ block main | / span.path= url.path - p#desc= desc[lang] || desc['ja'] + if desc + p#desc= desc[lang] || desc['ja'] - section - h2= i18n('docs.api.endpoints.params') - +propTable(params) + if params + section + h2= i18n('docs.api.endpoints.params') + +propTable(params) - if paramDefs - each paramDef in paramDefs - section(id= paramDef.name) - h3= paramDef.name - +propTable(paramDef.params) + if paramDefs + each paramDef in paramDefs + section(id= paramDef.name) + h3= paramDef.name + +propTable(paramDef.params) if res section diff --git a/src/docs/base.pug b/src/docs/base.pug index 1ee623bb3..058aea64a 100644 --- a/src/docs/base.pug +++ b/src/docs/base.pug @@ -25,7 +25,7 @@ html(lang= lang) li Endpoints ul each endpoint in endpoints - li: a(href=`/docs/${lang}/api/endpoints/${kebab(endpoint)}`)= endpoint + li: a(href=`/docs/${lang}/api/endpoints/${kebab(endpoint.name)}`)= endpoint.name main article block main diff --git a/src/docs/style.styl b/src/docs/style.styl index d9ee9dad4..c851d07b8 100644 --- a/src/docs/style.styl +++ b/src/docs/style.styl @@ -60,6 +60,10 @@ nav background #fff border-right solid 2px #eee + ul + padding 0 + margin 0 + @media (max-width 1025px) main margin 0 diff --git a/src/server/api/endpoints.ts b/src/server/api/endpoints.ts index cc9b90d6f..5923694c6 100644 --- a/src/server/api/endpoints.ts +++ b/src/server/api/endpoints.ts @@ -2,6 +2,12 @@ import * as path from 'path'; import * as glob from 'glob'; export interface IEndpointMeta { + desc?: any; + + params?: any; + + res?: any; + /** * このエンドポイントにリクエストするのにユーザー情報が必須か否か * 省略した場合は false として解釈されます。 diff --git a/src/server/web/docs.ts b/src/server/web/docs.ts index 3e6ee0f12..f203815a5 100644 --- a/src/server/web/docs.ts +++ b/src/server/web/docs.ts @@ -15,6 +15,7 @@ import config from '../../config'; import I18n from '../../misc/i18n'; import { licenseHtml } from '../../misc/license'; const constants = require('../../const.json'); +import endpoints from '../../server/api/endpoints'; async function genVars(lang: string): Promise<{ [key: string]: any }> { const vars = {} as { [key: string]: any }; @@ -23,8 +24,7 @@ async function genVars(lang: string): Promise<{ [key: string]: any }> { const cwd = path.resolve(__dirname + '/../../../') + '/'; - const endpoints = glob.sync('built/server/api/endpoints/**/*.js', { cwd }); - vars['endpoints'] = endpoints.map(ep => require(cwd + ep)).filter(x => x.meta).map(x => x.meta.name); + vars['endpoints'] = endpoints; const entities = glob.sync('src/docs/api/entities/**/*.yaml', { cwd }); vars['entities'] = entities.map(x => { @@ -169,7 +169,7 @@ router.get('/assets/*', async ctx => { router.get('/*/api/endpoints/*', async ctx => { const lang = ctx.params[0]; const name = ctx.params[1]; - const ep = require('../../../built/server/api/endpoints/' + name).meta || {}; + const ep = endpoints.find(e => e.name === name); const vars = { title: name, @@ -178,11 +178,11 @@ router.get('/*/api/endpoints/*', async ctx => { host: config.api_url, path: name }, - desc: ep.desc, + desc: ep.meta.desc, // @ts-ignore - params: sortParams(Object.entries(ep.params).map(([k, v]) => parseParamDefinition(k, v))), - paramDefs: extractParamDefRef(Object.entries(ep.params).map(([k, v]) => v)), - res: ep.res && ep.res.props ? sortParams(Object.entries(ep.res.props).map(([k, v]) => parsePropDefinition(k, v))) : null, + 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, + res: ep.meta.res && ep.meta.res.props ? sortParams(Object.entries(ep.meta.res.props).map(([k, v]) => parsePropDefinition(k, v))) : null, resDefs: null//extractPropDefRef(Object.entries(ep.res.props).map(([k, v]) => parsePropDefinition(k, v))) };