BenefitJS / benefit

BenefitJS base on koa.js, running in v8 runtime.
MIT License
0 stars 0 forks source link

benefit

BenefitJS base on koa.js, running in v8 runtime.

[![standard][standard-image]][standard-url]

Build Status codecov Dependency Status license Greenkeeper badge

The framework is mainly to solve the relationship document and service.

description

So how to write this document?

define model


const props = {
  id: Joi.number().integer().description('id'),
  phone: Joi.string().description('phone'),
  password: Joi.string().description('password')
}

const schema = Joi.object().keys(props).description('user info')

index

index: {
  path: '/users',
  method: 'get',
  tags: ['users'],
  summary: 'get users list',
  query: _.pick(props, ['phone']),
  output: {
    200: Joi.object().keys({
      result: Joi.array().items(props).description('users list')
    })
  }
}

create

create: {
  path: '/users',
  method: 'post',
  tags: ['users'],
  summary: 'create user',
  requestBody: {
    body: _.pick(props, ['phone', 'password']),
    required: ['phone', 'password']
  },
  output: {
    200: Joi.object().keys(props).description('result')
  }
}

show

show: {
  path: '/users/:id',
  method: 'get',
  tags: ['users'],
  summary: 'get user',
  params: _.pick(props, ['id']),
  output: {
    200: Joi.object().keys(props).description('result')
  }
}

update

update: {
  path: '/users/{id}',
  method: 'put',
  tags: ['users'],
  summary: 'update user',
  params: _.pick(props, ['id']),
  requestBody: {
    body: _.pick(props, ['phone'])
  },
  output: {
    200: Joi.array().items(Joi.number()).descript('result')
  }
}

destroy

destroy: {
  path: '/users/{id}',
  method: 'put',
  tags: ['users'],
  summary: 'destroy user',
  params: _.pick(props, ['id']),
  output: {
    200: Joi.number().descript('result')
  }
}

[standard-image]: https://cdn.rawgit.com/standard/standard/master/badge.svg [standard-url]: https://github.com/standard/standard