Exemple #1
0
    it('should serialize binary attribute', function () {
      var config = {
        hashKey: 'data',
        schema : {
          data : Joi.binary(),
          bin  : Joi.binary()
        }
      };

      var s = new Schema(config);

      var item = serializer.serializeItem(s, {data: 'hello', bin : new Buffer('binary')});

      item.should.eql({data: new Buffer('hello'), bin : new Buffer('binary')});
    });
Exemple #2
0
    lab.test('upload with binary file type', (done) => {
        routes.config.validate.payload.file = Joi.binary().meta({ swaggerType: 'file' }).required();

        Helper.createServer({}, routes, (err, server) => {

            server.inject({ method: 'GET', url: '/swagger.json' }, function (response) {

                //console.log(JSON.stringify(response.result.paths['/test/'].post.parameters));
                expect(err).to.equal(null);
                expect(response.statusCode).to.equal(200);
                expect(response.result.paths['/test/'].post.parameters).to.equal([
                    {
                        'type': 'file',
                        'format': 'binary',
                        'required': true,
                        'x-meta': {
                            'swaggerType': 'file'
                        },
                        'name': 'file',
                        'in': 'formData'
                    }
                ]);
                Helper.validate(response, done, expect);
            });
        });
    });
var Undynamic = function(options) {
  if (!(this instanceof Undynamic))
    return new Undynamic(options);

  if (!options)
    options = {};

  this._options = options;
  this._options._api = 'https://undynamic.com/api/v1';

  Joi.assert(this._options.token, Joi.binary().encoding('base64'));
};
lab.experiment('lout examples', () => {


    // these are example are taken from https://github.com/hapijs/lout/blob/master/test/routes/default.js
    /*
    Copyright (c) 2012-2014, Walmart and other contributors.
    All rights reserved.

    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions are met:
        * Redistributions of source code must retain the above copyright
        notice, this list of conditions and the following disclaimer.
        * Redistributions in binary form must reproduce the above copyright
        notice, this list of conditions and the following disclaimer in the
        documentation and/or other materials provided with the distribution.
        * The names of any contributors may not be used to endorse or promote
        products derived from this software without specific prior written
        permission.

    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
    ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY
    DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
    ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    */
    const routes = [{
        method: 'GET',
        path: '/test',
        config: {
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    param1: Joi.string().insensitive().required()
                }
            },
            tags: ['api'],
            description: 'Test GET',
            notes: 'test note'
        }
    }, {
        method: 'GET',
        path: '/another/test',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    param1: Joi.string().required()
                }
            }
        }
    }, {
        method: 'GET',
        path: '/zanother/test',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    param1: Joi.string().required()
                }
            }
        }
    }, {
        method: 'POST',
        path: '/test',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    param2: Joi.string().valid('first', 'last'),
                    param3: 'third',
                    param4: 42
                }
            }
        }
    }, {
        method: 'DELETE',
        path: '/test',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    param2: Joi.string().valid('first', 'last')
                }
            }
        }
    }, {
        method: 'PUT',
        path: '/test',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    param2: Joi.string().valid('first', 'last')
                }
            }
        }
    }, {
        method: 'PATCH',
        path: '/test',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    param2: Joi.string().valid('first', 'last'),
                    param3: Joi.number().valid(42)
                }
            }
        }
    }, {
        method: 'GET',
        path: '/notincluded',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            plugins: {
                lout: false
            }
        }
    }, {
        method: 'GET',
        path: '/nested',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    param1: Joi.object({
                        nestedparam1: Joi.string().required(),
                        array: Joi.array()
                    })
                }
            }
        }
    }, {
        method: 'GET',
        path: '/rootobject',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: Joi.object({
                    param1: Joi.string().required()
                })
            }
        }
    }, {
        method: 'GET',
        path: '/rootarray',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: Joi.array().items(
                    Joi.string().required(),
                    Joi.object({ param1: Joi.number() }),
                    Joi.number().forbidden()
                    ).min(2).max(5).length(3)
            }
        }
    }, {
        method: 'GET',
        path: '/complexarray',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: Joi.array()
                    .ordered('foo', 'bar')
                    .items(
                        Joi.string().required(),
                        Joi.string().valid('four').forbidden(),
                        Joi.object({ param1: Joi.number() }),
                        Joi.number().forbidden()
                        ).min(2).max(5).length(3)
                    .ordered('bar', 'bar')
                    .items(
                        Joi.number().required()
                        )
            }
        }
    }, {
        method: 'GET',
        path: '/path/{pparam}/test',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                params: {
                    pparam: Joi.string().required()
                }
            }
        }
    }, {
        method: 'GET',
        path: '/emptyobject',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    param1: Joi.object()
                }
            }
        }
    }, {
        method: 'GET',
        path: '/alternatives',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    param1: Joi.alternatives().try(Joi.number().required(), Joi.string().valid('first', 'last'))
                }
            }
        }
    }, {
        method: 'GET',
        path: '/withnestedalternatives',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    param1: Joi.object({
                        param2: Joi.alternatives().try(
                            {
                                param3: Joi.object({
                                    param4: Joi.number().example(5)
                                }).description('this is cool too')
                            },
                            Joi.number().min(42)
                            )
                    }).description('something really cool'),
                    param2: Joi.array().items(
                        Joi.object({
                            param2: Joi.alternatives().try(
                                {
                                    param3: Joi.object({
                                        param4: Joi.number().example(5)
                                    }).description('this is cool too')
                                },
                                Joi.array().items('foo', 'bar'),
                                Joi.number().min(42).required(),
                                Joi.number().max(42).required()
                                )
                        }).description('all the way down')
                        ).description('something really cool')
                }
            }
        }
    }, {
        method: 'GET',
        path: '/novalidation',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler
        }
    }, {
        method: 'GET',
        path: '/withresponse',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            response: {
                schema: {
                    param1: Joi.string()
                }
            }
        }
    }, {
        method: 'GET',
        path: '/withstatus',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            response: {
                schema: {
                    param1: Joi.string()
                },
                status: {
                    204: {
                        param2: Joi.string()
                    },
                    404: {
                        error: 'Failure'
                    }
                }
            }
        }
    }, {
        method: 'GET',
        path: '/withpojoinarray',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    param1: Joi.array().items({
                        param2: Joi.string()
                    })
                }
            }
        }
    }, {
        method: 'POST',
        path: '/withnestedrulesarray',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                payload: {
                    param1: Joi.array().items(Joi.object({
                        param2: Joi.array().items(Joi.object({
                            param3: Joi.string()
                        })).optional()
                    }))
                }
            }
        }
    }, {
        method: 'GET',
        path: '/withhtmlnote',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    param1: Joi.string().notes('<span class="htmltypenote">HTML type note</span>')
                }
            },
            notes: '<span class="htmlroutenote">HTML route note</span>'
        }
    }, {
        method: 'GET',
        path: '/withnotesarray',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    param1: Joi.string().notes([
                        '<span class="htmltypenote">HTML type note</span>',
                        '<span class="htmltypenote">HTML type note</span>'
                    ])
                }
            }
        }
    }, {
        method: 'GET',
        path: '/withexample',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    param1: Joi.string().regex(/^\w{1,5}$/).example('abcde')
                }
            }
        }
    }, {
        method: 'POST',
        path: '/denybody',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                payload: false
            }
        }
    }, {
        method: 'POST',
        path: '/rootemptyobject',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                payload: Joi.object()
            }
        }
    }, {
        method: 'GET',
        path: '/withnestedexamples',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    param1: Joi.object({
                        param2: Joi.object({
                            param3: Joi.number().example(5)
                        }).example({
                            param3: 5
                        })
                    }).example({
                        param2: {
                            param3: 5
                        }
                    })
                }
            }
        }
    }, {
        method: 'GET',
        path: '/withmeta',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    param1: Joi.string().meta({
                        index: true,
                        unique: true
                    })
                }
            }
        }
    }, {
        method: 'GET',
        path: '/withunit',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    param1: Joi.number().unit('ms')
                }
            }
        }
    }, {
        method: 'GET',
        path: '/withdefaultvalue',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    param1: Joi.number().default(42)
                }
            }
        }
    }, {
        method: 'GET',
        path: '/withbinaryencoding',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    param1: Joi.binary().min(42).max(128).length(64).encoding('base64')
                }
            }
        }
    }, {
        method: 'GET',
        path: '/withdate',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    param1: Joi.date().min('1-1-1974').max('12-31-2020')
                }
            }
        }
    }, {
        method: 'GET',
        path: '/withpeersconditions',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    param1: Joi.object()
                        .and('a', 'b', 'c')
                        .or('a', 'b', 'c')
                        .xor('a', 'b', 'c')
                        .with('a', ['b', 'c'])
                        .without('a', ['b', 'c'])
                }
            }
        }
    }, {
        method: 'GET',
        path: '/withpattern',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    param1: Joi.object({
                        a: Joi.string()
                    }).pattern(/\w\d/, Joi.boolean())

                }
            }
        }
    }, {
        method: 'GET',
        path: '/withallowunknown',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    param1: Joi.object().unknown(),
                    param2: Joi.object().unknown(false)
                }
            }
        }
    }, {
        method: 'GET',
        path: '/withstringspecifics',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    param1: Joi.string()
                        .alphanum()
                        .regex(/\d{3}.*/)
                        .token()
                        .email()
                        .guid()
                        .isoDate()
                        .hostname()
                        .lowercase()
                        .uppercase()
                        .trim(),
                    param2: Joi.string().email()
                }
            }
        }
    }, {
        method: 'GET',
        path: '/withconditionalalternatives',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    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',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    param1: Joi.ref('a.b'),
                    param2: Joi.ref('$x')
                }
            }
        }
    }, {
        method: 'GET',
        path: '/withassert',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    param1: Joi.object().assert('d.e', Joi.ref('a.c'), 'equal to a.c'),
                    param2: Joi.object().assert('$x', Joi.ref('b.e'), 'equal to b.e')
                }
            }
        }
    }, {
        method: 'GET',
        path: '/withproperties',
        vhost: 'john.doe',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            cors: {
                maxAge: 12345
            },
            jsonp: 'callback'
        }
    }, {
        method: 'OPTIONS',
        path: '/optionstest',
        handler: Helper.defaultHandler
    }, {
        method: 'GET',
        path: '/withrulereference',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    param1: Joi.date().min(Joi.ref('param2')),
                    param2: Joi.date()
                }
            }
        }
    }, {
        method: 'GET',
        path: '/withcorstrue',
        vhost: 'john.doe',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            cors: true
        }
    }, {
        method: 'GET',
        path: '/withstrip',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    param1: Joi.any().strip(),
                    param2: Joi.any()
                }
            }
        }
    }, {
        method: 'GET',
        path: '/internal',
        config: {
            tags: ['api'],
            isInternal: true,
            handler: Helper.defaultHandler
        }
    }];



    lab.test('all routes parsed', (done) => {

        Helper.createServer({}, routes, (err, server) => {

            expect(err).to.equal(null);
            server.inject({ method: 'GET', url: '/swagger.json' }, function (response) {

                expect(response.statusCode).to.equal(200);
                // the 40 to 45 difference is in one route having a number of methods
                expect(response.result.paths).to.have.length(40);
                done();
            });

        });
    });

});
Exemple #5
0
});


