给你的Egg来一打SwaggerUi(可测试的接口文档,问你心不心动)

<img width="100" src="https://user-gold-cdn.xitu.io...;h=128&f=png&s=7630"/>javascript

Egg.js 路由装饰器,让你的开发更敏捷~
Lady and gentleman,让咱们庆祝 蛋壳 v1.0.4 版本的发布~

具体的使用方式请查看文档java

该新版本主要集成了swagger-ui,让咱们来秀上一波:git

import { Controller } from 'egg';
import { Post, IgnoreJwtAll, Description, TagsAll,
         Parameters, Responses } from 'egg-shell-decorators';

const USER_SCHEMA = {
  type: 'object',
  properties: {
    name: { type: 'string', description: '姓名' },
    phone: { type: 'string', description: '手机号码' },
    age: { type: 'integer', format: 'int32', description: '年龄' }
  }
};

@TagsAll('用户')
@IgnoreJwtAll
export default class SubOrderController extends Controller {

  @Post('/')
  @Description('建立用户')
  @Parameters([
    { name: 'body', in: 'body', required: true, schema: USER_SCHEMA }
  ])
  @Responses(USER_SCHEMA)
  public listUser({ body: { name, phone, age } }) {
    return { name, phone, age };
  }

}

上面代码会生成如下的文档:
github

可测试的噢!阿~这是心动的感受~typescript

以为上面的代码侵入性太强?没问题,路由映射帮你搞定:shell

// app/controller/user.ts
import { Controller } from 'egg';
import { Post, IgnoreJwtAll, TagsAll } from 'egg-shell-decorators';

@TagsAll('用户')
@IgnoreJwtAll
export default class UserController extends Controller {

  @Post('/')
  public listUser({ body: { name, phone, age } }) {
    return { name, phone, age };
  }

}
// swagger/user.json
{
  "/": {
    "post": {
      "description": "建立用户",
      "parameters": [
        { "name": "body", "in": "body", "required": true, "schema": { "$ref": "User" } }
      ],
      "responses": { "type": "object", "schema": { "$ref": "User" } }
    }
  }
}
具体的使用方式请查看 文档

以为不错就请做者喝杯咖啡(速溶)️☕️


给个小星星也是能够的~😘json

加入小组来面基~

因为本人不多上QQ,因此建的是微信群,而微信群码很快就失效,因此想进交流群的小伙伴加我微信噢~我拉你进群,欢迎大佬们加入😁

相关文章
相关标签/搜索