How to use the joi.object function in joi

To help you get started, we’ve selected a few joi 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 godaddy / timings / routes / v2 / post-routes.js View on Github external
function validateSchema(route, req, pu) {
  // Schema for request validation (extended in individual routes)

  // Add base schema
  const baseSchema = joi.object({
    sla: joi.object({
      pageLoadTime: joi.number().integer(),
      visualCompleteTime: joi.number().integer()
    }).length(1).required(),
    baseline: joi.object({
      days: joi.number().integer(),
      perc: joi.number().integer().max(100),
      padding: joi.number().min(1),
      src: joi.string().allow(''),
      aggField: joi.string().allow(''),
      searchUrl: joi.string().allow(''),
      incl: joi.object(),
      excl: joi.object()
    }),
    flags: joi.object({
      assertBaseline: joi.boolean(),
      assertRum: joi.boolean(),
      debug: joi.boolean(),
      esTrace: joi.boolean(),
      esCreate: joi.boolean(),
      passOnFailedAssert: joi.boolean()
github screwdriver-cd / screwdriver / plugins / jobs / metrics.js View on Github external
'use strict';

const boom = require('boom');
const joi = require('joi');
const { setDefaultTimeRange, validTimeRange } = require('../helper.js');
const MAX_DAYS = 180; // 6 months
const schema = require('screwdriver-data-schema');
const jobMetricListSchema = joi.array().items(joi.object());
const jobIdSchema = joi.reach(schema.models.job.base, 'id');

module.exports = () => ({
    method: 'GET',
    path: '/jobs/{id}/metrics',
    config: {
        description: 'Get build metrics for this job',
        notes: 'Returns list of build metrics for the given job',
        tags: ['api', 'jobs', 'metrics'],
        auth: {
            strategies: ['token'],
            scope: ['user', '!guest', 'pipeline']
        },
        plugins: {
            'hapi-swagger': {
                security: [{ token: [] }]
github HubSpotWebTeam / hs-node-api / test / schemas / page.js View on Github external
publish_date_local_time: joi.number(),
  publish_date_localized: joi.object(),
  publish_immediately: joi.boolean(),
  published_url: joi.string().allow(''),
  resolved_domain: joi.string().allow(''),
  screenshot_preview_taken_at: joi.number(),
  screenshot_preview_url: joi.string().allow(''),
  site_id: joi.number(),
  slug: joi.string().allow(''),
  state: joi.string().allow(''),
  subcategory: joi.string().allow(''),
  team_perms: joi.array().allow(null),
  template_path: joi.string().allow(''),
  template_path_for_render: joi.string().allow(''),
  title: joi.string().allow(''),
  translated_content: joi.object(),
  tweet_immediately: joi.boolean(),
  unpublished_at: joi.number(),
  updated: joi.number(),
  updated_by_id: joi.number().optional(),
  upsize_featured_image: joi.boolean(),
  url: joi.string().allow(''),
  use_featured_image: joi.boolean(),
  user_perms: joi.array().allow(null),
  views: joi.number(),
  widget_containers: joi.object(),
  widgetcontainers: joi.object(),
  widgets: joi.object()
});

const limit = joi
  .number()
github screwdriver-cd / screwdriver / plugins / events / metrics.js View on Github external
return event.getMetrics({
                        startTime,
                        endTime
                    });
                })
                .then(metrics => reply(metrics))
                .catch(err => reply(boom.boomify(err)));
        },
        response: {
            schema: eventMetricListSchema
        },
        validate: {
            params: {
                id: eventIdSchema
            },
            query: joi.object({
                startTime: joi.string().isoDate(),
                endTime: joi.string().isoDate()
            })
        }
    }
});
github krakenjs / hapi-openapi / lib / index.js View on Github external
const Package = require('../package.json');
const Joi = require('joi');
const Hoek = require('hoek');
const Caller = require('./caller');
const Path = require('path');
const Parser = require('swagger-parser');
const Utils = require('./utils');
const Routes = require('./routes');
const Yaml = require('js-yaml');
const Fs = require('fs');
const Util = require('util');

const CALLER_DIR = Path.resolve(Path.dirname(Caller()));

const optionsSchema = Joi.object({
    api: Joi.alternatives(Joi.string(), Joi.object().unknown(true)),
    //deprecated
    docspath: Joi.string().default('/api-docs'),
    docs: Joi.object({
        path: Joi.string().default('/api-docs'),
        auth: Joi.alternatives().try(Joi.object(), Joi.boolean()).allow(null),
        stripExtensions: Joi.boolean().default(true),
        prefixBasePath: Joi.boolean().default(true)
    }).default(),
    cors: Joi.boolean().default(true),
    vhost: Joi.string().allow(null),
    handlers: Joi.alternatives().try(Joi.string().default(Path.join(CALLER_DIR, 'routes')), Joi.object()).allow(null),
    extensions: Joi.array().items(Joi.string()).default(['js']),
    outputvalidation: Joi.boolean().default(false)
}).required();

const stripVendorExtensions = function (obj) {
github Sunbird-Ed / SunbirdEd-portal / src / app / helpers / announcement / services / notification / notificationPayload.js View on Github external
* @property {string} disbehavior - the behaviour when displaying, either "<option>" or "".
     */
    this.dispbehavior = dispbehavior

    /**
     *                schema - Schema validation, Which is used to validate the payload object strucutre.
     */
    this.schema = Joi.object().keys({
      'msgid': Joi.string().required(),
      'title': Joi.string().required(),
      'msg': Joi.string().empty(''),
      'icon': Joi.string().empty(''),
      'time': Joi.string().required(),
      'validity': Joi.number(),
      'actionid': Joi.number(),
      'actiondata': Joi.object().keys({
            announcementId: Joi.string().required()
        }).required(),
      'dispbehavior': Joi.string().empty('')
    }).unknown()
  }
</option>
github Hughp135 / angular-5-chat-app / back-end / src / api / servers / post.ts View on Github external
import Server from '../../models/server.model';
import User from '../../models/user.model';
import * as Joi from 'joi';
import { log } from 'winston';
import * as fs from 'fs';
import * as shortid from 'shortid';

const schema = Joi.object().keys({
  name: Joi.string().min(3).max(30).required(),
  icon: Joi.string().base64().min(8).max(20000).allow(null),
});

export async function createServer(req, res) {

  const user = await User.findOne({ '_id': req.claim.user_id });
  const result = Joi.validate(req.body, schema);

  if (result.error) {
    log('error', result.error.details[0].message);
    const errorMessage = getValidationMessage(result.error.details);
    return res.status(400).json({ error: errorMessage });
  }

  if (await existingServerCount(user) >= 3) {
github screwdriver-cd / screwdriver / plugins / commands / list.js View on Github external
'use strict';

const boom = require('boom');
const joi = require('joi');
const schema = require('screwdriver-data-schema');
const listSchema = joi.array().items(schema.models.command.get).label('List of commands');
const distinctSchema = joi.string()
    .valid(Object.keys(schema.models.command.base.describe().children))
    .label('Field to return unique results by');
const compactSchema = joi.string()
    .valid(['', 'false', 'true'])
    .label('Flag to return compact data');
const namespaceSchema = joi.reach(schema.models.command.base, 'namespace');
const namespacesSchema = joi.array().items(joi.object().keys({ namespace: namespaceSchema }));

module.exports = () => ({
    method: 'GET',
    path: '/commands',
    config: {
        description: 'Get commands with pagination',
        notes: 'Returns all command records',
        tags: ['api', 'commands'],
        auth: {
            strategies: ['token'],
            scope: ['user', 'build']
        },
        plugins: {
            'hapi-swagger': {
                security: [{ token: [] }]
            }
github StarpTech / bootme / examples / basic-wizard.js View on Github external
task.validateConfig = function(value) {
  return Joi.object()
    .keys({
      size: Joi.string().required(),
      theme: Joi.string().required()
    })
    .validate(value)
}
github screener-io / screener-runner / src / validate.js View on Github external
disableConcurrency: Joi.boolean(),
  useNewerBaseBranch: Joi.string().valid(['accepted', 'latest']),
  diffOptions: Joi.object().keys({
    structure: Joi.boolean(),
    layout: Joi.boolean(),
    style: Joi.boolean(),
    content: Joi.boolean(),
    minLayoutPosition: Joi.number().integer().min(0),
    minLayoutDimension: Joi.number().integer().min(0),
    minShiftGraphic: Joi.number().integer().min(0),
    compareSVGDOM: Joi.boolean()
  }),
  sauce: sauceSchema,
  vsts: vstsSchema,
  browserStack: browserStackSchema,
  meta: Joi.object(),
  failOnNewStates: Joi.boolean(),
  alwaysAcceptBaseBranch: Joi.boolean(),
  disableAutoSnapshots: Joi.boolean(),
  newSessionForEachState: Joi.boolean(),
  failureExitCode: Joi.number().integer().min(0).max(255).default(1),
  beforeEachScript: [Joi.func(), Joi.string()],
  ieNativeEvents: Joi.boolean()
})
  .without('resolutions', ['resolution'])
  .without('sauce', ['browserStack'])
  .with('disableBranchBaseline', ['baseBranch'])
  .with('useNewerBaseBranch', ['baseBranch'])
  .with('alwaysAcceptBaseBranch', ['baseBranch'])
  .required();

exports.runnerConfig = function(value) {