How to use the @hapi/joi.alternatives 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 / travis / travis-build.tester.js View on Github external
'use strict'

const Joi = require('@hapi/joi')
const { isBuildStatus } = require('../build-status')
const t = (module.exports = require('../tester').createServiceTester())

// Travis (.org) CI

t.create('build status on default branch')
  .get('/rust-lang/rust.json')
  .expectBadge({
    label: 'build',
    message: Joi.alternatives().try(isBuildStatus, Joi.equal('unknown')),
  })

t.create('build status on named branch')
  .get('/rust-lang/rust/stable.json')
  .expectBadge({
    label: 'build',
    message: Joi.alternatives().try(isBuildStatus, Joi.equal('unknown')),
  })

t.create('unknown repo')
  .get('/this-repo/does-not-exist.json')
  .expectBadge({ label: 'build', message: 'unknown' })

t.create('invalid svg response')
  .get('/foo/bar.json')
  .intercept(nock =>
github badges / shields / core / base-service / base.js View on Github external
prepareRoute,
  namedParamsForMatch,
  getQueryParamNames,
} = require('./route')
const { assertValidServiceDefinition } = require('./service-definitions')
const trace = require('./trace')
const validate = require('./validate')

const defaultBadgeDataSchema = Joi.object({
  label: Joi.string(),
  color: Joi.string(),
  labelColor: Joi.string(),
  namedLogo: Joi.string(),
}).required()

const optionalStringWhenNamedLogoPresent = Joi.alternatives().conditional(
  'namedLogo',
  {
    is: Joi.string().required(),
    then: Joi.string(),
  }
)

const optionalNumberWhenAnyLogoPresent = Joi.alternatives()
  .conditional('namedLogo', { is: Joi.string().required(), then: Joi.number() })
  .conditional('logoSvg', { is: Joi.string().required(), then: Joi.number() })

const serviceDataSchema = Joi.object({
  isError: Joi.boolean(),
  label: Joi.string().allow(''),
  // While a number of badges pass a number here, in the long run we may want
  // `render()` to always return a string.
github fknop / hapi-pagination / lib / config.js View on Github external
active: Joi.boolean().required()
        })
    }),
    results: Joi.object({
        name: Joi.string().required()
    }),
    reply: Joi.object({
        paginate: Joi.string().required(),
        parameters: {
            results: internals.schemas.replyParameter,
            totalCount: internals.schemas.replyParameter
        }
    }),
    routes: Joi.object({
        include: Joi.array().items(Joi.alternatives().try(Joi.object().type(RegExp), Joi.string())), // May register no routes...
        exclude: Joi.array().items(Joi.alternatives().try(Joi.object().type(RegExp), Joi.string()))
    })
});


internals.schemas.routeOptions = Joi.object({
    enabled: Joi.boolean(),
    defaults: Joi.object({
        page: Joi.number().integer().positive(),
        limit: Joi.number().integer().positive(),
        pagination: Joi.boolean()
    })
});

const getConfig = function (server, options) {

    const config = Hoek.applyToDefaults(internals.defaults, options);
github outmoded / lout / test / routes / default.js View on Github external
options: {
            handler: () => 'ok',
            validate: {
                query: Joi.object({
                    param1: Joi.alternatives()
                        .when('b', {
                            is: 5,
                            then: Joi.string(),
                            otherwise: Joi.number().required().description('Things and stuff')
                        })
                        .when('a', {
                            is: true,
                            then: Joi.date(),
                            otherwise: Joi.any()
                        }),
                    param2: Joi.alternatives()
                        .when('b', {
                            is: 5,
                            then: Joi.string()
                        })
                        .when('a', {
                            is: true,
                            otherwise: Joi.any()
                        })
                })
            }
        }
    },
    {
        method: 'GET',
        path: '/withreferences',
        options: {
github auth0 / express-openid-connect / lib / config.js View on Github external
auth0Logout: Joi.boolean().optional().default(false),
  authorizationParams: Joi.object().optional(),
  baseURL: Joi.string().uri().required(),
  clientID: Joi.string().required(),
  clientSecret: Joi.string().optional(),
  clockTolerance: Joi.number().optional().default(60),
  errorOnRequiredAuth: Joi.boolean().optional().default(false),
  getUser: Joi.func().optional().default(getUser),
  handleCallback: Joi.func().optional().default(handleCallback),
  httpOptions: Joi.object().optional(),
  identityClaimFilter: Joi.array().optional().default(['aud', 'iss', 'iat', 'exp', 'nonce', 'azp', 'auth_time']),
  idpLogout: Joi.boolean().optional().default(false).when(
    'auth0Logout', { is: true, then: Joi.boolean().optional().default(true) }
  ),
  idTokenAlg: Joi.string().not('none').optional().default('RS256'),
  issuerBaseURL: Joi.alternatives([ Joi.string().uri(), Joi.string().hostname() ]).required(),
  legacySameSiteCookie: Joi.boolean().optional().default(true),
  loginPath: Joi.string().uri({relativeOnly: true}).optional().default('/login'),
  logoutPath: Joi.string().uri({relativeOnly: true}).optional().default('/logout'),
  redirectUriPath: Joi.string().uri({relativeOnly: true}).optional().default('/callback'),
  required: Joi.alternatives([ Joi.func(), Joi.boolean()]).optional().default(true),
  routes: Joi.boolean().optional().default(true),
});

