egg-controller icon indicating copy to clipboard operation
egg-controller copied to clipboard

生成 open api 时,能自定义 Request 对象的名称,且能输出字段的 description

Open vfasky opened this issue 5 years ago • 2 comments

自定义 Request 对象的名称

在 validateMetaInfo 增加 schemaName 字段,用于解决 Requestobject 时, 名称总是 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';
  }

vfasky avatar Dec 16 '19 06:12 vfasky

Codecov Report

Merging #17 into master will increase coverage by 1.47%. The diff coverage is 0%.

Impacted file tree graph

@@            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.

codecov-io avatar Dec 16 '19 06:12 codecov-io

validateMetaInfo 的数据是对齐 https://github.com/node-modules/parameter 这个库的,其实可以使用 OAS3 的定义来替代,用 schemas 那个属性,手写或者通过这个模块内的 ts 编译插件

zhang740 avatar Dec 29 '19 05:12 zhang740