Skip to content

Commit

Permalink
feat: update schema and controller, auto swagger generation
Browse files Browse the repository at this point in the history
  • Loading branch information
ruiming committed Mar 7, 2018
1 parent 4cfb3b0 commit 117349c
Show file tree
Hide file tree
Showing 17 changed files with 907 additions and 67 deletions.
291 changes: 291 additions & 0 deletions doc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,291 @@
{
"swagger": "2.0",
"info": {
"title": "TinyLog API Document",
"description": "API Document for TinyLog-Service",
"version": "0.1.0"
},
"host": "api.example.com",
"basePath": "/v1",
"schemes": ["https"],
"paths": {
"/log/initialize": {
"post": {
"description": "初次连接需要进行该请求,服务端会进行 Cookie 处理,前端无需关心返回值",
"tags": ["log"],
"parameters": [
{
"in": "body",
"name": "body",
"schema": {
"$ref": "#/definitions/IInitialize"
}
}
],
"responses": {
"200": {
"description": "ok"
}
}
}
},
"/log/page": {
"post": {
"description":
"\n 当前页面的用户行为数据,如果有的话需要把前一个页面的 PageId 传回,没有 PageId 视这个页面为入口页面\n 会返回 PageId,该 PageId 在发送该页面的数据资源信息的时候需要带上,以及跳转下一个页面的时候要用\n ",
"tags": ["log"],
"parameters": [
{
"in": "body",
"name": "body",
"schema": {
"$ref": "#/definitions/IPageInfo"
}
}
],
"responses": {
"200": {
"description": "ok"
}
}
}
},
"/log/assets": {
"post": {
"description": "当前页面的所有资源数据,需要把前面的 PageId 传回来",
"tags": ["log"],
"parameters": [
{
"in": "body",
"name": "body",
"schema": {
"$ref": "#/definitions/IAssetsInfo"
}
}
],
"responses": {
"200": {
"description": "ok"
}
}
}
},
"/log/exit": {
"post": {
"description": "网页退出,把当前哪个页面发送过来,以及退出时间",
"tags": ["log"],
"parameters": [
{
"in": "body",
"name": "body",
"schema": {
"$ref": "#/definitions/IExit"
}
}
],
"responses": {
"200": {
"description": "ok"
}
}
}
},
"/user/login": {
"post": {
"description": "登录,后续认证依赖 Cookie 里处理,前端不用做任何处理",
"tags": ["user"],
"parameters": [
{
"in": "body",
"name": "body",
"schema": {
"$ref": "#/definitions/IUserLogin"
}
}
],
"responses": {
"200": {
"description": "ok"
}
}
}
},
"/user/register": {
"post": {
"description": "注册,注册后即自动登录,后续认证依赖 Cookie 里处理,前端不用做任何处理",
"tags": ["user"],
"parameters": [
{
"in": "body",
"name": "body",
"schema": {
"$ref": "#/definitions/IUserRegister"
}
}
],
"responses": {
"200": {
"description": "ok"
}
}
}
}
},
"tags": [
{
"name": "log"
},
{
"name": "user"
}
],
"definitions": {
"IInitialize": {
"type": "object",
"properties": {
"referer": {
"type": "string"
},
"lang": {
"type": "string"
},
"ua": {
"type": "string"
},
"os": {
"type": "string"
}
},
"required": ["lang", "os", "referer", "ua"]
},
"IPageInfo": {
"type": "object",
"properties": {
"url": {
"type": "string"
},
"startTime": {
"type": "number"
},
"prePageId": {
"type": "number"
},
"referrer": {
"type": "string"
},
"loadPage": {
"type": "number"
},
"domReady": {
"type": "number"
},
"redirect": {
"type": "number"
},
"lookupDomain": {
"type": "number"
},
"ttfb": {
"type": "number"
},
"request": {
"type": "number"
},
"tcp": {
"type": "number"
},
"loadEvent": {
"type": "number"
}
},
"required": [
"domReady",
"loadEvent",
"loadPage",
"lookupDomain",
"redirect",
"referrer",
"request",
"startTime",
"tcp",
"ttfb",
"url"
]
},
"IAssetsInfo": {
"type": "object",
"properties": {
"pageId": {
"type": "number"
},
"assets": {
"type": "array",
"items": {
"type": "object",
"properties": {
"entryType": {
"type": "string"
},
"initiatorType": {
"type": "number"
},
"name": {
"type": "string"
},
"redirect": {
"type": "number"
},
"lookupDomain": {
"type": "number"
},
"request": {
"type": "number"
},
"duration": {
"type": "number"
}
},
"required": ["duration", "entryType", "initiatorType", "lookupDomain", "name", "redirect", "request"]
}
}
},
"required": ["assets", "pageId"]
},
"IExit": {
"type": "object",
"properties": {
"pageId": {
"type": "number"
},
"exitTime": {
"type": "number"
}
},
"required": ["exitTime", "pageId"]
},
"IUserLogin": {
"type": "object",
"properties": {
"email": {
"type": "string"
},
"password": {
"type": "string"
}
},
"required": ["email", "password"]
},
"IUserRegister": {
"type": "object",
"properties": {
"email": {
"type": "string"
},
"password": {
"type": "string"
}
},
"required": ["email", "password"]
}
}
}
14 changes: 12 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,41 @@
"test": "cross-env NODE_ENV=test npm run test:run",
"report-coverage": "cross-env NODE_ENV=test nyc report --reporter=text-lcov > coverage.lcov && codecov",
"lint": "tslint --fix --project tsconfig.json '{src,test}/**/*.ts'",
"migration": "ts-node ./node_modules/.bin/typeorm migrations:generate -n Update",
"precommit": "lint-staged",
"commit": "git-cz",
"commitmsg": "validate-commit-msg",
"version": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0 && git add CHANGELOG.md"
},
"dependencies": {
"config": "^1.30.0",
"kcors": "^2.2.1",
"koa": "^2.5.0",
"koa-bodyparser": "^4.2.0",
"koa-jwt": "^3.3.0",
"koa-logger": "^3.1.0",
"koa-router": "^7.1.1",
"mysql": "^2.15.0",
"reflect-metadata": "^0.1.12",
"routing-controllers": "^0.7.6",
"typedi": "^0.7.0",
"routing-controllers": "^0.7.7",
"typedi": "^0.7.1",
"typeorm": "^0.1.13"
},
"devDependencies": {
"@types/glob": "^5.0.35",
"@types/koa": "^2.0.44",
"@types/koa-logger": "^3.1.0",
"@types/mocha": "^2.2.41",
"@types/node": "^9.4.6",
"@types/power-assert": "^1.4.29",
"@types/supertest": "^2.0.0",
"@types/swagger-schema-official": "^2.0.9",
"codecov": "^3.0.0",
"conventional-changelog-cli": "^1.3.4",
"cross-env": "^5.0.5",
"cz-conventional-changelog": "^2.0.0",
"espower-typescript": "^8.0.2",
"glob": "^7.1.2",
"husky": "^0.14.3",
"lint-staged": "^7.0.0",
"mocha": "^5.0.0",
Expand All @@ -51,11 +59,13 @@
"prettier": "1.11.0",
"source-map-support": "^0.5.2",
"supertest": "^3.0.0",
"swagger-schema-official": "^2.0.0-bab6bed",
"ts-node": "^5.0.0",
"tslint": "^5.4.3",
"tslint-config-prettier": "^1.6.0",
"tslint-eslint-rules": "^5.1.0",
"typescript": "^2.4.0",
"typescript-json-schema": "^0.21.0",
"validate-commit-msg": "^2.12.2"
},
"lint-staged": {
Expand Down
35 changes: 35 additions & 0 deletions src/controllers/Log.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Service } from 'typedi';
import { JsonController, Post, Body } from 'routing-controllers';
import { IInitialize, IPageInfo, IAssetsInfo, IExit } from '../interfaces/Log';
import { Description } from '../utils/docHelper';

@Service()
@JsonController('/log')
export class LogController {
@Description('初次连接需要进行该请求,服务端会进行 Cookie 处理,前端无需关心返回值')
@Post('/initialize')
async initialize(@Body() body: IInitialize) {
// todo
}

@Description(`
当前页面的用户行为数据,如果有的话需要把前一个页面的 PageId 传回,没有 PageId 视这个页面为入口页面
会返回 PageId,该 PageId 在发送该页面的数据资源信息的时候需要带上,以及跳转下一个页面的时候要用
`)
@Post('/page')
async pageInfo(@Body() body: IPageInfo) {
// todo
}

@Description('当前页面的所有资源数据,需要把前面的 PageId 传回来')
@Post('/assets')
async assetsInfo(@Body() body: IAssetsInfo) {
// todo
}

@Description('网页退出,把当前哪个页面发送过来,以及退出时间')
@Post('/exit')
async exit(@Body() body: IExit) {
// todo
}
}

0 comments on commit 117349c

Please sign in to comment.