How to use the koa-joi-router.Joi.object function in koa-joi-router

To help you get started, we’ve selected a few koa-joi-router examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github a-s-o / koa-docs / example / routes / pets.js View on Github external
'use strict';

const t = require('koa-joi-router').Joi;

const Category = t.object().label('Category').keys({
   id: t.number(),
   name: t.string()
});

const Tag = t.object().label('Tag').keys({
   id: t.number(),
   name: t.string()
});

const Pet = t.object().label('Pet').keys({
   id: t.number().optional(),
   name: t.string().required(),
   category: Category,
   tags: t.array().items(Tag),
   photoUrls: t.array().items(t.string()).required(),
   status: t.string()
      .valid(['available', 'pending', 'sold'])
      .description('pet status in the store')
});

const createPet = {
   method: 'post',
   path: '/pet',
   meta: {
      friendlyName: 'Add pet',
      description: 'Add a new pet to the store'
github interledgerjs / rafiki / src / services / admin-api.ts View on Github external
method: 'get',
      path: '/alerts',
      handler: async (ctx: Context) => ctx.body = { alerts: this.app.alerts.getAlerts() }
    })
    router.route({
      method: 'get',
      path: '/balance',
      handler: async (ctx: Context) => ctx.body = this.app.getBalances()
    })
    router.route({
      method: 'post',
      path: '/peer',
      validate: {
        body: {
          peerInfo: Joi.object().required(),
          endpointInfo: Joi.object().required()
        },
        type: 'json'
      },
      handler: async (ctx: Context) => {
        const peerInfo = ctx.request.body['peerInfo']
        const endpointInfo = ctx.request.body['endpointInfo']
        await this.app.addPeer(peerInfo, endpointInfo, true)
        await this._auth.generateAuthToken(peerInfo.id)
        ctx.response.status = 204
      }
    })
    router.route({
      method: 'get',
      path: '/peer',
      handler: async (ctx: Context) => ctx.body = this.app.connector.getPeerList()
    })
github a-s-o / koa-docs / example / routes / store.js View on Github external
* Returns a map of status codes to quantities
      `
   },
   validate: {
      output: {
        200: {
          body: {
            available: Quantity.description('Pets available for sale'),
            pending: Quantity.description('# of pets awaiting processing'),
            sold: Quantity.description('# of pets sold')
          }
        },
        400: {
          body: {
            code: t.number().integer().min(0).max(100).default(0).description('Code to explain the response.'),
            errors: t.object().keys({
              name: {
                message: t.string().required().default('Some pet has no name!').description('Thrown when some pets has no name.')
              }
            }),
            tags: t.array().items(t.object().keys({
              label: t.string().example('Hello').example('World'),
              signal: t.array().items(t.string())
            })),
            error: t.string().valid('Pets not found!').description('Pets not found!')
          }
        },
        500: {
          body: t.string().default('Server Internal Error.')
        }
      }
   },
github interledgerjs / rafiki / src / services / admin-api.ts View on Github external
router.route({
      method: 'get',
      path: '/alerts',
      handler: async (ctx: Context) => ctx.body = { alerts: this.app.alerts.getAlerts() }
    })
    router.route({
      method: 'get',
      path: '/balance',
      handler: async (ctx: Context) => ctx.body = this.app.getBalances()
    })
    router.route({
      method: 'post',
      path: '/peer',
      validate: {
        body: {
          peerInfo: Joi.object().required(),
          endpointInfo: Joi.object().required()
        },
        type: 'json'
      },
      handler: async (ctx: Context) => {
        const peerInfo = ctx.request.body['peerInfo']
        const endpointInfo = ctx.request.body['endpointInfo']
        await this.app.addPeer(peerInfo, endpointInfo, true)
        await this._auth.generateAuthToken(peerInfo.id)
        ctx.response.status = 204
      }
    })
    router.route({
      method: 'get',
      path: '/peer',
      handler: async (ctx: Context) => ctx.body = this.app.connector.getPeerList()
github a-s-o / koa-docs / example / routes / store.js View on Github external
'use strict';

const t = require('koa-joi-router').Joi;

const Order = t.object().label('Order').keys({
   id: t.number(),
   petId: t.number(),
   quantity: t.number(),
   shipDate: t.date(),
   status: t.string().valid(['placed', 'approved', 'delivered']),
   complete: t.boolean()
});

const Quantity = t.number().integer().label('Quantity');

const storeInventory = {
   method: 'get',
   path: '/inventory',
   meta: {
      friendlyName: 'Store inventory',
      description: 'Returns pet inventories by status',

koa-joi-router

Configurable, input validated routing for koa.

MIT
Latest version published 3 years ago

Package Health Score

51 / 100
Full package analysis