egg-controller
egg-controller copied to clipboard
生成 open api 时,能自定义 Request 对象的名称,且能输出字段的 description
自定义 Request 对象的名称
在 validateMetaInfo 增加 schemaName 字段,用于解决 Request
为 object
时, 名称总是 GenType_
@route('POST /api/body', {
name: 'post with body: q',
validateMetaInfo: [
{
name: 'q',
rule: {
schemaName: 'ReqData',
type: 'object',
rule: {
a: {
type: 'string'
},
b: {
type: 'number'
}
}
}
}
]
})
post(q: { a: string, b: number }) {
return 'ok';
}
生成 open api 时,Request 属性输出 description
@route('/api/query', {
name: 'get with query: q',
validateMetaInfo: [
{
name: 'q',
rule: {
type: 'string',
description: 'query'
}
}
]
})
getQuery(q: string) {
return 'ok';
}
Codecov Report
Merging #17 into master will increase coverage by
1.47%
. The diff coverage is0%
.
@@ Coverage Diff @@
## master #17 +/- ##
==========================================
+ Coverage 78.45% 79.92% +1.47%
==========================================
Files 24 24
Lines 557 558 +1
Branches 71 73 +2
==========================================
+ Hits 437 446 +9
+ Misses 97 88 -9
- Partials 23 24 +1
Impacted Files | Coverage Δ | |
---|---|---|
lib/openapi/index.ts | 70.45% <0%> (+9.53%) |
:arrow_up: |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact)
,ø = not affected
,? = missing data
Powered by Codecov. Last update eb68643...04a0a34. Read the comment docs.
validateMetaInfo 的数据是对齐 https://github.com/node-modules/parameter 这个库的,其实可以使用 OAS3 的定义来替代,用 schemas 那个属性,手写或者通过这个模块内的 ts 编译插件