良い感じに
This commit is contained in:
parent
1744316656
commit
3a02a7dad8
|
@ -14,8 +14,10 @@ block main
|
||||||
| /
|
| /
|
||||||
span.path= url.path
|
span.path= url.path
|
||||||
|
|
||||||
|
if desc
|
||||||
p#desc= desc[lang] || desc['ja']
|
p#desc= desc[lang] || desc['ja']
|
||||||
|
|
||||||
|
if params
|
||||||
section
|
section
|
||||||
h2= i18n('docs.api.endpoints.params')
|
h2= i18n('docs.api.endpoints.params')
|
||||||
+propTable(params)
|
+propTable(params)
|
||||||
|
|
|
@ -25,7 +25,7 @@ html(lang= lang)
|
||||||
li Endpoints
|
li Endpoints
|
||||||
ul
|
ul
|
||||||
each endpoint in endpoints
|
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
|
main
|
||||||
article
|
article
|
||||||
block main
|
block main
|
||||||
|
|
|
@ -60,6 +60,10 @@ nav
|
||||||
background #fff
|
background #fff
|
||||||
border-right solid 2px #eee
|
border-right solid 2px #eee
|
||||||
|
|
||||||
|
ul
|
||||||
|
padding 0
|
||||||
|
margin 0
|
||||||
|
|
||||||
@media (max-width 1025px)
|
@media (max-width 1025px)
|
||||||
main
|
main
|
||||||
margin 0
|
margin 0
|
||||||
|
|
|
@ -2,6 +2,12 @@ import * as path from 'path';
|
||||||
import * as glob from 'glob';
|
import * as glob from 'glob';
|
||||||
|
|
||||||
export interface IEndpointMeta {
|
export interface IEndpointMeta {
|
||||||
|
desc?: any;
|
||||||
|
|
||||||
|
params?: any;
|
||||||
|
|
||||||
|
res?: any;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* このエンドポイントにリクエストするのにユーザー情報が必須か否か
|
* このエンドポイントにリクエストするのにユーザー情報が必須か否か
|
||||||
* 省略した場合は false として解釈されます。
|
* 省略した場合は false として解釈されます。
|
||||||
|
|
|
@ -15,6 +15,7 @@ import config from '../../config';
|
||||||
import I18n from '../../misc/i18n';
|
import I18n from '../../misc/i18n';
|
||||||
import { licenseHtml } from '../../misc/license';
|
import { licenseHtml } from '../../misc/license';
|
||||||
const constants = require('../../const.json');
|
const constants = require('../../const.json');
|
||||||
|
import endpoints from '../../server/api/endpoints';
|
||||||
|
|
||||||
async function genVars(lang: string): Promise<{ [key: string]: any }> {
|
async function genVars(lang: string): Promise<{ [key: string]: any }> {
|
||||||
const vars = {} as { [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 cwd = path.resolve(__dirname + '/../../../') + '/';
|
||||||
|
|
||||||
const endpoints = glob.sync('built/server/api/endpoints/**/*.js', { cwd });
|
vars['endpoints'] = endpoints;
|
||||||
vars['endpoints'] = endpoints.map(ep => require(cwd + ep)).filter(x => x.meta).map(x => x.meta.name);
|
|
||||||
|
|
||||||
const entities = glob.sync('src/docs/api/entities/**/*.yaml', { cwd });
|
const entities = glob.sync('src/docs/api/entities/**/*.yaml', { cwd });
|
||||||
vars['entities'] = entities.map(x => {
|
vars['entities'] = entities.map(x => {
|
||||||
|
@ -169,7 +169,7 @@ router.get('/assets/*', async ctx => {
|
||||||
router.get('/*/api/endpoints/*', async ctx => {
|
router.get('/*/api/endpoints/*', async ctx => {
|
||||||
const lang = ctx.params[0];
|
const lang = ctx.params[0];
|
||||||
const name = ctx.params[1];
|
const name = ctx.params[1];
|
||||||
const ep = require('../../../built/server/api/endpoints/' + name).meta || {};
|
const ep = endpoints.find(e => e.name === name);
|
||||||
|
|
||||||
const vars = {
|
const vars = {
|
||||||
title: name,
|
title: name,
|
||||||
|
@ -178,11 +178,11 @@ router.get('/*/api/endpoints/*', async ctx => {
|
||||||
host: config.api_url,
|
host: config.api_url,
|
||||||
path: name
|
path: name
|
||||||
},
|
},
|
||||||
desc: ep.desc,
|
desc: ep.meta.desc,
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
params: sortParams(Object.entries(ep.params).map(([k, v]) => parseParamDefinition(k, v))),
|
params: ep.meta.params ? sortParams(Object.entries(ep.meta.params).map(([k, v]) => parseParamDefinition(k, v))) : null,
|
||||||
paramDefs: extractParamDefRef(Object.entries(ep.params).map(([k, v]) => v)),
|
paramDefs: ep.meta.params ? extractParamDefRef(Object.entries(ep.meta.params).map(([k, v]) => v)) : null,
|
||||||
res: ep.res && ep.res.props ? sortParams(Object.entries(ep.res.props).map(([k, v]) => parsePropDefinition(k, 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)))
|
resDefs: null//extractPropDefRef(Object.entries(ep.res.props).map(([k, v]) => parsePropDefinition(k, v)))
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue