✌️
This commit is contained in:
parent
a357d5c6a5
commit
d6ec5f2fe1
11 changed files with 305 additions and 80 deletions
|
|
@ -1,96 +0,0 @@
|
|||
/**
|
||||
* Gulp tasks
|
||||
*/
|
||||
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as glob from 'glob';
|
||||
import * as gulp from 'gulp';
|
||||
import * as pug from 'pug';
|
||||
import * as yaml from 'js-yaml';
|
||||
import * as mkdirp from 'mkdirp';
|
||||
|
||||
import config from './../../../../conf';
|
||||
|
||||
const parseParam = param => {
|
||||
const id = param.type.match(/^id\((.+?)\)/);
|
||||
const entity = param.type.match(/^entity\((.+?)\)/);
|
||||
const isObject = /^object/.test(param.type);
|
||||
const isArray = /\[\]$/.test(param.type);
|
||||
if (id) {
|
||||
param.kind = 'id';
|
||||
param.type = 'string';
|
||||
param.entity = id[1];
|
||||
if (isArray) {
|
||||
param.type += '[]';
|
||||
}
|
||||
}
|
||||
if (entity) {
|
||||
param.kind = 'entity';
|
||||
param.type = 'object';
|
||||
param.entity = entity[1];
|
||||
if (isArray) {
|
||||
param.type += '[]';
|
||||
}
|
||||
}
|
||||
if (isObject) {
|
||||
param.kind = 'object';
|
||||
}
|
||||
|
||||
return param;
|
||||
};
|
||||
|
||||
const extractDefs = params => {
|
||||
const defs = [];
|
||||
|
||||
params.forEach(param => {
|
||||
if (param.def) {
|
||||
defs.push({
|
||||
name: param.defName,
|
||||
params: param.def.map(p => parseParam(p))
|
||||
});
|
||||
|
||||
const childDefs = extractDefs(param.def);
|
||||
|
||||
defs.concat(childDefs);
|
||||
}
|
||||
});
|
||||
|
||||
return defs;
|
||||
};
|
||||
|
||||
gulp.task('doc:endpoints', () => {
|
||||
glob('./src/web/docs/api/endpoints/**/*.yaml', (globErr, files) => {
|
||||
if (globErr) {
|
||||
console.error(globErr);
|
||||
return;
|
||||
}
|
||||
//console.log(files);
|
||||
files.forEach(file => {
|
||||
const ep = yaml.safeLoad(fs.readFileSync(file, 'utf-8'));
|
||||
const vars = {
|
||||
endpoint: ep.endpoint,
|
||||
url: `${config.api_url}/${ep.endpoint}`,
|
||||
desc: ep.desc,
|
||||
params: ep.params.map(p => parseParam(p)),
|
||||
paramDefs: extractDefs(ep.params),
|
||||
res: ep.res.map(p => parseParam(p)),
|
||||
resDefs: extractDefs(ep.res)
|
||||
};
|
||||
pug.renderFile('./src/web/docs/api/endpoints/view.pug', vars, (renderErr, html) => {
|
||||
if (renderErr) {
|
||||
console.error(renderErr);
|
||||
return;
|
||||
}
|
||||
const htmlPath = `./built/web/docs/api/endpoints/${ep.endpoint}.html`;
|
||||
mkdirp(path.dirname(htmlPath), (mkdirErr) => {
|
||||
if (mkdirErr) {
|
||||
console.error(mkdirErr);
|
||||
return;
|
||||
}
|
||||
fs.writeFileSync(htmlPath, html, 'utf-8');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -10,7 +10,7 @@ params:
|
|||
optional: true
|
||||
desc:
|
||||
ja: "投稿の本文"
|
||||
en: "Text of a post"
|
||||
en: "The text of your post"
|
||||
- name: "media_ids"
|
||||
type: "id(DriveFile)[]"
|
||||
optional: true
|
||||
|
|
@ -22,19 +22,19 @@ params:
|
|||
optional: true
|
||||
desc:
|
||||
ja: "返信する投稿"
|
||||
en: "A post you want to reply"
|
||||
en: "The post you want to reply"
|
||||
- name: "repost_id"
|
||||
type: "id(Post)"
|
||||
optional: true
|
||||
desc:
|
||||
ja: "引用する投稿"
|
||||
en: "A post you want to quote"
|
||||
en: "The post you want to quote"
|
||||
- name: "poll"
|
||||
type: "object"
|
||||
optional: true
|
||||
desc:
|
||||
ja: "投票"
|
||||
en: "A poll"
|
||||
en: "The poll"
|
||||
defName: "poll"
|
||||
def:
|
||||
- name: "choices"
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
@import "../../style"
|
||||
@import "../style"
|
||||
|
||||
#url
|
||||
padding 8px 12px
|
||||
|
|
@ -6,13 +6,3 @@
|
|||
color #fff
|
||||
background #222e40
|
||||
border-radius 4px
|
||||
|
||||
table
|
||||
.name
|
||||
font-weight bold
|
||||
|
||||
.name
|
||||
.type
|
||||
.optional
|
||||
font-family Consolas, 'Courier New', Courier, Monaco, monospace
|
||||
|
||||
|
|
|
|||
|
|
@ -1,63 +1,30 @@
|
|||
doctype html
|
||||
extends ../../layout.pug
|
||||
include ../mixins
|
||||
|
||||
mixin i18n(xs)
|
||||
each text, lang in xs
|
||||
span(class=`i18n ${lang}`)= text
|
||||
block title
|
||||
| #{endpoint} | Misskey API
|
||||
|
||||
mixin table(params)
|
||||
table
|
||||
thead: tr
|
||||
th Name
|
||||
th Type
|
||||
th Optional
|
||||
th Description
|
||||
tbody
|
||||
each param in params
|
||||
tr
|
||||
td.name= param.name
|
||||
td.type
|
||||
if param.kind == 'id'
|
||||
| #{param.type} (
|
||||
a(href=`/docs/api/entities/${param.entity}`)= param.entity
|
||||
| ID)
|
||||
else if param.kind == 'entity'
|
||||
| #{param.type} (
|
||||
a(href=`/docs/api/entities/${param.entity}`)= param.entity
|
||||
| )
|
||||
else if param.kind == 'object'
|
||||
| #{param.type} (
|
||||
a(href=`#${param.defName}`)= param.defName
|
||||
| )
|
||||
else
|
||||
= param.type
|
||||
td.optional= param.optional.toString()
|
||||
td.desc: +i18n(param.desc)
|
||||
block meta
|
||||
link(rel="stylesheet" href="/assets/docs/api/endpoints/style.css")
|
||||
|
||||
html
|
||||
head
|
||||
meta(charset="UTF-8")
|
||||
title #{endpoint} | Misskey API
|
||||
link(rel="stylesheet" href="/assets/docs/api/endpoints/style.css")
|
||||
block main
|
||||
h1= endpoint
|
||||
|
||||
body
|
||||
main
|
||||
h1= endpoint
|
||||
p#url= url
|
||||
|
||||
p#url= url
|
||||
p#desc: +i18n(desc)
|
||||
|
||||
p#desc: +i18n(desc)
|
||||
section
|
||||
h2 Params
|
||||
+propTable(params)
|
||||
|
||||
section
|
||||
h2 Params
|
||||
+table(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
|
||||
+table(paramDef.params)
|
||||
|
||||
section
|
||||
h2 Response
|
||||
+table(res)
|
||||
section
|
||||
h2 Response
|
||||
+propTable(res)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue