How to use the joi.array 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 trendscenter / coinstac / packages / coinstac-common / src / models / consortium.js View on Github external
* @todo A computation's inputs shouldn't be set on the consortium because
   * this limits runs to one-at-a-time. Consider moving elsewhere, perhaps some
   * sort of `ComputationRun` model.
   */
  activeComputationInputs: joi.array().items(
    joi.array().items(
      joi.array().items(joi.number(), joi.object(), joi.string()),
      joi.number(),
      joi.string()
    )
  ).default([]),
  activeRunId: joi.string().min(1),
  description: joi.string().required(),
  label: joi.string().min(1).required(),
  tags: joi.array().default([]),
  users: joi.array().items(joi.string()).required()
    .default([]), // @TODO users => usernames
  owners: joi.array().items(joi.string()).required(),
});

module.exports = Consortium;
github xogroup / joi2gql / test / integration.spec.js View on Github external
it('should execute a graphql query given a complex joi schema', () => {

            let schema;
            const joiSchemaOverride = Joi.object().keys({
                teamMembers: Joi.array().items(Joi.lazy(() => schema).description('Cyborg'))
            });

            const graphqlSchema = Joi2GQL.schema( internals.buildQuerySchema(joiSchemaOverride) );
            const query = `
                { 
                    subject(id: 2) {
                        a
                        b
                        c
                        d {
                            key1
                            key2
                        }
                        e
                        experiment
                        collection {
github bentonam / fakeit / test / fixtures / models / ecommerce / validation / users.model.js View on Github external
var is = require('joi');

module.exports = is.object({
  name: 'Users',
  type: 'object',
  file: is.string(),
  root: is.string(),
  is_dependency: is.boolean(),
  dependants: is.array(),
  key: '_id',
  seed: 0,
  data: {
    min: 200,
    max: 500,
    count: is.number().min(200).max(500),
    dependencies: is.array().length(0),
    inputs: is.array().items(is.string()).length(0),
    pre_run: is.func(),
  },
  properties: {
    _id: utils.check('string', 'The document id', { post_build: is.func(), }),
    doc_type: utils.check('string', 'The document type', { value: is.string(), }),
    user_id: utils.check('integer', 'The users id', { build: is.func(), }),
    first_name: utils.check('string', 'The users first name', { fake: is.string(), }),
    last_name: utils.check('string', 'The users last name', { fake: is.string(), }),
    username: utils.check('string', 'The users username', { fake: is.string(), }),
    password: utils.check('string', 'The users password', { fake: is.string(), }),
    email_address: utils.check('string', 'The users email address', { fake: is.string(), }),
    home_phone: utils.check('string', 'The users home phone', { fake: is.string(), post_build: is.func(), }),
    mobile_phone: utils.check('string', 'The users mobile phone', { fake: is.string(), post_build: is.func(), }),
    addresses: utils.check('array', 'An array of addresses', { build: is.func(), }),
    created_on: utils.check('integer', 'An epoch time of when the user was created', { fake: is.string(), post_build: is.func(), }),
github gershonv / react-blog / server / schemas / article.js View on Github external
const create = Joi.object().keys({
  title: Joi.string()
    .required()
    .error(new Error('标题不能为空')),
  content: Joi.string(),
  categories: Joi.array(),
  tags: Joi.array()
})

const update = Joi.object().keys({
  articleId: Joi.number(),
  title: Joi.string(),
  content: Joi.string(),
  categories: Joi.array(),
  tags: Joi.array(),
  showOrder: Joi.number()
})

const getArticleList = Joi.object().keys({
  page: Joi.number(),
  pageSize: Joi.number(),
  title: Joi.string().allow(''),
  tag: Joi.string().allow(''),
  category: Joi.string().allow('')
})

module.exports = {
  create,
  update,
  getArticleList
}
github arangodb / arangodb / js / apps / system / _admin / aardvark / APP / models / configuration.js View on Github external
(function() {
  "use strict";

  var Foxx = require("@arangodb/foxx"),
    joi = require("joi"),
    Configuration;

  Configuration = Foxx.Model.extend({
    schema: {
      applicationContext: joi.string().optional(),
      path: joi.string().optional(),
      name: joi.string().required(),
      collectionNames: joi.array().required(),
      authenticated: joi.boolean().required(),
      author: joi.string().required(),
      description: joi.string().required(),
      license: joi.string().required()
    }
  });

  exports.Model = Configuration;
}());
github labibramadhan / mastery / src / services / _core / handlersGenerator.js View on Github external
({
    handler,
    permissions,
  } = handlerFindById(model, componentId));
  this.findById = handler;
  this.findById.permissions = permissions;

  ({
    handler,
    permissions,
  } = handlerCreate(model, componentId));
  this.create = handler;
  this.create.permissions = permissions;

  if (associations) {
    const validAssociations = Joi.validate(associations, [Joi.string().valid('*'), Joi.array().items(Joi.string())]);
    if (!validAssociations || validAssociations.error) {
      throw validAssociations.error;
    }

    let associationsRequested;
    if (validAssociations === '*') {
      associationsRequested = model.associations;
    } else {
      associationsRequested = _.pick(model.associations, associations);
    }

    _.each(associationsRequested, (association) => {
      switch (association.associationType) {
        case 'BelongsToMany':
        case 'HasMany':
          ({
github contentful / contentful-migration / src / lib / offline-api / validator / schema / content-type-schema.ts View on Github external
import * as Joi from 'joi'

const MAX_FIELDS = 50
const contentTypeSchema = Joi.object().keys({
  name: Joi.string().required(),
  description: Joi.string().allow(''),
  displayField: Joi.string(),
  fields: Joi.array().max(MAX_FIELDS).required()
})

export default contentTypeSchema
export {
  MAX_FIELDS,
  contentTypeSchema
}
github arago / hiro-graph-js / packages / hiro-graph-populate / src / config.ts View on Github external
password: Joi.string().required(),
        perOrg: Joi.number().required()
    }),
    orgs: Joi.object({
        count: Joi.number().required(),
        name: Joi.string().required()
    }),
    users: Joi.object({
        password: Joi.string().required(),
        perOrg: Joi.number().required()
    })
});

const configPopulateSchema = Joi.array().items(
    Joi.object({
        admins: Joi.array()
            .items(userSchema)
            .required(),
        name: Joi.string().required(),
        users: Joi.array()
            .items(userSchema)
            .required()
    }).required()
);

const configSchema = Joi.object({
    generate: configGenerateSchema,
    populate: configPopulateSchema
}).xor("populate", "generate");

const explorer = cosmiconfig("hiro-graph-populate");
github gothinkster / hapijs-realworld-example-app / lib / modules / api / validations.js View on Github external
function schemaForStatusCode (statusCode) {
  let schema = {
    errors: {}
  }

  schema.errors[statusCode] = Joi.array().items(Joi.string())

  return Joi.object().keys(schema)
}
github opendistro-for-elasticsearch / security-kibana-plugin / lib / configuration / validation / roles.js View on Github external
import Joi from 'joi';

export default Joi.object().keys({
    description: Joi.string().allow(''),
    cluster_permissions: Joi.array().items(Joi.string()).optional(),
    tenant_permissions: Joi.array(),
    index_permissions: Joi.array()
});