internals.register = Joi.object({
    route: Joi.object({
        prefix: Joi.string().regex(/^\/.+/),
        vhost: internals.vhost
    }),
    select: internals.labels
});


internals.state = Joi.object({
    strictHeader: Joi.boolean(),
    failAction: Joi.string().valid('error', 'log', 'ignore'),
    clearInvalid: Joi.boolean(),
    isSecure: Joi.boolean(),
    isHttpOnly: Joi.boolean(),
    path: Joi.string(),
    domain: Joi.string(),
    ttl: Joi.number(),
    encoding: Joi.string().valid('base64json', 'base64', 'form', 'iron', 'none'),
    sign: Joi.object({
        password: [Joi.string(), Joi.binary(), Joi.object()],
        integrity: Joi.object()
    }),
    iron: Joi.object(),
    password: [Joi.string(), Joi.binary(), Joi.object()],
    autoValue: Joi.any()
});
    }
};

var schema = Joi.object().keys({
    bucket: Joi.string().required(),
    bucketType: Joi.string().required(),
    key: Joi.string().optional(),
    callback: Joi.func().required(),
    op: Joi.object().type(MapOperation).required(),
    w: Joi.number().default(null).optional(),
    dw: Joi.number().default(null).optional(),
    pw: Joi.number().default(null).optional(),
    returnBody: Joi.boolean().default(true).optional(),
    setsAsBuffers: Joi.boolean().default(false).optional(),
    timeout: Joi.number().default(null).optional(),
    context: Joi.binary().default(null).optional()    
});


/**
 * A builder for constructing UpdateMap instances.
 * 
 * Rather than having to manually construct the __options__ and instantiating
 * a UpdateMap directly, this builder may be used.
 * 
 *     var update = new UpdateMap.Builder()
 *               .withBucketType('counters')
 *               .withBucket('myBucket')
 *               .withKey('counter_1')
 *               .withMapOperation(mapOp)
 *               .withCallback(callback)
Exemple #7
0
// Load modules

var Boom = require('boom');
var Hoek = require('hoek');
var jwt = require('jsonwebtoken');
var Joi = require('joi');

var optionsSchema = Joi.object().keys({
  key: Joi.alternatives().try(Joi.binary(), Joi.func()).required(),
  validateFunc: Joi.func(),
  algorithms: Joi.array().items(Joi.string()),
  audience: Joi.alternatives().try(Joi.string(), Joi.array().items(Joi.string())),
  issuer: Joi.alternatives().try(Joi.string(), Joi.array().items(Joi.string())),
  subject: Joi.string()
}).label('jwt auth strategy options');

// Declare internals
var internals = {};

function register(server, options) {
  server.auth.scheme('jwt', internals.implementation);
};

internals.implementation = function (server, options) {

  var validationResult = Joi.validate(options, optionsSchema);
  if (validationResult.error) {
    throw new Error(validationResult.error.message);
  }

  var settings = Hoek.clone(options);
Exemple #8
0
lab.experiment('lout examples', () => {


    // these are example are taken from https://github.com/hapijs/lout/blob/master/test/routes/default.js
    // License: https://github.com/hapijs/lout/blob/master/LICENSE
    const routes = [{
        method: 'GET',
        path: '/test',
        config: {
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    param1: Joi.string().insensitive().required()
                }
            },
            tags: ['api'],
            description: 'Test GET',
            notes: 'test note'
        }
    }, {
        method: 'GET',
        path: '/another/test',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    param1: Joi.string().required()
                }
            }
        }
    }, {
        method: 'GET',
        path: '/zanother/test',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    param1: Joi.string().required()
                }
            }
        }
    }, {
        method: 'POST',
        path: '/test',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    param2: Joi.string().valid('first', 'last'),
                    param3: 'third',
                    param4: 42
                }
            }
        }
    }, {
        method: 'DELETE',
        path: '/test',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    param2: Joi.string().valid('first', 'last')
                }
            }
        }
    }, {
        method: 'PUT',
        path: '/test',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    param2: Joi.string().valid('first', 'last')
                }
            }
        }
    }, {
        method: 'PATCH',
        path: '/test',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    param2: Joi.string().valid('first', 'last'),
                    param3: Joi.number().valid(42)
                }
            }
        }
    }, {
        method: 'GET',
        path: '/notincluded',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            plugins: {
                lout: false
            }
        }
    }, {
        method: 'GET',
        path: '/nested',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    param1: Joi.object({
                        nestedparam1: Joi.string().required(),
                        array: Joi.array()
                    })
                }
            }
        }
    }, {
        method: 'GET',
        path: '/rootobject',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: Joi.object({
                    param1: Joi.string().required()
                })
            }
        }
    }, {
        method: 'GET',
        path: '/rootarray',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: Joi.array().items(
                    Joi.string().required(),
                    Joi.object({ param1: Joi.number() }),
                    Joi.number().forbidden()
                    ).min(2).max(5).length(3)
            }
        }
    }, {
        method: 'GET',
        path: '/complexarray',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: Joi.array()
                    .ordered('foo', 'bar')
                    .items(
                        Joi.string().required(),
                        Joi.string().valid('four').forbidden(),
                        Joi.object({ param1: Joi.number() }),
                        Joi.number().forbidden()
                        ).min(2).max(5).length(3)
                    .ordered('bar', 'bar')
                    .items(
                        Joi.number().required()
                        )
            }
        }
    }, {
        method: 'GET',
        path: '/path/{pparam}/test',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                params: {
                    pparam: Joi.string().required()
                }
            }
        }
    }, {
        method: 'GET',
        path: '/emptyobject',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    param1: Joi.object()
                }
            }
        }
    }, {
        method: 'GET',
        path: '/alternatives',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    param1: Joi.alternatives().try(Joi.number().required(), Joi.string().valid('first', 'last'))
                }
            }
        }
    }, {
        method: 'GET',
        path: '/withnestedalternatives',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    param1: Joi.object({
                        param2: Joi.alternatives().try(
                            {
                                param3: Joi.object({
                                    param4: Joi.number().example(5)
                                }).description('this is cool too')
                            },
                            Joi.number().min(42)
                            )
                    }).description('something really cool'),
                    param2: Joi.array().items(
                        Joi.object({
                            param2: Joi.alternatives().try(
                                {
                                    param3: Joi.object({
                                        param4: Joi.number().example(5)
                                    }).description('this is cool too')
                                },
                                Joi.array().items('foo', 'bar'),
                                Joi.number().min(42).required(),
                                Joi.number().max(42).required()
                                )
                        }).description('all the way down')
                        ).description('something really cool')
                }
            }
        }
    }, {
        method: 'GET',
        path: '/novalidation',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler
        }
    }, {
        method: 'GET',
        path: '/withresponse',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            response: {
                schema: {
                    param1: Joi.string()
                }
            }
        }
    }, {
        method: 'GET',
        path: '/withstatus',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            response: {
                schema: {
                    param1: Joi.string()
                },
                status: {
                    204: {
                        param2: Joi.string()
                    },
                    404: {
                        error: 'Failure'
                    }
                }
            }
        }
    }, {
        method: 'GET',
        path: '/withpojoinarray',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    param1: Joi.array().items({
                        param2: Joi.string()
                    })
                }
            }
        }
    }, {
        method: 'POST',
        path: '/withnestedrulesarray',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                payload: {
                    param1: Joi.array().items(Joi.object({
                        param2: Joi.array().items(Joi.object({
                            param3: Joi.string()
                        })).optional()
                    }))
                }
            }
        }
    }, {
        method: 'GET',
        path: '/withhtmlnote',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    param1: Joi.string().notes('<span class="htmltypenote">HTML type note</span>')
                }
            },
            notes: '<span class="htmlroutenote">HTML route note</span>'
        }
    }, {
        method: 'GET',
        path: '/withnotesarray',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    param1: Joi.string().notes([
                        '<span class="htmltypenote">HTML type note</span>',
                        '<span class="htmltypenote">HTML type note</span>'
                    ])
                }
            }
        }
    }, {
        method: 'GET',
        path: '/withexample',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    param1: Joi.string().regex(/^\w{1,5}$/).example('abcde')
                }
            }
        }
    }, {
        method: 'POST',
        path: '/denybody',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                payload: false
            }
        }
    }, {
        method: 'POST',
        path: '/rootemptyobject',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                payload: Joi.object()
            }
        }
    }, {
        method: 'GET',
        path: '/withnestedexamples',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    param1: Joi.object({
                        param2: Joi.object({
                            param3: Joi.number().example(5)
                        }).example({
                            param3: 5
                        })
                    }).example({
                        param2: {
                            param3: 5
                        }
                    })
                }
            }
        }
    }, {
        method: 'GET',
        path: '/withmeta',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    param1: Joi.string().meta({
                        index: true,
                        unique: true
                    })
                }
            }
        }
    }, {
        method: 'GET',
        path: '/withunit',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    param1: Joi.number().unit('ms')
                }
            }
        }
    }, {
        method: 'GET',
        path: '/withdefaultvalue',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    param1: Joi.number().default(42)
                }
            }
        }
    }, {
        method: 'GET',
        path: '/withbinaryencoding',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    param1: Joi.binary().min(42).max(128).length(64).encoding('base64')
                }
            }
        }
    }, {
        method: 'GET',
        path: '/withdate',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    param1: Joi.date().min('1-1-1974').max('12-31-2020')
                }
            }
        }
    }, {
        method: 'GET',
        path: '/withpeersconditions',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    param1: Joi.object()
                        .and('a', 'b', 'c')
                        .or('a', 'b', 'c')
                        .xor('a', 'b', 'c')
                        .with('a', ['b', 'c'])
                        .without('a', ['b', 'c'])
                }
            }
        }
    }, {
        method: 'GET',
        path: '/withpattern',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    param1: Joi.object({
                        a: Joi.string()
                    }).pattern(/\w\d/, Joi.boolean())

                }
            }
        }
    }, {
        method: 'GET',
        path: '/withallowunknown',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    param1: Joi.object().unknown(),
                    param2: Joi.object().unknown(false)
                }
            }
        }
    }, {
        method: 'GET',
        path: '/withstringspecifics',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    param1: Joi.string()
                        .alphanum()
                        .regex(/\d{3}.*/)
                        .token()
                        .email()
                        .guid()
                        .isoDate()
                        .hostname()
                        .lowercase()
                        .uppercase()
                        .trim(),
                    param2: Joi.string().email()
                }
            }
        }
    }, {
        method: 'GET',
        path: '/withconditionalalternatives',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    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',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    param1: Joi.ref('a.b'),
                    param2: Joi.ref('$x')
                }
            }
        }
    }, {
        method: 'GET',
        path: '/withassert',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    param1: Joi.object().assert('d.e', Joi.ref('a.c'), 'equal to a.c'),
                    param2: Joi.object().assert('$x', Joi.ref('b.e'), 'equal to b.e')
                }
            }
        }
    }, {
        method: 'GET',
        path: '/withproperties',
        vhost: 'john.doe',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            cors: {
                maxAge: 12345
            },
            jsonp: 'callback'
        }
    }, {
        method: 'OPTIONS',
        path: '/optionstest',
        handler: Helper.defaultHandler
    }, {
        method: 'GET',
        path: '/withrulereference',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    param1: Joi.date().min(Joi.ref('param2')),
                    param2: Joi.date()
                }
            }
        }
    }, {
        method: 'GET',
        path: '/withcorstrue',
        vhost: 'john.doe',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            cors: true
        }
    }, {
        method: 'GET',
        path: '/withstrip',
        config: {
            tags: ['api'],
            handler: Helper.defaultHandler,
            validate: {
                query: {
                    param1: Joi.any().strip(),
                    param2: Joi.any()
                }
            }
        }
    }, {
        method: 'GET',
        path: '/internal',
        config: {
            tags: ['api'],
            isInternal: true,
            handler: Helper.defaultHandler
        }
    }];



    lab.test('all routes parsed', (done) => {

        Helper.createServer({}, routes, (err, server) => {

            expect(err).to.equal(null);
            server.inject({ method: 'GET', url: '/swagger.json' }, function (response) {

                expect(response.statusCode).to.equal(200);
                // the 40 to 45 difference is in one route having a number of methods
                expect(response.result.paths).to.have.length(40);
                done();
            });

        });
    });

});
    this._callback(null, response);

    return true;
};

var schema = Joi.object().keys({
   bucket: Joi.string().required(),
   bucketType: Joi.string().default('default'),
   key: Joi.string().required(),
   r: Joi.number().default(null).optional(),
   pr: Joi.number().default(null).optional(),
   notFoundOk: Joi.boolean().default(false).optional(),
   useBasicQuorum: Joi.boolean().default(false).optional(),
   returnDeletedVClock: Joi.boolean().default(false).optional(),
   headOnly: Joi.boolean().default(false).optional(),
   ifNotModified: Joi.binary().default(null).optional(),
   timeout: Joi.number().default(null).optional(),
   conflictResolver: Joi.func().default(null).optional(),
   convertToJs: Joi.boolean().default(false).optional()
});

/**
 * A builder for constructing FetchValue instances.
 *
 * Rather than having to manually construct the __options__ and instantiating
 * a FetchValue directly, this builder may be used.
 *
 *     var fetchValue = new FetchValue.Builder()
 *          .withBucket('myBucket')
 *          .withKey('myKey')
 *          .build();
Exemple #10
0
const handlersAds = require('./handlersAds');

const Joi = require('Joi');

const adSchema = Joi.object({
    title: Joi.string().min(5).max(70).required(),
    category: Joi.string().min(2).required(),
    description: Joi.string().min(2).max(4096).required(), //min 20
    author: Joi.string().min(2).max(50).required(),
    contact_person: Joi.string().min(2).max(50).required(),
    address: Joi.string().min(2).max(50).required(),    
    email: Joi.string().email().required(),
    phone: Joi.string().optional(),
    //validityDate: Joi.date().min('1-1-1900').max('now').iso().optional()
    picture : Joi.binary().optional(),
    //picture: Joi.Buffer(0),
    userId : Joi.string().length(24).optional()
});

module.exports = [
    {
    method: 'GET',
    path: '/api/ads',
    handler: handlersAds.findAll
    },
    {
        method: 'GET',
        path: '/api/ads/{adsId}',
        handler: handlersAds.find,
        config: {
            validate: {
'use strict';

const Enjoi = require('enjoi');
const Joi = require('joi');
const Util = require('util');

const types = {
    int64: Joi.string().regex(/^\d+$/),
    byte: Joi.string().base64(),
    binary: Joi.binary(),
    date: Joi.date(),
    'date-time': Joi.date().iso(),
    file: Joi.object({
        value: Joi.binary().required(true),
        consumes: Joi.array().items([
            Joi.string().regex(/multipart\/form-data|application\/x-www-form-urlencoded/)
        ]).required(true),
        in: Joi.string().regex(/formData/).required(true)
    })
};

const refineType = function (type, format) {
    if (type === 'integer') {
        type = 'number';
    }

    switch (format) {
        case 'int64':
        case 'byte':
        case 'binary':
        case 'date':
Exemple #12
0
Schema.types.binarySet = function () {
  var set = Joi.array().includes(Joi.binary(), Joi.string()).meta({dynamoType : 'BS'});
  return set;
};
Exemple #13
0
'use strict';

const vogels = require('../index');
const fs = require('fs');
const AWS = vogels.AWS;
const Joi = require('joi');

AWS.config.loadFromPath(`${process.env.HOME}/.ec2/credentials.json`);

const BinModel = vogels.define('example-binary', {
  hashKey: 'name',
  timestamps: true,
  schema: {
    name: Joi.string(),
    data: Joi.binary()
  }
});

const printFileInfo = (err, file) => {
  if (err) {
    console.log('got error', err);
  } else if (file) {
    console.log('got file', file.get());
  } else {
    console.log('file not found');
  }
};

vogels.createTables(err => {
  if (err) {
    console.log('Error creating tables', err);
Exemple #14
0
 blob: function () {
   return joi.alternatives().meta({ cql: true, type: 'blob' }).try(
     joi.binary(),
     joi.string().hex()
   );
 },
Exemple #15
0
        response = { generatedKey: responseKey, vclock: vclock, values: values };

    } else {
        response = { generatedKey: null, vclock: null, values: [] };
    }

    this._callback(null, response);

    return true;
};

var schema = Joi.object().keys({
    bucket: Joi.string().optional(),
    bucketType: Joi.string().default('default'),
    key: Joi.binary().default(null).optional(),
    value: Joi.any().required(),
    w: Joi.number().default(null).optional(),
    dw: Joi.number().default(null).optional(),
    pw: Joi.number().default(null).optional(),
    returnBody: Joi.boolean().default(false).optional(),
    returnHead: Joi.boolean().default(false).optional(),
    timeout: Joi.number().default(null).optional(),
    ifNotModified: Joi.boolean().default(false).optional(),
    ifNoneMatch: Joi.boolean().default(false).optional(),
    vclock: Joi.binary().default(null).optional(),
    convertToJs: Joi.boolean().default(false).optional(),
    conflictResolver: Joi.func().default(null).optional()
});

/**
    CommandBase.call(this, 'RpbGetReq', 'RpbGetResp', callback);
    var self = this;
    Joi.validate(options, schema, function(err, options) {
        if (err) {
            throw err;
        }
        self.options = options;
    });
}

inherits(TestCommand, CommandBase);

var schema = Joi.object().keys({
   bucketType: Joi.string().default('default'),
   bucket: Joi.string().required(),
   key: Joi.binary().required()
});

function TestBuilder() {}

TestBuilder.prototype = {
    withBucket : function(bucket) {
        this.bucket = bucket;
        return this;
    },
    withKey : function(key) {
        this.key = key;
        return this;
    },
    withCallback : function(callback) {
        this.callback = callback;
Exemple #17
0
    config: {
        handler: handler,
        validate: {
            query: {
                param1: Joi.number().default(42)
            }
        }
    }
}, {
    method: 'GET',
    path: '/withbinaryencoding',
    config: {
        handler: handler,
        validate: {
            query: {
                param1: Joi.binary().min(42).max(128).length(64).encoding('base64')
            }
        }
    }
}, {
    method: 'GET',
    path: '/withdate',
    config: {
        handler: handler,
        validate: {
            query: {
                param1: Joi.date().min('1-1-1974').max('12-31-2020')
            }
        }
    }
}, {
let numberString = '16';
console.log(typeof numberString);

Joi.validate(numberString, Joi.number(), (err, value) => {

    if (err) {
        throw err;
    }
    console.log(typeof value);
});

// String => Buffer

const string = 'I\'m a string';

Joi.validate(string, Joi.binary(), (err, value) => {

    if (err) {
        throw err;
    }
    console.log(value);
    console.log(value instanceof Buffer);
});

// No convert

numberString = '16';

Joi.validate(numberString, Joi.number(), { convert: false }, (err, value) => {

    if (err) {