How to use the koa-joi-router.Joi.array 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
return this.db().table('pets').update(pet).run();
   }
};


const getPetByStatus = {
   method: 'put',
   path: '/pet',
   meta: {
      friendlyName: 'Find pets by status'
   },
   validate: {
      type: 'json',
      query: {
         status: t.array()
            .description('Status values that need to be considered for filter')
            .items(t.string())
            .min(1)        // At least 1 should be provided
            .single()      // If only one is provided, wrap it in an array
      },
      output: {
        200: {
          body: t.array().items(Pet.requiredKeys('id', 'status')),
          header: {
            'Content-Type': t.string()
          }
        }
      }
   },
   *handler () {
      const query = this.request.query;
github a-s-o / koa-docs / example / routes / store.js View on Github external
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.')
        }
      }
   },
   *handler () {
      // This route does not have any validations
      return this.db().table('store')
         .groupBy('statusCode')
         .map('quantity')
github a-s-o / koa-docs / example / routes / pets.js View on Github external
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'
   },
   validate: {
      type: 'json',
      body: Pet

koa-joi-router

Configurable, input validated routing for koa.

MIT
Latest version published 3 years ago

Package Health Score

51 / 100
Full package analysis