How to use the @hapi/joi.any 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 IcedFrisby / IcedFrisby / test / frisby_httpbin.js View on Github external
},
      })
      .expectStatus(200)
      .expectHeaderContains('content-type', 'application/json')
      .expectJSONTypes({
        // use the JSONTypes to check for data and headers. We don't really care about anything else.
        data: Joi.string().valid(
          'data:application/octet-stream;base64,' +
            Buffer.from(data).toString('base64')
        ),
        headers: Joi.object()
          .required()
          .keys({
            Accept: Joi.any(),
            'Accept-Encoding': Joi.any(),
            'Cache-Control': Joi.any(),
            Connection: Joi.any(),
            'Content-Type': Joi.string()
              .required()
              .valid('application/octet-stream'),
            'Content-Length': Joi.string()
              .required()
              .valid('1024'),
            Host: Joi.any(),
          }),
        args: Joi.any(),
        files: Joi.any(),
        form: Joi.any(),
        json: Joi.any(),
        origin: Joi.any(),
        url: Joi.string()
          .required()
github pelias / api / schema.js View on Github external
module.exports = Joi.object().keys({
  api: Joi.object().required().keys({
    version: Joi.string(),
    indexName: Joi.string(),
    host: Joi.string(),
    accessLog: Joi.string().allow(''),
    relativeScores: Joi.boolean(),
    requestRetries: Joi.number().integer().min(0),
    customBoosts: Joi.object().keys({
      layer: Joi.object(),
      source: Joi.object()
    }),
    localization: Joi.object().keys({
      flipNumberAndStreetCountries: Joi.array().items(Joi.string().regex(/^[A-Z]{3}$/))
    }).unknown(false),
    pipService: Joi.any(), // got moved to services, ignored for now
    placeholderService: Joi.any().forbidden(), // got moved to services
    services: Joi.object().keys({
      pip: Joi.object().keys({
        url: Joi.string().uri({ scheme: /https?/ }).required(),
        timeout: Joi.number().integer().optional().default(250).min(0),
        retries: Joi.number().integer().optional().default(3).min(0),
      }).unknown(false),
      placeholder: Joi.object().keys({
        url: Joi.string().uri({ scheme: /https?/ }).required(),
        timeout: Joi.number().integer().optional().default(250).min(0),
        retries: Joi.number().integer().optional().default(3).min(0),
      }).unknown(false),
      interpolation: Joi.object().keys({
        url: Joi.string().uri({ scheme: /https?/ }).required(),
        timeout: Joi.number().integer().optional().default(250).min(0),
        retries: Joi.number().integer().optional().default(3).min(0),
github hapijs / hapi / lib / config.js View on Github external
app: Joi.object().allow(null),
    autoListen: Joi.boolean(),
    cache: Joi.allow(null),                                 // Validated elsewhere
    compression: Joi.object({
        minBytes: Joi.number().min(1).integer().default(1024)
    })
        .allow(false)
        .default(),
    debug: Joi.object({
        request: Joi.array().items(Joi.string()).single().allow(false).default(['implementation']),
        log: Joi.array().items(Joi.string()).single().allow(false)
    })
        .allow(false)
        .default(),
    host: Joi.string().hostname().allow(null),
    listener: Joi.any(),
    load: Joi.object({
        sampleInterval: Joi.number().integer().min(0).default(0)
    })
        .unknown()
        .default(),
    mime: Joi.object().allow(null).default(null),
    operations: Joi.object({
        cleanStop: Joi.boolean().default(true)
    })
        .default(),
    plugins: Joi.object(),
    port: Joi.alternatives([
        Joi.number().integer().min(0),          // TCP port
        Joi.string().pattern(/\//),               // Unix domain socket
        Joi.string().pattern(/^\\\\\.\\pipe\\/)   // Windows named pipe
    ])
github glennjones / hapi-swagger / lib / builder.js View on Github external
host: Joi.string(), // JOI hostname validator too strict
  basePath: Joi.string().regex(/^\//),
  schemes: Joi.array()
    .items(Joi.string().valid(['http', 'https', 'ws', 'wss']))
    .optional(),
  consumes: Joi.array().items(Joi.string()),
  produces: Joi.array().items(Joi.string()),
  paths: Joi.any(),
  definitions: Joi.any(),
  parameters: Joi.any(),
  responses: Joi.any(),
  securityDefinitions: Joi.any(),
  security: Joi.any(),
  grouping: Joi.string().valid(['path', 'tags']),
  tagsGroupingFilter: Joi.func(),
  tags: Joi.any(),
  cors: Joi.boolean(),
  externalDocs: Joi.object({
    description: Joi.string(),
    url: Joi.string().uri()
  }),
  cache: Joi.object({
    expiresIn: Joi.number(),
    expiresAt: Joi.string(),
    generateTimeout: Joi.number()
  })
}).pattern(/^x-/, Joi.any());

/**
 * gets the Swagger JSON
 *
 * @param  {Object} settings
github hapipal / hpal-debug / test / closet / curl / server.js View on Github external
params: (value) => value,
                    payload: (value) => value,
                    query: (value) => value
                },
                handler: () => 'use-no-joi-validation-result'
            }
        },
        {
            method: 'post',
            path: '/non-obj-joi-validation/{param?}',
            options: {
                id: 'use-non-obj-joi-validation',
                validate: {
                    params: Joi.any(),
                    payload: Joi.any(),
                    query: Joi.any()
                },
                handler: () => 'use-non-obj-joi-validation-result'
            }
        },
        {
            method: 'post',
            path: '/use-joi-array-validation',
            options: {
                id: 'use-joi-array-validation',
                validate: {
                    payload: {
                        single: Joi.array().items(Joi.number()),
                        mixed: Joi.array().items(Joi.number(), Joi.string())
                    }
                },
                handler: ({ payload }) => payload
github banzaicloud / service-tools / src / middleware / express / request-validator.ts View on Github external
export default function requestValidatorFactory({
  params = joi.any(),
  query = joi.any(),
  body = joi.any(),
} = {}): RequestHandler {
  const schema = joi
    .object({
      params,
      query,
      body,
    })
    .required()

  return function requestValidator(req: Request, res: Response, next: NextFunction) {
    const { value: validated, error } = schema.validate(
      {
        params: req.params,
        query: req.query,
        body: req.body,
      },
github nearform / udaru / packages / udaru-hapi-plugin / lib / headers.js View on Github external
'use strict'

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

const headers = Joi.object({
  'authorization': Joi.any().required().description('User ID of the enpoint caller'),
  'org': Joi.any().description('Specify a different organization for the user who is calling the endpoint (works only for SuperUser, it\'s like impersonation).')
}).unknown()

module.exports = headers
github banzaicloud / service-tools / src / middleware / koa / request-validator.ts View on Github external
export default function requestValidatorFactory({ params = joi.any(), query = joi.any(), body = joi.any() } = {}) {
  const schema = joi
    .object({
      params,
      query,
      body,
    })
    .required()

  return async function requestValidator(ctx: IContextWithRequest, next: () => void) {
    const { value: validated, error } = schema.validate(
      {
        params: ctx.params || (ctx.request && ctx.request.params),
        query: ctx.query || (ctx.request && ctx.request.query),
        body: ctx.request && ctx.request.body,
      },
      { abortEarly: false }
github brave-intl / bat-ledger / bat-utils / lib / hapi-controllers-login.js View on Github external
request.cookieAuth.set(credentials)
      return h.redirect(runtime.login.github.world)
    }
  },

  auth: 'github',

  description: 'Logs the user into management operations',
  notes: 'This operation authenticates an administrative role for the server. The user is asked to authenticate their GitHub identity, and are assigned permissions based on team-membership. Operations are henceforth authenticated via an encrypted session cookie.',
  tags: [ 'api' ],

  validate: {
    query: Joi.object().keys({
      code: Joi.string().optional().description('an opaque string identifying an oauth flow'),
      refresh: Joi.any(),
      state: Joi.string().optional().description('an opaque string')
    }).unknown(true)
  }
}

/*
   GET /v1/logout
 */

v1.logout = {
  handler: (runtime) => {
    return async (request, h) => {
      const debug = braveHapi.debug(module, request)
      const credentials = request.auth.credentials
      const suffix = ' at ' + os.hostname() + ' ' + npminfo.name + '@' + npminfo.version +
            (process.env.DYNO ? ' at ' + process.env.DYNO : '') + ' from ' + whitelist.ipaddr(request)
github cjihrig / artificial / lib / index.js View on Github external
'use strict';

const Assert = require('assert');
const Joi = require('@hapi/joi');
const Request = require('@hapi/shot/lib/request');
const Response = require('@hapi/shot/lib/response');

const schema = Joi.object().keys({
  url: Joi.alternatives([
    Joi.string(),
    Joi.object().keys({
      protocol: Joi.string(),
      hostname: Joi.string(),
      port: Joi.any(),
      pathname: Joi.string().required(),
      query: Joi.any()
    })
  ]).required(),
  headers: Joi.object(),
  payload: Joi.any(),
  simulate: {
    end: Joi.boolean(),
    split: Joi.boolean(),
    error: Joi.boolean(),
    close: Joi.boolean()
  },
  authority: Joi.string(),
  remoteAddress: Joi.string(),
  method: Joi.string(),
  validate: Joi.boolean()
});