How to use the @hapi/joi.object function in @hapi/joi

To help you get started, we’ve selected a few @hapi/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 badges / shields / services / nuget / nuget-v3-service-family.js View on Github external
// both in years, the yearly number of queries for the endpoint are 1/x,
    // and when the endpoint changes, we wait for up to x years to get the
    // right endpoint.
    // So the waiting time within n years is n*l/x + x years, for which a
    // derivation yields an optimum at x = sqrt(n*l), roughly 42 minutes.
    intervalMillis: 42 * 60 * 1000,
    json: true,
    scraper: json =>
      json.resources.filter(
        resource => resource['@type'] === 'SearchQueryService'
      ),
  })
  return randomElementFrom(searchQueryServices)['@id']
}

const schema = Joi.object({
  data: Joi.array()
    .items(
      Joi.object({
        versions: Joi.array()
          .items(
            Joi.object({
              version: Joi.string().required(),
            })
          )
          .default([]),
        totalDownloads: Joi.number().integer(),
        totaldownloads: Joi.number().integer(),
      })
    )
    .max(1)
    .default([]),
github badges / shields / services / travis / travis-build.service.js View on Github external
'use strict'

const Joi = require('@hapi/joi')
const { isBuildStatus, renderBuildStatusBadge } = require('../build-status')
const { BaseSvgScrapingService } = require('..')

const schema = Joi.object({
  message: Joi.alternatives()
    .try(isBuildStatus, Joi.equal('unknown'))
    .required(),
}).required()

module.exports = class TravisBuild extends BaseSvgScrapingService {
  static get category() {
    return 'build'
  }

  static get route() {
    return {
      base: 'travis',
      format: '(?:(com)/)?(?!php-v)([^/]+/[^/]+?)(?:/(.+?))?',
      capture: ['comDomain', 'userRepo', 'branch'],
    }
github badges / shields / services / eclipse-marketplace / eclipse-marketplace-favorites.service.js View on Github external
'use strict'

const Joi = require('@hapi/joi')
const { nonNegativeInteger } = require('../validators')
const EclipseMarketplaceBase = require('./eclipse-marketplace-base')

const favoritesResponseSchema = Joi.object({
  marketplace: Joi.object({
    node: Joi.object({
      favorited: nonNegativeInteger,
    }),
  }),
}).required()

module.exports = class EclipseMarketplaceFavorites extends EclipseMarketplaceBase {
  static get category() {
    return 'other'
  }

  static get route() {
    return this.buildRoute('eclipse-marketplace/favorites')
  }
github feater-dev / feater / server / src / instantiation / validation / defintion-recipe-zero-one-zero-validator.component.ts View on Github external
protected createProxiedPortSchema(): joi.Schema {
        return joi.object().keys({
            id: joi
                .string()
                .regex(idRegex)
                .required(),
            service_id: joi
                .string()
                .regex(idRegex)
                .required(),
            port: joi
                .number()
                .integer()
                .min(1),
            name: joi
                .string()
                .min(1)
                .required(),
github badges / shields / services / bit / bit-components.service.js View on Github external
'use strict'

const Joi = require('@hapi/joi')
const { metric } = require('../text-formatters')
const { nonNegativeInteger } = require('../validators')
const { downloadCount } = require('../color-formatters')
const { BaseJsonService } = require('..')

const collectionSchema = Joi.object({
  payload: Joi.object({
    totalComponents: nonNegativeInteger,
  }).required(),
}).required()

module.exports = class BitComponents extends BaseJsonService {
  static get category() {
    return 'other'
  }

  static get route() {
    return {
      base: 'bit/collection/total-components',
      pattern: ':owner/:collection',
    }
  }
github badges / shields / services / itunes / itunes.service.js View on Github external
'use strict'

const Joi = require('@hapi/joi')
const { renderVersionBadge } = require('../version')
const { nonNegativeInteger } = require('../validators')
const { BaseJsonService, NotFound } = require('..')

const schema = Joi.object({
  resultCount: nonNegativeInteger,
  results: Joi.array()
    .items(Joi.object({ version: Joi.string().required() }))
    .min(0),
}).required()

module.exports = class Itunes extends BaseJsonService {
  static get category() {
    return 'version'
  }

  static get route() {
    return {
      base: 'itunes/v',
      pattern: ':bundleId',
    }
  }

  static get examples() {
github JKHeadley / rest-hapi / utilities / joi-mongoose-helper.js View on Github external
Joi.array()
        .items(Joi.string())
        .description(
          'A set of complex object properties to populate. Valid first level values include ' +
            Object.keys(associations)
              .toString()
              .replace(/,/g, ', ')
        ),
      Joi.string()
    )
    queryModel.$flatten = Joi.boolean().description(
      'Set to true to flatten embedded arrays, i.e. remove linking-model data.'
    )
  }

  queryModel = Joi.object(queryModel)

  if (!config.enableQueryValidation) {
    queryModel = queryModel.unknown()
  }

  return queryModel
}
github ipfs / js-ipfs / src / http / api / resources / resolve.js View on Github external
'use strict'

const Joi = require('@hapi/joi')
const debug = require('debug')
const multibase = require('multibase')

const log = debug('ipfs:http-api:resolve')
log.error = debug('ipfs:http-api:resolve:error')

module.exports = {
  validate: {
    query: Joi.object().keys({
      recursive: Joi.boolean().default(true),
      arg: Joi.string().required(),
      'cid-base': Joi.string().valid(...multibase.names)
    }).unknown()
  },
  async handler (request, h) {
    const { ipfs } = request.server.app
    const name = request.query.arg
    const recursive = request.query.recursive
    const cidBase = request.query['cid-base']

    log(name, { recursive, cidBase })
    const res = await ipfs.resolve(name, { recursive, cidBase })

    return h.response({ Path: res })
  }
github hapijs / inert / lib / directory.js View on Github external
const File = require('./file');
const Fs = require('./fs');


const internals = {};


internals.schema = Joi.object({
    path: Joi.alternatives(Joi.array().items(Joi.string()).single(), Joi.func()).required(),
    index: Joi.alternatives(Joi.boolean(), Joi.array().items(Joi.string()).single()).default(true),
    listing: Joi.boolean(),
    showHidden: Joi.boolean(),
    redirectToSlash: Joi.boolean(),
    lookupCompressed: Joi.boolean(),
    lookupMap: Joi.object().min(1).pattern(/.+/, Joi.string()),
    etagMethod: Joi.string().valid('hash', 'simple').allow(false),
    defaultExtension: Joi.string().alphanum()
});


internals.resolvePathOption = function (result) {

    if (result instanceof Error) {
        throw result;
    }

    if (typeof result === 'string') {
        return [result];
    }

    if (Array.isArray(result)) {
github nearform / udaru / packages / udaru-hapi-16-plugin / routes / public / teams.js View on Github external
const { name, description, metadata } = request.payload

      const params = {
        id,
        name,
        description,
        metadata,
        organizationId
      }

      request.udaruCore.teams.update(params, reply)
    },
    config: {
      validate: {
        params: _.pick(validation.updateTeam, ['id']),
        payload: Joi.object(_.pick(validation.updateTeam, ['name', 'description', 'metadata'])).or('name', 'description', 'metadata').label('UpdateTeamPayload'),
        headers
      },
      description: 'Update a team',
      notes: 'The PUT /authorization/teams/{id} endpoint updates a team data.\n',
      tags: ['api', 'teams'],
      plugins: {
        auth: {
          action: Action.UpdateTeam,
          getParams: (request) => ({ teamId: request.params.id })
        }
      },
      response: { schema: swagger.Team }
    }
  })

  server.route({