summaryrefslogtreecommitdiff
path: root/src/web/docs/api/endpoints
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2017-12-15 00:23:45 +0900
committersyuilo <syuilotan@yahoo.co.jp>2017-12-15 00:23:45 +0900
commitd6ec5f2fe13bb1e3f4316f04591bf419f587c2bd (patch)
treee6c027442f2cbc285391e34f927ab6d3f9eb2e1a /src/web/docs/api/endpoints
parent:v: (diff)
downloadmisskey-d6ec5f2fe13bb1e3f4316f04591bf419f587c2bd.tar.gz
misskey-d6ec5f2fe13bb1e3f4316f04591bf419f587c2bd.tar.bz2
misskey-d6ec5f2fe13bb1e3f4316f04591bf419f587c2bd.zip
:v:
Diffstat (limited to '')
-rw-r--r--src/web/docs/api/endpoints/posts/create.yaml8
-rw-r--r--src/web/docs/api/endpoints/style.styl12
-rw-r--r--src/web/docs/api/endpoints/view.pug75
-rw-r--r--src/web/docs/api/gulpfile.ts (renamed from src/web/docs/api/endpoints/gulpfile.ts)78
4 files changed, 95 insertions, 78 deletions
diff --git a/src/web/docs/api/endpoints/posts/create.yaml b/src/web/docs/api/endpoints/posts/create.yaml
index 498a99159c..5e2307dab4 100644
--- a/src/web/docs/api/endpoints/posts/create.yaml
+++ b/src/web/docs/api/endpoints/posts/create.yaml
@@ -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"
diff --git a/src/web/docs/api/endpoints/style.styl b/src/web/docs/api/endpoints/style.styl
index ab74e100b5..07fb7ec2a3 100644
--- a/src/web/docs/api/endpoints/style.styl
+++ b/src/web/docs/api/endpoints/style.styl
@@ -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
-
diff --git a/src/web/docs/api/endpoints/view.pug b/src/web/docs/api/endpoints/view.pug
index 841ca8b3f9..cebef9fa5b 100644
--- a/src/web/docs/api/endpoints/view.pug
+++ b/src/web/docs/api/endpoints/view.pug
@@ -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)
diff --git a/src/web/docs/api/endpoints/gulpfile.ts b/src/web/docs/api/gulpfile.ts
index e375447c55..05567b6233 100644
--- a/src/web/docs/api/endpoints/gulpfile.ts
+++ b/src/web/docs/api/gulpfile.ts
@@ -10,12 +10,15 @@ import * as pug from 'pug';
import * as yaml from 'js-yaml';
import * as mkdirp from 'mkdirp';
-import config from './../../../../conf';
+import config from './../../../conf';
+
+const kebab = string => string.replace(/([a-z])([A-Z])/g, '$1-$2').replace(/\s+/g, '-').toLowerCase();
const parseParam = param => {
- const id = param.type.match(/^id\((.+?)\)/);
+ const id = param.type.match(/^id\((.+?)\)|^id/);
const entity = param.type.match(/^entity\((.+?)\)/);
const isObject = /^object/.test(param.type);
+ const isDate = /^date/.test(param.type);
const isArray = /\[\]$/.test(param.type);
if (id) {
param.kind = 'id';
@@ -36,30 +39,53 @@ const parseParam = param => {
if (isObject) {
param.kind = 'object';
}
+ if (isDate) {
+ param.kind = 'date';
+ param.type = 'string';
+ if (isArray) {
+ param.type += '[]';
+ }
+ }
return param;
};
+const sortParams = params => {
+ params.sort((a, b) => {
+ if (a.name < b.name)
+ return -1;
+ if (a.name > b.name)
+ return 1;
+ return 0;
+ });
+ return params;
+};
+
const extractDefs = params => {
- const defs = [];
+ let defs = [];
params.forEach(param => {
if (param.def) {
defs.push({
name: param.defName,
- params: param.def.map(p => parseParam(p))
+ params: sortParams(param.def.map(p => parseParam(p)))
});
const childDefs = extractDefs(param.def);
- defs.concat(childDefs);
+ defs = defs.concat(childDefs);
}
});
return defs;
};
-gulp.task('doc:endpoints', () => {
+gulp.task('doc:api', [
+ 'doc:api:endpoints',
+ 'doc:api:entities'
+]);
+
+gulp.task('doc:api:endpoints', () => {
glob('./src/web/docs/api/endpoints/**/*.yaml', (globErr, files) => {
if (globErr) {
console.error(globErr);
@@ -72,10 +98,11 @@ gulp.task('doc:endpoints', () => {
endpoint: ep.endpoint,
url: `${config.api_url}/${ep.endpoint}`,
desc: ep.desc,
- params: ep.params.map(p => parseParam(p)),
+ params: sortParams(ep.params.map(p => parseParam(p))),
paramDefs: extractDefs(ep.params),
- res: ep.res.map(p => parseParam(p)),
- resDefs: extractDefs(ep.res)
+ res: sortParams(ep.res.map(p => parseParam(p))),
+ resDefs: extractDefs(ep.res),
+ kebab
};
pug.renderFile('./src/web/docs/api/endpoints/view.pug', vars, (renderErr, html) => {
if (renderErr) {
@@ -94,3 +121,36 @@ gulp.task('doc:endpoints', () => {
});
});
});
+
+gulp.task('doc:api:entities', () => {
+ glob('./src/web/docs/api/entities/**/*.yaml', (globErr, files) => {
+ if (globErr) {
+ console.error(globErr);
+ return;
+ }
+ files.forEach(file => {
+ const entity = yaml.safeLoad(fs.readFileSync(file, 'utf-8'));
+ const vars = {
+ name: entity.name,
+ desc: entity.desc,
+ props: sortParams(entity.props.map(p => parseParam(p))),
+ propDefs: extractDefs(entity.props),
+ kebab
+ };
+ pug.renderFile('./src/web/docs/api/entities/view.pug', vars, (renderErr, html) => {
+ if (renderErr) {
+ console.error(renderErr);
+ return;
+ }
+ const htmlPath = `./built/web/docs/api/entities/${kebab(entity.name)}.html`;
+ mkdirp(path.dirname(htmlPath), (mkdirErr) => {
+ if (mkdirErr) {
+ console.error(mkdirErr);
+ return;
+ }
+ fs.writeFileSync(htmlPath, html, 'utf-8');
+ });
+ });
+ });
+ });
+});