Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
lab.test('parse type number', (done) => {
// mapped direct to openapi
expect(properties.parseProperty('x', Joi.number().integer())).to.equal({ 'type': 'integer' });
expect(properties.parseProperty('x', Joi.number().min(5))).to.equal({ 'type': 'number', 'minimum': 5 });
expect(properties.parseProperty('x', Joi.number().max(10))).to.equal({ 'type': 'number', 'maximum': 10 });
// x-* mappings
expect(properties.parseProperty('x', Joi.number().greater(10))).to.equal({ 'type': 'number', 'x-constraint': { 'greater': 10 } });
expect(properties.parseProperty('x', Joi.number().less(10))).to.equal({ 'type': 'number', 'x-constraint': { 'less': 10 } });
expect(properties.parseProperty('x', Joi.number().precision(2))).to.equal({ 'type': 'number', 'x-constraint': { 'precision': 2 } });
expect(properties.parseProperty('x', Joi.number().multiple(2))).to.equal({ 'type': 'number', 'x-constraint': { 'multiple': 2 } });
expect(properties.parseProperty('x', Joi.number().positive())).to.equal({ 'type': 'number', 'x-constraint': { 'positive': true } });
expect(properties.parseProperty('x', Joi.number().negative())).to.equal({ 'type': 'number', 'x-constraint': { 'negative': true } });
done();
});
const async = require('async');
// http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GSI.html
const AWS = dynogels.AWS;
AWS.config.update({ region: 'us-east-1' });
const GameScore = dynogels.define('example-global-index', {
hashKey: 'userId',
rangeKey: 'gameTitle',
schema: {
userId: Joi.string(),
gameTitle: Joi.string(),
topScore: Joi.number(),
topScoreDateTime: Joi.date(),
wins: Joi.number(),
losses: Joi.number()
},
indexes: [{
hashKey: 'gameTitle',
rangeKey: 'topScore',
name: 'GameTitleIndex',
type: 'global',
projection: { NonKeyAttributes: ['wins'], ProjectionType: 'INCLUDE' }
},
{ hashKey: 'gameTitle', rangeKey: 'losses', name: 'GameLosersIndex', type: 'global' }
]
});
const data = [
{ userId: '101', gameTitle: 'Galaxy Invaders', topScore: 5842, wins: 10, losses: 5, topScoreDateTime: new Date(2012, 1, 3, 8, 30) },
{ userId: '101', gameTitle: 'Meteor Blasters', topScore: 1000, wins: 12, losses: 3, topScoreDateTime: new Date(2013, 1, 3, 8, 30) },
// Raw telemetry entry
const RawTelemetrySchema = {
time: Joi.number(),
velocity: Joi.number(),
altitude: Joi.number()
};
// Analysed telemetry entry
const AnalysedTelemetrySchema = {
time: Joi.number(),
velocity: Joi.number(),
altitude: Joi.number(),
velocity_y: Joi.number(),
velocity_x: Joi.number(),
acceleration: Joi.number(),
downrange_distance: Joi.number(),
angle: Joi.number(),
q: Joi.number()
};
// Raw telemetry of a specific stage
const StageRawTelemetrySchema = {
stage: Joi.number(),
telemetry: Joi.array().items(RawTelemetrySchema)
};
// Analysed telemetry of a specific stage
const StageAnalysedTelemetrySchema = {
stage: Joi.number().integer().min(0),
var error = Boom.badRequest('Kaboom');
error.output.payload.custom = i++;
return reply(error);
};
var server = new Hapi.Server({ debug: false });
server.connection();
server.route({
method: 'GET',
path: '/',
config: {
response: {
schema: true,
status: {
400: {
statusCode: Joi.number(),
error: Joi.string(),
message: Joi.string(),
custom: 1
}
}
}
},
handler: handler
});
server.inject('/', function (res) {
expect(res.statusCode).to.equal(200);
server.inject('/', function (res) {
expect(res.statusCode).to.equal(400);
generateJoiModelFromFieldType: function (field, Log) {
var model;
assert(field.type, "incorrect field format");
switch (field.type.schemaName) {
case 'ObjectId':
model = Joi.objectId();
break;
case 'Boolean':
model = Joi.bool();
break;
case 'Number':
model = Joi.number();
break;
case 'Date':
model = Joi.date();
break;
case 'String':
if (field.enum) {
model = Joi.any().only(field.enum);
}
else {
model = Joi.string();
}
break;
default:
model = Joi.any();
break;
}
{
method: 'POST',
path: '/charge/quote',
handler: Handler.chargeQuote,
options: {
id: 'charge',
tags: tags,
auth: Auth.strategy(),
description: 'Quote a charge for a transaction amount',
payload: {
allow: 'application/json',
failAction: 'error'
},
validate: {
payload: {
amount: Joi.number().required().description('Amount for charge quote')
}
}
}
}
]
host: Joi.string(),
port: Joi.number().integer(),
protocol: Joi.string().valid('http', 'https', 'http:', 'https:'),
uri: Joi.string(),
passThrough: Joi.boolean(),
localStatePassThrough: Joi.boolean(),
acceptEncoding: Joi.boolean().when('passThrough', { is: true, otherwise: Joi.forbidden() }),
rejectUnauthorized: Joi.boolean(),
xforward: Joi.boolean(),
redirects: Joi.number().min(0).integer().allow(false),
timeout: Joi.number().integer(),
mapUri: Joi.func(),
onResponse: Joi.func(),
agent: Joi.object(),
ttl: Joi.string().valid('upstream').allow(null),
maxSockets: Joi.number().positive().allow(false)
})
.xor('host', 'mapUri', 'uri')
.without('mapUri', 'port', 'protocol')
.without('uri', 'port', 'protocol');
exports.register = function (server, pluginOptions, next) {
server.handler('proxy', internals.handler);
server.decorate('reply', 'proxy', function (options) {
internals.handler(this.request.route, options)(this.request, this);
});
return next();
constructor(props, context) {
super(props, context);
this.actions = bindActionCreators(ContractActions, this.props.dispatch);
//TODO: modify validation for nested properties
this.validatorTypes = {
id: Joi.number().required().label('Contract Id'),
description: Joi.when('finished', { is: true, then: Joi.string().min(5).max(25).required() }).label('Description'),
finished: Joi.boolean().label('Finished')
}
this.state = this.props.contract ? this.props.contract : this.initialState;
}
cors: { origin: ['*'], credentials: false },
validate: {
payload: Joi.object({
query: {
id: Joi.alternatives(
Joi.string().guid(),
Joi.object().keys({
nin$: Joi.array()
.items(Joi.string().guid())
.min(1),
in$: Joi.array()
.items(Joi.string().guid())
.min(1),
})
),
mysqlDojoId: Joi.alternatives(Joi.string(), Joi.number()),
ids: Joi.array().items(Joi.string().guid()),
name: Joi.string(),
verified: Joi.number()
.valid(0)
.valid(1),
stage: Joi.alternatives(
Joi.number().integer(),
Joi.object({
ne$: Joi.number(),
})
),
deleted: Joi.number()
.valid(0)
.valid(1),
alpha2: joiValidator.alpha2(),
fields$: Joi.array().items(Joi.string()),