function buildAuthorizeParams(authorizationParams) {
  /*
If the user does not provide authorizationParams we default to "defaultAuthorizeParams" (id_token/form_post).

If the user provides authorizationParams then
    - the default response_mode is DEFAULT (undefined),
    - the default scope is defaultAuthorizeParams.scope
    - response type is required
github scality / backbeat / lib / config.joi.js View on Github external
metrics: {
        topic: joi.string().required(),
    },
    server: {
        healthChecks: joi.object({
            allowFrom: joi.array().items(joi.string()).default([]),
        }).required(),
        host: joi.string().required(),
        port: joi.number().default(8900),
    },
    redis: {
        host: joi.string().default('localhost'),
        port: joi.number().default(6379),
        name: joi.string().default('backbeat'),
        password: joi.string().default('').allow(''),
        sentinels: joi.alternatives([joi.string(), joi.array().items(
            joi.object({
                host: joi.string().required(),
                port: joi.number().required(),
            }))]
        ),
        sentinelPassword: joi.string().default('').allow(''),
    },
    localCache: {
        host: joi.string().default('localhost'),
        port: joi.number().default(6379),
        password: joi.string(),
    },
    healthcheckServer: joi.object({
        bindAddress: joi.string().default('127.0.0.1'),
        port: joi.number().default(4042),
    }).required(),
github opporty-com / Plasma-Cash / plasma-core / src / api / validates / block.js View on Github external
import Joi from '@hapi/joi';

import {trxResponse} from "./default";

const getByNumber = Joi.object({
  number: Joi.string().required().description('Number for block you need'),
}).label('getByNumber')

const getBlockResponse = Joi.alternatives().try([
  Joi.object({
    number: Joi.number(),
    merkleRootHash: Joi.string(),
    transactions: Joi.array().items(trxResponse),
    signature: Joi.string().allow(null).allow(''),
    totalFee: Joi.string(),
  }),
  Joi.object({ error: Joi.string() })
]).label('Block')

const getByNumberAndTokenId = Joi.object({
  blockNumber: Joi.string().required().description('Number for block you need'),
  tokenId: Joi.string().required().description('Token id for block you need')
}).label('getByNumberAndTokenId')
github badges / shields / services / nuget / nuget-v2-service-family.js View on Github external
Joi.object({
          Version: Joi.string(),
          NormalizedVersion: Joi.string(),
          DownloadCount: nonNegativeInteger,
        })
      )
      .max(1)
      .default([]),
  }).required(),
}).required()

const xmlSchema = Joi.object({
  feed: Joi.object({
    entry: Joi.object({
      'm:properties': Joi.object({
        'd:Version': Joi.alternatives(Joi.string(), Joi.number()),
        'd:NormalizedVersion': Joi.string(),
        'd:DownloadCount': nonNegativeInteger,
        'd:Tags': Joi.string(),
      }),
    }),
  }).required(),
}).required()

const queryParamSchema = Joi.object({
  include_prereleases: Joi.equal(''),
}).required()

async function fetch(
  serviceInstance,
  { odataFormat, baseUrl, packageName, includePrereleases = false }
) {
github cascornelissen / svg-spritemap-webpack-plugin / lib / options-validator.js View on Github external
svgo: Joi.alternatives([
                    Joi.boolean(),
                    Joi.object()
                ])
            }),
            sprite: Joi.object({
                prefix: Joi.alternatives([
                    Joi.string(),
                    Joi.valid(false),
                    Joi.func()
                ]),
                idify: Joi.alternatives([
                    Joi.func(),
                    Joi.valid(false)
                ]),
                gutter: Joi.alternatives([
                    Joi.number(),
                    Joi.valid(false)
                ]),
                generate: Joi.object({
                    title: Joi.boolean(),
                    symbol: Joi.alternatives([
                        Joi.boolean(),
                        Joi.string()
                    ]),
                    use: Joi.boolean(),
                    view: Joi.alternatives([
                        Joi.boolean(),
                        Joi.string()
                    ])
                })
            }),