Skip to content

Commit

Permalink
Style(mock): change swagger config to better fit REST api
Browse files Browse the repository at this point in the history
* fix fullscreen doesn't work bug
* use global directive by default
* add support to simulate request time
* promise -> async/await
* update package.json dependencies
  • Loading branch information
Armour committed Jun 20, 2019
1 parent d7839b9 commit 439ecec
Show file tree
Hide file tree
Showing 33 changed files with 401 additions and 364 deletions.
20 changes: 13 additions & 7 deletions mock/articles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ export const getArticle = (req: Request, res: Response) => {
if (article.id.toString() === id) {
return res.json({
code: 20000,
data: article
data: {
article
}
})
}
}
Expand All @@ -68,21 +70,25 @@ export const getArticle = (req: Request, res: Response) => {
}

export const createArticle = (req: Request, res: Response) => {
const { data } = req.body
const { article } = req.body
return res.json({
code: 20000,
data
data: {
article
}
})
}

export const updateArticle = (req: Request, res: Response) => {
const { id } = req.params
const { data } = req.body
for (const article of articleList) {
if (article.id.toString() === id) {
const { article } = req.body
for (const v of articleList) {
if (v.id.toString() === id) {
return res.json({
code: 20000,
data
data: {
article
}
})
}
}
Expand Down
26 changes: 12 additions & 14 deletions mock/role/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ const roles: IRoleData[] = [
export const getRoles = (req: Request, res: Response) => {
return res.json({
code: 20000,
data: roles
data: {
total: roles.length,
items: roles
}
})
}

Expand All @@ -52,19 +55,12 @@ export const createRole = (req: Request, res: Response) => {
}

export const updateRole = (req: Request, res: Response) => {
const { id } = req.params
const { data } = req.body
for (const role of roles) {
if (role.key === id) {
return res.json({
code: 20000,
data
})
}
}
const { role } = req.body
return res.json({
code: 70001,
message: 'Role not found'
code: 20000,
data: {
role
}
})
}

Expand All @@ -77,6 +73,8 @@ export const deleteRole = (req: Request, res: Response) => {
export const getRoutes = (req: Request, res: Response) => {
return res.json({
code: 20000,
data: routes
data: {
routes
}
})
}
56 changes: 41 additions & 15 deletions mock/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ paths:
security:
- AccessTokenAuth: []
parameters:
- name: data
- name: article
in: query
required: true
description: The data for new article.
Expand All @@ -114,7 +114,10 @@ paths:
type: integer
format: int32
data:
$ref: '#/components/schemas/Article'
type: object
properties:
article:
$ref: '#/components/schemas/Article'
401:
$ref: '#/components/responses/Unauthorized'
/articles/{id}:
Expand Down Expand Up @@ -146,7 +149,10 @@ paths:
type: integer
format: int32
data:
$ref: '#/components/schemas/Article'
type: object
properties:
article:
$ref: '#/components/schemas/Article'
401:
$ref: '#/components/responses/Unauthorized'
404:
Expand All @@ -167,8 +173,9 @@ paths:
schema:
type: integer
format: int64
- name: data
- name: article
in: query
required: true
description: data for the updated article.
schema:
$ref: '#/components/schemas/Article'
Expand All @@ -184,7 +191,10 @@ paths:
type: integer
format: int32
data:
$ref: '#/components/schemas/Article'
type: object
properties:
article:
$ref: '#/components/schemas/Article'
401:
$ref: '#/components/responses/Unauthorized'
404:
Expand Down Expand Up @@ -226,7 +236,7 @@ paths:
- articles
summary: Get Pageviews Data
description: Return a list of pageviews for each platforms.
operationId: getPageViews
operationId: getPageviews
responses:
200:
description: OK
Expand Down Expand Up @@ -310,7 +320,7 @@ paths:
security:
- AccessTokenAuth: []
parameters:
- name: data
- name: role
in: query
required: true
description: The data for new role.
Expand Down Expand Up @@ -352,8 +362,9 @@ paths:
schema:
type: integer
format: int64
- name: data
- name: role
in: query
required: true
description: The data for updated role.
schema:
$ref: '#/components/schemas/Role'
Expand All @@ -369,7 +380,10 @@ paths:
type: integer
format: int32
data:
$ref: '#/components/schemas/Role'
type: object
properties:
role:
$ref: '#/components/schemas/Role'
401:
$ref: '#/components/responses/Unauthorized'
404:
Expand Down Expand Up @@ -424,7 +438,10 @@ paths:
type: integer
format: int32
data:
$ref: '#/components/schemas/Role/properties/routes'
type: object
properties:
routes:
$ref: '#/components/schemas/Role/properties/routes'
/users:
get:
tags:
Expand Down Expand Up @@ -468,7 +485,7 @@ paths:
description: This can only be done by the logged in user.
operationId: register
parameters:
- name: data
- name: user
in: query
required: true
description: The data for created user.
Expand Down Expand Up @@ -581,7 +598,10 @@ paths:
type: integer
format: int32
data:
$ref: '#/components/schemas/User'
type: object
properties:
user:
$ref: '#/components/schemas/User'
400:
$ref: '#/components/responses/InvalidUser'
401:
Expand All @@ -603,7 +623,7 @@ paths:
description: Name that need to be updated.
schema:
type: string
- name: data
- name: user
in: query
required: true
description: The data for updated user.
Expand All @@ -621,7 +641,10 @@ paths:
type: integer
format: int32
data:
$ref: '#/components/schemas/User'
type: object
properties:
user:
$ref: '#/components/schemas/User'
400:
$ref: '#/components/responses/InvalidUser'
401:
Expand Down Expand Up @@ -681,7 +704,10 @@ paths:
type: integer
format: int32
data:
$ref: '#/components/schemas/User'
type: object
properties:
user:
$ref: '#/components/schemas/User'
401:
$ref: '#/components/responses/Unauthorized'
components:
Expand Down
18 changes: 12 additions & 6 deletions mock/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ export const getUserInfo = (req: Request, res: Response) => {
// Mock data based on access token
return res.json({
code: 20000,
data: req.header('X-Access-Token') == 'admin-token' ? userList[0] : userList[1]
data: {
user: req.header('X-Access-Token') == 'admin-token' ? userList[0] : userList[1]
}
})
}

Expand All @@ -100,7 +102,9 @@ export const getUserByName = (req: Request, res: Response) => {
if (user.username === username) {
return res.json({
code: 20000,
data: user
data: {
user
}
})
}
}
Expand All @@ -112,12 +116,14 @@ export const getUserByName = (req: Request, res: Response) => {

export const updateUser = (req: Request, res: Response) => {
const { username } = req.params
const { data } = req.body
for (const user of userList) {
if (user.username === username) {
const { user } = req.body
for (const v of userList) {
if (v.username === username) {
return res.json({
code: 20000,
data
data: {
user
}
})
}
}
Expand Down
24 changes: 13 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"clipboard": "^2.0.4",
"codemirror": "^5.47.0",
"cors": "^2.8.5",
"driver.js": "^0.9.6",
"driver.js": "^0.9.7",
"echarts": "^4.2.1",
"element-ui": "2.8.2",
"faker": "^4.1.0",
Expand All @@ -28,6 +28,7 @@
"js-cookie": "^2.2.0",
"jsonlint": "^1.6.3",
"jszip": "^3.2.1",
"lodash": "^4.17.11",
"morgan": "^1.9.1",
"normalize.css": "^8.0.1",
"nprogress": "^0.2.0",
Expand All @@ -36,14 +37,14 @@
"screenfull": "^4.2.0",
"script-loader": "^0.7.2",
"sortablejs": "^1.9.0",
"tinymce": "^5.0.7",
"tui-editor": "^1.4.2",
"tinymce": "^5.0.8",
"tui-editor": "^1.4.3",
"vue": "^2.6.10",
"vue-class-component": "^7.1.0",
"vue-count-to": "^1.0.13",
"vue-i18n": "^8.11.2",
"vue-image-crop-upload": "^2.5.0",
"vue-property-decorator": "^8.1.1",
"vue-property-decorator": "^8.2.1",
"vue-router": "^3.0.6",
"vue-svgicon": "^3.2.6",
"vue2-dropzone": "^3.5.9",
Expand All @@ -63,9 +64,10 @@
"@types/express": "^4.17.0",
"@types/faker": "^4.1.5",
"@types/file-saver": "^2.0.1",
"@types/jest": "^24.0.13",
"@types/jest": "^24.0.15",
"@types/js-cookie": "^2.2.2",
"@types/jszip": "^3.1.6",
"@types/lodash": "^4.14.134",
"@types/morgan": "^1.7.35",
"@types/nprogress": "^0.2.0",
"@types/sortablejs": "^1.7.2",
Expand All @@ -78,29 +80,29 @@
"@vue/cli-plugin-pwa": "^3.8.0",
"@vue/cli-plugin-typescript": "^3.8.1",
"@vue/cli-plugin-unit-jest": "^3.8.0",
"@vue/cli-service": "^3.8.0",
"@vue/cli-service": "^3.8.4",
"@vue/eslint-config-standard": "^4.0.0",
"@vue/eslint-config-typescript": "^4.0.0",
"@vue/test-utils": "^1.0.0-beta.29",
"babel-core": "^7.0.0-bridge.0",
"babel-eslint": "^10.0.1",
"babel-eslint": "^10.0.2",
"concurrently": "^4.1.0",
"eslint": "^5.16.0",
"eslint-plugin-vue": "^5.2.2",
"fibers": "^4.0.1",
"jest": "^24.8.0",
"lint-staged": "^8.2.0",
"lint-staged": "^8.2.1",
"sass": "^1.21.0",
"sass-loader": "^7.1.0",
"style-resources-loader": "^1.2.1",
"swagger-routes-express": "^3.0.1",
"ts-jest": "^24.0.2",
"ts-node-dev": "^1.0.0-pre.39",
"typescript": "3.5.1",
"ts-node-dev": "^1.0.0-pre.40",
"typescript": "3.5.2",
"vue-cli-plugin-element": "^1.0.1",
"vue-cli-plugin-style-resources-loader": "^0.1.3",
"vue-template-compiler": "^2.6.10",
"webpack": "^4.33.0"
"webpack": "^4.34.0"
},
"bugs": {
"url": "https://github.com/armour/vue-typescript-admin-template/issues"
Expand Down
Loading

0 comments on commit 439ecec

Please sign in to comment.