Skip to content

Commit

Permalink
🚧 [tool-restful-api] feat: update example and templates
Browse files Browse the repository at this point in the history
  • Loading branch information
lemon-clown committed Aug 26, 2020
1 parent 55f5511 commit eea9d06
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 20 deletions.
2 changes: 1 addition & 1 deletion tools/restful-api/example/simple/app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ generate:
muteMissingModel: true
ignoredDataTypes:
- 'undefined'
schemaArgs:
additionalSchemaArgs:
ref: false
required: true

Expand Down
6 changes: 3 additions & 3 deletions tools/restful-api/example/simple/script/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ async function serve () {
projectDir,
'--log-level=debug',
'-s',
'schemas/answer',
'--api-config-path',
'api.yml',
'data/schemas',
'--config-path',
'app.yml',
]
console.log(chalk.gray('--> ' + args.join(' ')))
program.parse(args)
Expand Down
24 changes: 22 additions & 2 deletions tools/restful-api/example/simple/src/model/core/response/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,27 @@ export enum ResponseCode {
/**
* response result
*/
export interface ResponseResult<T = undefined> {
export interface ResponseResult<T = unknown> {
/**
* response code
* @default 200
*/
code: ResponseCode
/**
* response message
*/
message: string
/**
* response data
*/
result: T
}


/**
* response result
*/
export interface OptionalResponseResult<T = unknown> {
/**
* response code
* @default 200
Expand All @@ -32,7 +52,7 @@ export interface ResponseResult<T = undefined> {
/**
* 分页响应数据
*/
export interface PaginationResponseResult<T = undefined> extends ResponseResult<T> {
export interface PaginationResponseResult<T = unknown> extends ResponseResult<T> {
/**
* pagination info
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { ResponseResult } from '../../../core/response'
import { OptionalResponseResult, ResponseResult } from '../../../core/response'
import { User } from '../../user/user'


/**
* update current user information
*/
export interface UpdateCurrentUserRequestVo extends User {}
export type UpdateCurrentUserResponseVo = ResponseResult<undefined>
export type UpdateCurrentUserResponseVo = OptionalResponseResult<undefined>


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ module.exports = {
tsconfigRootDir: __dirname,
project: './tsconfig.json'
},
ignorePatterns: [
'ecosystem.config.js',
],
rules: {
},
ignorePatterns: [
]
}
5 changes: 4 additions & 1 deletion tools/restful-api/src/config/templates/simple/app.yml.hbs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
__globalOptions__:
encoding: {{{encoding}}}
logLevel: {{{lowerCase logLevel}}}
schemaRootPath: data/schemas
apiConfigPath:
- api.yml

# options for sub-command `generate`
generate:
clean: true
muteMissingModel: true
ignoredDataTypes:
- 'undefined'
schemaArgs:
additionalSchemaArgs:
ref: false
required: true

Expand Down
48 changes: 45 additions & 3 deletions tools/restful-api/src/config/templates/simple/package.json.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,61 @@
"version": "0.0.0",
"private": true,
"scripts": {
"build:schemas": "barusu-rapit generate . -C api.yml",
"serve:cli": "nodemon --exec \"yarn build:schemas && barusu-rapit serve . -C api.yml\"",
"build:schemas": "barusu-rapit generate . -c app.yml",
"serve:cli": "nodemon --exec \"yarn build:schemas && barusu-rapit serve . -c app.yml\"",
"serve:program": "nodemon --exec \"yarn build:schemas && node -r ts-node/register script/serve.ts\"",
"serve": "yarn serve:program"
"serve": "yarn serve:program",
"format": "barusu-sort-imports ."
},
"dependencies": {
"@barusu/tool-restful-api": "^{{{lowerCase templateVersion}}}"
},
"devDependencies": {
"@barusu/eslint-config": "^{{{lowerCase templateVersion}}}",
"@barusu/rollup-config": "^{{{lowerCase templateVersion}}}",
"@barusu/tool-sort-imports": "^{{{lowerCase templateVersion}}}",
"nodemon": "^1.19.1",
"ts-node": "^8.8.2",
"typescript": "^3.8.2"
},
"@barusu/tool-sort-imports": {
"pattern": [
"{src,test,__test__}/**/*.{ts,tsx}"
],
"moduleRanks": [
{
"regex": "^(react|vue|angular)(?:[/\\-][\\w\\-./]*)?$",
"rank": 1.1
},
{
"regex": "^[a-zA-Z\\d][\\w\\-.]*",
"rank": 1.3
},
{
"regex": "^@[a-zA-Z\\d][\\w\\-.]*\\/[a-zA-Z\\d][\\w\\-.]*",
"rank": 1.4
},
{
"regex": "^@\\/",
"rank": 2.1
},
{
"regex": "^(?:\\/|[a-zA-Z]:)",
"rank": 3.1
},
{
"regex": "^[.]{2}[\\/\\\\][^\\n]*",
"rank": 3.2
},
{
"regex": "^[.][\\/\\\\][^\\n]*",
"rank": 3.3
}
],
"indent": " ",
"quote": "'",
"semicolon": false,
"maxColumn": 80,
"logLevel": "verbose"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ async function serve () {
projectDir,
'--log-level=debug',
'-s',
'schemas/answer',
'--api-config-path',
'api.yml',
'data/schemas',
'--config-path',
'app.yml',
]
console.log(chalk.gray('--> ' + args.join(' ')))
program.parse(args)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,27 @@ export enum ResponseCode {
/**
* response result
*/
export interface ResponseResult<T = undefined> {
export interface ResponseResult<T = unknown> {
/**
* response code
* @default 200
*/
code: ResponseCode
/**
* response message
*/
message: string
/**
* response data
*/
result: T
}


/**
* response result
*/
export interface OptionalResponseResult<T = unknown> {
/**
* response code
* @default 200
Expand All @@ -32,7 +52,7 @@ export interface ResponseResult<T = undefined> {
/**
* Paginated response data
*/
export interface PaginationResponseResult<T = undefined> extends ResponseResult<T> {
export interface PaginationResponseResult<T = unknown> extends ResponseResult<T> {
/**
* pagination info
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"suppressImplicitAnyIndexErrors": true
},
"include": [
"src"
"src",
"script"
]
}

0 comments on commit eea9d06

Please sign in to comment.